forked from Parth/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·164 lines (135 loc) · 4.24 KB
/
deploy.sh
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/bash
prompt_install() {
echo -n "$1 is not installed. Would you like to install it? (y/n) " >&2
old_stty_cfg=$(stty -g)
stty raw -echo
answer=$( while ! head -c 1 | grep -i '[ny]' ;do true ;done )
stty $old_stty_cfg && echo
if echo "$answer" | grep -iq "^y" ;then
# This could def use community support
if [ -x "$(command -v apt-get)" ]; then
sudo apt-get install $1 -y
elif [ -x "$(command -v brew)" ]; then
brew install $1
elif [ -x "$(command -v pkg)" ]; then
sudo pkg install $1
elif [ -x "$(command -v pacman)" ]; then
sudo pacman -S $1
else
echo "I'm not sure what your package manager is! Please install $1 on your own and run this deploy script again."
fi
fi
}
check_for_software() {
echo "Checking to see if $1 is installed"
if ! ( [ -x "$(command -v $1)" ] || [ "$(dpkg -l | grep $1)" ] ); then
prompt_install $1
else
echo "$1 is installed."
fi
}
check_default_shell() {
if [ -z "${SHELL##*zsh*}" ] ;then
echo "Default shell is zsh."
else
echo -n "Default shell is not zsh. Do you want to chsh -s \$(which zsh)? (y/n)"
old_stty_cfg=$(stty -g)
stty raw -echo
answer=$( while ! head -c 1 | grep -i '[ny]' ;do true ;done )
stty $old_stty_cfg && echo
if echo "$answer" | grep -iq "^y" ;then
chsh -s $(which zsh)
else
echo "Warning: Your configuration won't work properly. If you exec zsh, it'll exec tmux which will exec your default shell which isn't zsh."
fi
fi
}
echo "We're going to do the following:"
echo "1. Check to make sure you have zsh, wget, vim, tmux, fzf and fonts-powerline"
echo "2. We'll help you install them if you don't"
echo "3. We're going to check to see if your default shell is zsh"
echo "4. We'll try to change it if it's not"
echo "Let's get started? (y/n)"
old_stty_cfg=$(stty -g)
stty raw -echo
answer=$( while ! head -c 1 | grep -i '[ny]' ;do true ;done )
stty $old_stty_cfg
if echo "$answer" | grep -iq "^y" ;then
echo
else
echo "Quitting, nothing was changed."
exit 0
fi
# base requirements
check_for_software wget
echo
check_for_software vim
echo
check_for_software tmux
echo
check_for_software git
echo
check_for_software zsh
echo
# oh-my-zsh "agnoster"-theme requirements
check_for_software fonts-powerline
echo
check_for_software fzf
echo
# oh-my-tmux requirements
check_for_software awk
echo
check_for_software sed
echo
check_for_software perl
echo
check_for_software xclip
echo
# backup current dotfiles
echo
echo -n "Would you like to backup your current dotfiles? (y/n) "
old_stty_cfg=$(stty -g)
stty raw -echo
answer=$( while ! head -c 1 | grep -i '[ny]' ;do true ;done )
stty $old_stty_cfg
now=$(date +"%Y-%m-%d_%H-%M-%S")
if echo "$answer" | grep -iq "^y" ;then
mv $HOME/.tmux.conf $HOME/.tmux.conf.${now}
mv $HOME/.vimrc $HOME/.vimrc.${now}
mv $HOME/.config/Code/User/settings.json $HOME/.config/Code/User/settings.json.${now}
mv $HOME/.config/Code/User/keybindings.json $HOME/.config/Code/User/keybindings.json.${now}
else
echo -e "\nNot backing up old dotfiles."
fi
# the directory this script is in
BASEDIR=$(dirname "$0")
echo "Install oh-my-zsh"
if [ -d "$HOME/.oh-my-zsh" ]; then
(cd $HOME/.oh-my-zsh && git pull --rebase)
else
sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh) --unattended"
fi
echo "Install zsh-autosuggestions plugin"
if [ -d "$HOME/.oh-my-zsh/custom/plugins/zsh-autosuggestions" ]; then
(cd $HOME/.oh-my-zsh/custom/plugins/zsh-autosuggestions && git pull --rebase)
else
(cd $HOME/.oh-my-zsh/custom/plugins && git clone https://github.com/zsh-users/zsh-autosuggestions.git)
fi
echo "Install oh-my-tmux"
if [ -d "$HOME/.oh-my-tmux" ]; then
(cd $HOME/.oh-my-tmux && git pull --rebase)
else
git clone https://github.com/gpakosz/.tmux.git $HOME/.oh-my-tmux
fi
ln -s -f $HOME/.oh-my-tmux/.tmux.conf $HOME/.tmux.conf
# setup locales
sudo locale-gen --purge de_DE.UTF-8
sudo bash -c "echo -e 'LANG=\"de_DE.UTF-8\"\nLANGUAGE=\"de_DE:de\"\n' > /etc/default/locale"
# check for default shell
check_default_shell
# symlink custom configs from this folder
ln -s -f $HOME/$BASEDIR/zsh/.zshrc $HOME/.zshrc
ln -s -f $HOME/$BASEDIR/tmux/.tmux.conf.local $HOME/.tmux.conf.local
printf "so $HOME/$BASEDIR/vim/vimrc.vim" > $HOME/.vimrc
echo
echo "Please log out and log back in for default shell to be initialized."