-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·354 lines (287 loc) · 11.4 KB
/
setup.sh
File metadata and controls
executable file
·354 lines (287 loc) · 11.4 KB
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
#!/usr/bin/env bash
#
# bash -c "$(curl -fsSL https://raw.github.com/davidxia/bootstrap_dotfiles/master/setup.sh)"
#
#
# Aptitude packages:
# build-essential - for GCC, GNU Make, etc.
# curl - obviously
# exuberant-ctags - for Vim Tagbar
# git - obviously
# tmux - terminal multiplexer
# vim-nox - Vim compiled with support for scripting with Perl, Python, Ruby, and Tcl
# zsh - best shell evar
#
#
# Homebrew packages:
#
#
#
# Pip packges:
# ipython -
# virtualenv -
aptitude="aptitude"
squeezePkgs="build-essential cmake curl exuberant-ctags git tmux vim-nox zsh"
precisePkgs="build-essential cmake curl exuberant-ctags git tmux vim-nox zsh"
brews="ack cmake cmatrix cowsay ctags fortune ifstat libevent libmpdclient mercurial netcat tor wget xz"
scriptDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
function cecho() {
case "${2}" in
red) code=31;;
green) code=32;;
yellow) code=33;;
blue) code=34;;
purple) code=35;;
cyan) code=36;;
white) code=37;;
*) code=1;;
esac
printf "\n\e[0;${code}m${1}\e[0m\n"
}
function notify() {
cecho "${1}" cyan
sleep 1
}
function ask() {
cecho "${1}" yellow
}
function pause() {
read -p "$*"
}
function error() {
cecho "${1}" red
sleep 1
}
function die() {
cecho "Error: ${1}" red
exit 1
}
function backup() {
for arg in "$@"; do
if [ -e ${arg} -o -h ${arg} ]; then
notify "Backing up existing ${arg} to ${arg}.bak"
rm -fr ${arg}.bak && mv ${arg} ${arg}.bak
fi
sleep 1
done
}
function askYesNo() {
ask "Do you want to ${1} ${2}?"
select ynq in "yes" "no" "quit"; do
case ${ynq} in
yes) shouldInstall=true; break;;
no) shouldInstall=false; break;;
quit) exit;;
esac
done
}
function aptInstall() {
case "${1}" in
precise) aptPkgs="${precisePkgs}";;
squeeze) aptPkgs="${squeezePkgs}";;
*) ;;
esac
askYesNo "install" "aptitude packages: ${aptPkgs}"
if ${shouldInstall}; then
ask "We'll need your password:"
sudo ${aptitude} install ${aptPkgs}
if [ "${1}" == "precise" ]; then
notify "Downloading the patched Monaco font for zsh's powerline theme"
mkdir ~/.fonts && git clone https://github.com/scotu/ubuntu-mono-powerline.git ~/.fonts/
fi
fi
}
function installHomebrew() {
if [ ! -x /usr/local/bin/brew ]; then
askYesNo "install" "Homebrew"
if ${shouldInstall}; then
printf "\n"
printf "\e[0;32m"' __ __ __ '"\e[0m\n"
printf "\e[0;32m"' / / / /___ ____ ___ ___ / /_ ________ _ __'"\e[0m\n"
printf "\e[0;32m"' / /_/ / __ \/ __ `__ \/ _ \/ __ \/ ___/ _ \ | /| / /'"\e[0m\n"
printf "\e[0;32m"' / __ / /_/ / / / / / / __/ /_/ / / / __/ |/ |/ / '"\e[0m\n"
printf "\e[0;32m"'/_/ /_/\____/_/ /_/ /_/\___/_.___/_/ \___/|__/|__/ '"\e[0m\n\n"
notify "Installing Homebrew"
ruby <(curl -fsSkL raw.github.com/mxcl/homebrew/go)
fi
else
notify "Updating Homebrew and formulae"
brew update
fi
}
function installBrews() {
if brewLoc="$(which brew)" && [ ! -z "${brewLoc}" ]; then
installedBrews=$(brew list)
missingBrews=""
# Create string of missing Homebrew formulae
for formula in ${brews}; do
test "${installedBrews#*$formula}" == "${installedBrews}" && ${missingBrews}="${missingBrews} ${formula}"
done
if [ ! "${missingBrews}" == "" ]; then
askYesNo "install" "Homebrew packages: ${missingBrews}"
if ${shouldInstall}; then
brew install ${missingBrews}
fi
fi
else
error "${brewLoc} is not executable"
fi
}
function configureZsh() {
askYesNo "install" "oh-my-zsh"
if ${shouldInstall}; then
notify "Installing oh-my-zsh!"
bash -c "$(curl -fsSL https://github.com/davidxia/oh-my-zsh/raw/master/tools/install.sh)"
fi
}
function configureTmux() {
askYesNo "configure" "tmux"
if ${shouldInstall}; then
printf "\n"
printf "\e[0;32m"' __ '"\e[0m\n"
printf "\e[0;32m"' / | '"\e[0m\n"
printf "\e[0;32m"' _$$ |_ _____ ____ __ __ __ __ '"\e[0m\n"
printf "\e[0;32m"'/ $$ | / \/ \ / | / |/ \ / |'"\e[0m\n"
printf "\e[0;32m"'$$$$$$/ $$$$$$ $$$$ |$$ | $$ |$$ \/$$/ '"\e[0m\n"
printf "\e[0;32m"' $$ | __ $$ | $$ | $$ |$$ | $$ | $$ $$< '"\e[0m\n"
printf "\e[0;32m"' $$ |/ |$$ | $$ | $$ |$$ \__$$ | /$$$$ \ '"\e[0m\n"
printf "\e[0;32m"' $$ $$/ $$ | $$ | $$ |$$ $$/ /$$/ $$ |'"\e[0m\n"
printf "\e[0;32m"' $$$$/ $$/ $$/ $$/ $$$$$$/ $$/ $$/ '"\e[0m\n\n"
backup ~/.tmux.conf ~/.tmux-conf
notify "Cloning David Xia's tmux conf and symlinking ~/.tmux.conf -> ~/.tmux-conf/tmux.conf"
git clone https://github.com/davidxia/tmux-conf.git ~/.tmux-conf && \
ln -s ~/.tmux-conf/tmux.conf ~/.tmux.conf
fi
}
function installTmuxPowerline() {
askYesNo "install" "tmux powerline"
if ${shouldInstall}; then
backup ~/.tmux-powerline && \
git clone https://github.com/davidxia/tmux-powerline.git ~/.tmux-powerline && \
~/.tmux-powerline/./generate_rc.sh && mv ~/.tmux-powerlinerc.default ~/.tmux-powerlinerc
pause "Your default tmux-powerlinerc is at ~/.tmux-powerlinerc. Edit it accordingly. See https://github.com/davidxia/tmux-powerline."
fi
}
function installTmuxPowerlineSegs() {
if [ -d ~/.tmux-powerline ]; then
askYesNo "install" "davidxia tmux-powerline theme"
if ${shouldInstall}; then
cd ~ && wget https://gist.github.com/davidxia/5271741/raw/ab29576b80154b95d07e45471a1b6a6a4bd2246b/davidxia.sh --output-document=.tmux-powerline/themes/davidxia.sh
fi
askYesNo "install" "tmux-mem-cpu-load"
if ${shouldInstall} && cmake_loc="$(which cmake)" && [ ! -z "${cmake_loc}" ]; then
rm -fr /tmp/tmux-mem-cpu-load && git clone https://github.com/thewtex/tmux-mem-cpu-load.git /tmp/tmux-mem-cpu-load && \
cd /tmp/tmux-mem-cpu-load && cmake . && make && sudo make install && \
rm -fr /tmp/tmux-mem-cpu-load
fi
fi
}
function configureVim() {
askYesNo "configure" "vim"
if ${shouldInstall}; then
backup ~/.vim ~/.vimrc
notify "Cloning David Xia's Vim config and symlinking ~/.vimrc -> ~/.vim/vimrc"
cd ~ && git clone https://github.com/davidxia/vim-config.git ~/.vim && \
cd ~/.vim && git submodule update --init bundle/vundle && cd ~ && \
vim -u ~/.vim/bundles.vim +BundleInstall +qall && ln -s ~/.vim/vimrc ~/.vimrc
fi
}
function configureGit() {
askYesNo "configure" "git"
if ${shouldInstall}; then
printf "\n"
printf "\e[0;32m"' _ _ '"\e[0m\n"
printf "\e[0;32m"' (_) | '"\e[0m\n"
printf "\e[0;32m"' __ _ _| |_ '"\e[0m\n"
printf "\e[0;32m"' / _` | | __|'"\e[0m\n"
printf "\e[0;32m"' | (_| | | |_ '"\e[0m\n"
printf "\e[0;32m"' \__, |_|\__|'"\e[0m\n"
printf "\e[0;32m"' __/ | '"\e[0m\n"
printf "\e[0;32m"' |___/ '"\e[0m\n\n"
backup ~/.git-config ~/.gitconfig ~/.gitignore_global
notify "Cloning David Xia's git-config"
notify "Symlinking ~/.gitconfig -> ~/.git-config/gitconfig"
notify "Symlinking ~/.gitignore_global -> ~/.git-config/gitignore_global"
git clone https://github.com/davidxia/git-config.git ~/.git-config && \
ln -s ~/.git-config/gitconfig ~/.gitconfig && \
ln -s ~/.git-config/gitignore_global ~/.gitignore_global
notify "Setting up git config\n"
notify "Initializing git hooks in ~/.git_template\n"
git config --global init.templatedir '~/.git_template'
mkdir -p ~/.git_template/hooks
curl -fsSL https://raw.github.com/davidxia/bootstrap_dotfiles/master/git_template/hooks/ctags > ~/.git_template/hooks/ctags
curl -fsSL https://raw.github.com/davidxia/bootstrap_dotfiles/master/git_template/hooks/post-commit > ~/.git_template/hooks/post-commit
curl -fsSL https://raw.github.com/davidxia/bootstrap_dotfiles/master/git_template/hooks/post-merge > ~/.git_template/hooks/post-merge
curl -fsSL https://raw.github.com/davidxia/bootstrap_dotfiles/master/git_template/hooks/post-checkout > ~/.git_template/hooks/post-checkout
curl -fsSL https://raw.github.com/davidxia/bootstrap_dotfiles/master/git_template/hooks/post-rewrite > ~/.git_template/hooks/post-rewrite
chmod u+x ~/.git_template/hooks/*
git config --global alias.ctags '!.git/hooks/ctags'
ask "What's your name?"
read git_name
git config --global user.name "${git_name}"
ask "What's your email?"
read git_email
git config --global user.email "${git_email}"
git config --list
pause "Here's your global git config. You can edit this later anytime. Press [Enter] key to continue."
fi
}
function installPip() {
if ! pip_loc="$(which pip)" || [ -z "${pip_loc}" ]; then
askYesNo "install" "python distribute and pip"
if ${shouldInstall}; then
printf "\n"
printf "\e[0;32m"' _ '"\e[0m\n"
printf "\e[0;32m"' (_) '"\e[0m\n"
printf "\e[0;32m"' _ __ _ _ __ '"\e[0m\n"
printf "\e[0;32m"' | |_ \| | |_ \ '"\e[0m\n"
printf "\e[0;32m"' | |_) | | |_) |'"\e[0m\n"
printf "\e[0;32m"' | .__/|_| .__/ '"\e[0m\n"
printf "\e[0;32m"' | | | | '"\e[0m\n"
printf "\e[0;32m"' |_| |_| '"\e[0m\n\n"
notify "Installing python distribute and pip"
cd ~ && curl http://python-distribute.org/distribute_setup.py | sudo python && \
curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | sudo python
cd ~ && rm distribute-*.tar.gz
fi
fi
}
function installPipPkgs() {
pipPkgs="ipython virtualenv virtualenvwrapper"
askYesNo "install" "pip packages: ${pipPkgs}"
if ${shouldInstall}; then
if pipLoc="$(which pip)" && [ ! -z "${pipLoc}" ]; then
notify "Installing pip packages: ${pipPkgs}"
sudo pip install ${pipPkgs}
fi
fi
configureVirtualenvwrapper
}
function configureVirtualenvwrapper() {
askYesNo "configure" "virtualenvwrapper"
if ${shouldInstall}; then
notify "Configuring virtualenvwrapper"
if [ "$(uname -s)" == "Darwin" ]; then
echo "[ -f /usr/local/bin/virtualenvwrapper.sh ] && source /usr/local/bin/virtualenvwrapper.sh" \
> ~/.oh-my-zsh/custom/virtualenvwrapper.zsh
fi
fi
}
# Debian or Ubuntu based distributions
if [ -e /usr/bin/lsb_release ]; then
distro=$(/usr/bin/lsb_release --codename --short)
if [ "${distro}" != "precise" -a "${distro}" != "squeeze" -a "${distro}" != "trusty" ]; then
die "unsupported distribution: ${distro}"
fi
aptInstall "${distro}"
fi;
# Mac OS X
[ "$(uname -s)" == "Darwin" ] && installHomebrew && installBrews
configureZsh
configureTmux
installTmuxPowerline
installTmuxPowerlineSegs
configureVim
configureGit
installPip
installPipPkgs