-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall
executable file
·105 lines (90 loc) · 3.19 KB
/
install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
#set -v
set -e
if [ -n "$BASH_VERSION" ]; then
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
elif [ -n "$ZSH_VERSION" ]; then
SCRIPT_DIR="${0:a:h}"
else
echo "Unknown shell"
exit 1
fi
BASHRC_DIR="$SCRIPT_DIR"
BASHRC_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [[ -f "$BASHRC_DIR/scripts/src/10_basics.sh" ]]; then
source "$BASHRC_DIR/scripts/src/10_basics.sh"
msg-info "bashrc repo found at $BASHRC_DIR"
else
echo "Could not find bashrc repo"
exit 1
fi
OS_TYPE=`get_os_type`
REQUIRED_PACKAGES="rsync git python"
if [[ "$OS_TYPE" == "Linux" ]] || [[ "$OS_TYPE" == "Mac" ]]; then
REQUIRED_PACKAGES="$REQUIRED_PACKAGES sudo"
fi
MISSING_PACKAGES=""
for REQUIRED_PACKAGE in $REQUIRED_PACKAGES; do
if ! commands_exist "$REQUIRED_PACKAGE"; then
MISSING_PACKAGES="$MISSING_PACKAGES $REQUIRED_PACKAGE"
fi
done
if [[ "$MISSING_PACKAGES" != "" ]]; then
msg-error "You must first install: $MISSING_PACKAGES"
ask-yes "Do you want me to try to install them for you?"
if [[ "$ASK" == "y" ]]; then
source "$BASHRC_DIR/scripts/src/50_pkgs.sh"
for REQUIRED_PACKAGE in $REQUIRED_PACKAGES; do
if ! commands_exist "$REQUIRED_PACKAGE"; then
pkg install "$REQUIRED_PACKAGE"
fi
done
else
exit 1
fi
fi
msg-info "Uninstalling the software, if it is already installed..."
"$BASHRC_DIR/uninstall"
msg-info "Cloning https://github.com/maludwig/bashrc.git into $HOME/bashrc.extensions/ ..."
git clone https://github.com/maludwig/bashrc.git "$HOME/bashrc.extensions/"
if [[ -f "$HOME/.zshrc" ]] || commands_exist zsh; then
msg-info "Adding source line to $HOME/.zshrc"
echo -e "\nsource \"$HOME/bashrc.extensions/main\"\n" >> "$HOME/.zshrc"
fi
if [[ -f "$HOME/.bashrc" ]]; then
msg-info "Adding source line to $HOME/.bashrc"
echo -e "\nsource \"$HOME/bashrc.extensions/main\"\n" >> "$HOME/.bashrc"
elif [[ -f "$HOME/.bash_profile" ]]; then
msg-info "Adding source line to $HOME/.bash_profile"
echo -e "\nsource \"$HOME/bashrc.extensions/main\"\n" >> "$HOME/.bash_profile"
fi
if ! [[ -d "$HOME/profile.d" ]]; then
msg-info "Copying sample to $HOME/profile.d"
rsync -av "$HOME/bashrc.extensions/profile.d/" "$HOME/profile.d/"
fi
if [[ "$OS_TYPE" == "Linux" ]] || [[ "$OS_TYPE" == "Mac" ]]; then
if [[ "$SHELL" == "/bin/sh" ]]; then
msg-info "Setting shell to /bin/bash"
if [[ -f /bin/bash ]]; then
sudo chsh -s /bin/bash `whoami`
fi
fi
fi
msg-info "Initializing submodules"
cd "$HOME/bashrc.extensions"
git submodule update --init --recursive
msg-success '
The maludwig/bashrc extensions were installed to: $HOME/bashrc.extensions
You can delete this directory now, if you like.
If you want to extend the current set with your own user-specific extensions
you can add them to your local ~/profile.d with a .sh extension
Check out ~/profile.d/50_sample.sh for an example.
On most platforms /etc/profile.d/*.sh scripts are run for all users.
Restart bash to experience the new world
'
if [[ "$OS_TYPE" == "Linux" ]] || [[ "$OS_TYPE" == "Mac" ]]; then
if [[ `whoami` != "root" ]]; then
msg-info 'You may also want to install these for the root user, like so:'
msg-dry " sudo -H \"$BASHRC_DIR/install\""
fi
fi