-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbootstrap.sh
executable file
·222 lines (198 loc) · 5.42 KB
/
bootstrap.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/usr/bin/env bash
backup_file() {
test -e $HOME/$1 && cp -LiR $HOME/$1 $HOME/$1.dotbackup && rm -rf $HOME/$1
true
}
backup_directory() {
test -d $HOME/$1.dotbackup && echo -n "~/$1.dotbackup: " && rm -rI $HOME/$1.dotbackup
test -d $HOME/$1 && cp -LR $HOME/$1 $HOME/$1.dotbackup && rm -rf $HOME/$1
true
}
link_file() {
backup_file $2
ln -s `pwd`/$1 $HOME/$2
}
link_directory() {
backup_directory $2
ln -s `pwd`/$1 $HOME/$2
}
copy_file() {
backup_file $2
cp `pwd`/$1 $HOME/$2
}
clone_or_pull_repo() {
if [ ! -f $HOME/$2/README.md ]; then
git clone https://github.com/$1.git $HOME/$2
else
pushd $HOME/$2 > /dev/null
git pull
popd > /dev/null
fi
}
load_zsh_modules() {
echo "Loading zsh modules..."
while read l; do
IFS=/ read -a path <<< "$l"
clone_or_pull_repo "$l" ".zsh_modules/${path[1]}"
done < $HOME/.zmodules
}
install_virtualenvwrapper() {
echo "Installing virtualenvwrapper..."
curl -s https://raw.githubusercontent.com/brainsik/virtualenv-burrito/master/virtualenv-burrito.sh | exclude_profile=1 $SHELL || true
}
configure_shell() {
echo "Configuring common shell environment..."
link_file .bash_aliases .bash_aliases
link_file .shenv .shenv
if [ "$OSTYPE" == "darwin"* ]; then
copy_file .bash_local-mac .bash_local
else
copy_file .bash_local-linux .bash_local
fi
}
configure_bash() {
echo "Configuring bash..."
link_directory .bash_scripts .bash_scripts
link_file .bash_profile .bash_profile
link_file .bashrc .bashrc
}
configure_zsh() {
echo "Configuring zsh..."
link_file .zshrc .zshrc
link_file .zmodules .zmodules
link_directory .zsh_scripts .zsh_scripts
backup_directory .zsh_modules
mkdir -p ~/.zsh_modules
load_zsh_modules
rm -f $HOME/.zcompdump
}
configure_git() {
echo "Configuring git..."
if [ -z "$GIT_NAME" ]; then
read -p "Git user.name: " GIT_NAME
fi
if [ -z "$GIT_EMAIL" ]; then
read -p "Git user.email: " GIT_EMAIL
fi
backup_file .gitconfig
sed -e 's/\[\[GIT_NAME\]\]/'"$GIT_NAME"'/g' -e 's/\[\[GIT_EMAIL\]\]/'"$GIT_EMAIL"'/g' `pwd`/.gitconfig-global > $HOME/.gitconfig
copy_file .gitignore-global .gitignore
}
configure_i3() {
echo "Configuring i3..."
backup_directory .i3
mkdir -p $HOME/.i3
link_file .i3/config .i3/config
link_file .i3status.conf .i3status.conf
}
configure_vim() {
echo "Configuring vim..."
link_file .vimrc .vimrc
clone_or_pull_repo gmarik/vundle .vim/bundle/vundle
echo "Installing Vim plugins. Please wait..."
vim +PluginInstall +qall > /dev/null 2>&1
}
configure_tmux() {
echo "Configuring tmux..."
link_file .tmux.conf .tmux.conf
}
configure_ipython() {
echo "Configuring ipython..."
if [ "$OSTYPE" == "darwin"* ]; then
link_directory .ipython .ipython
else
mkdir -p $HOME/.config
link_directory .ipython .config/ipython
fi
}
delete_backups() {
rm -rf $HOME/.bash_scripts.dotbackup
rm -rf $HOME/.i3.dotbackup
rm -rf $HOME/.i3status.conf.dotbackup
rm -rf $HOME/.ipython.dotbackup
rm -rf $HOME/.config/ipython.dotbackup
rm -rf $HOME/.bash_aliases.dotbackup
rm -rf $HOME/.bash_local.dotbackup
rm -rf $HOME/.bash_profile.dotbackup
rm -rf $HOME/.bash_prompt.dotbackup
rm -rf $HOME/.bashrc.dotbackup
rm -rf $HOME/.gitconfig.dotbackup
rm -rf $HOME/.gitignore.dotbackup
rm -rf $HOME/.shenv.dotbackup
rm -rf $HOME/.tmux.conf.dotbackup
rm -rf $HOME/.vimrc.dotbackup
rm -rf $HOME/.zshrc.dotbackup
rm -rf $HOME/.zmodules.dotbackup
rm -rf $HOME/.zsh_modules.dotbackup
rm -rf $HOME/.zsh_scripts.dotbackup
}
update() {
echo "Updating configuration..."
git pull origin master
if [ "$NO_VIM" != 1 ]; then
echo "Updating Vim plugins. Please wait..."
vim +PluginUpdate +qall > /dev/null 2>&1
fi
load_zsh_modules
rm -f $HOME/.zcompdump
}
set -e
while :
do
case $1 in
-h | --help | -\?) echo "See https://github.com/alanctkc/dotfiles-old/blob/master/README.md"; exit 0; ;;
--delete-backups) DELETE_BACKUPS=1; shift; ;;
--update) UPDATE=1; shift; ;;
--no-virtualenv) NO_VIRTUALENVWRAPPER=1; shift; ;;
--no-bash) NO_BASH=1; shift; ;;
--no-zsh) NO_ZSH=1; shift; ;;
--no-git) NO_GIT=1; shift; ;;
--git-name) GIT_NAME=$2; shift 2; ;;
--git-email) GIT_EMAIL=$2; shift 2; ;;
--no-i3) NO_I3=1; shift; ;;
--no-vim) NO_VIM=1; shift; ;;
--no-tmux) NO_TMUX=1; shift; ;;
--no-ipython) NO_IPYTHON=1; shift; ;;
--) shift; break; ;;
-*) printf >&2 'WARNING: Unknown option (ignored): %s\n' "$1"; shift; ;;
*) break; ;;
esac
done
if [ "$DELETE_BACKUPS" == 1 ]; then
delete_backups
echo "Backups deleted."
exit 0
fi
if [ "$UPDATE" == 1 ]; then
update
echo "Done."
exit 0
fi
if [ "$NO_VIRTUALENVWRAPPER" != 1 ]; then
install_virtualenvwrapper
fi
if [ "$NO_BASH" != 1 ] || [ "$NO_ZSH" != 1 ]; then
configure_shell
fi
if [ "$NO_BASH" != 1 ]; then
configure_bash
fi
if [ "$NO_ZSH" != 1 ]; then
configure_zsh
fi
if [ "$NO_GIT" != 1 ]; then
configure_git
fi
if [ "$NO_I3" != 1 ]; then
configure_i3
fi
if [ "$NO_TMUX" != 1 ]; then
configure_tmux
fi
if [ "$NO_IPYTHON" != 1 ]; then
configure_ipython
fi
if [ "$NO_VIM" != 1 ]; then
configure_vim
fi
echo "Done."