forked from kennylevinsen/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup
More file actions
executable file
·422 lines (370 loc) · 13.6 KB
/
setup
File metadata and controls
executable file
·422 lines (370 loc) · 13.6 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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
#!/bin/sh
#
# Dotfiles setup script from https://github.com/Joushou/dotfiles
#
# Use as you please, but give some credit, will ya'?
#
GITPATH=https://github.com/Joushou/dotfiles.git
USERHOME=~
TARGET=$USERHOME/.dotfiles
LOGFILE=$TARGET/setup_log
# Toggles for command-line options
OPT_UPGRADE=0
OPT_UPDATE=0
OPT_VERIFY=0
OPT_DRYRUN=1
OPT_CASK=0
OPT_CONF=0
OPT_TOOLCHAIN=0
OPT_SHELL=0
OPT_GITCLONE=0
OPT_DUPES=0
OPT_VERBOSE=1
# Color stuff
case $TERM in
xterm*)
RED_START="\033[1;31m"
GREEN_START="\033[1;32m"
YELLOW_START="\033[1;33m"
WHITE_START="\033[1;37m"
COLOR_END="\033[0m"
;;
screen*)
RED_START="\033[1;31m"
GREEN_START="\033[1;32m"
YELLOW_START="\033[1;33m"
WHITE_START="\033[1;37m"
COLOR_END="\033[0m"
;;
esac
###############################################################################
# #
# Utility functions #
# #
###############################################################################
# This is stupid, but it works
is_set() {
return $1
}
# Checks if the tool is available
in_path() {
which $1 1>/dev/null 2>/dev/null
ret=$?
printf '%b' "[tool availability check for $1: $ret]\n" >> $LOGFILE
return $ret
}
# Log error and exit
error() {
printf '%b' "$RED_START! $1$COLOR_END\n"
printf '%b' "! $1\n" >> $LOGFILE
exit 1
}
# Log
log() {
printf '%b' "$GREEN_START> $WHITE_START$1$COLOR_END\n"
printf '%b' "> $1\n" >> $LOGFILE
}
# Run, log and handle error
run() {
printf '%b' "$GREEN_START> $YELLOW_START$1$COLOR_END\n"
printf '%b' "> $1\n" >> $LOGFILE
cmd=${@#$1}
success=1
printf '%b' "[$1: $cmd]\n" >> $LOGFILE
# TODO Fix logging in verbose mode
if is_set $OPT_VERBOSE
then
is_set $OPT_DRYRUN || $cmd && success=0
else
is_set $OPT_DRYRUN || $cmd >> $LOGFILE 2>&1 && success=0
fi
printf '%b' "\n" >> $LOGFILE
if [ "$success" = "1" ]
then
echo $output
error "FAILED, check $LOGFILE for details"
fi
}
###############################################################################
# #
# Generic Setup #
# #
###############################################################################
# Setup the dotfile git repo
setup_git() {
log "Setting up dotfiles repo"
# Hacky "DIR IS NOT EMPTY!" workaround
run "Initialising git" git init
run "Adding remote" git remote add origin $GITPATH
run "Pulling master" git pull --force origin master
run "Initialising submodules" git submodule update --init
}
# Setup symlinks
setup_symlinks() {
log "Setting up symlinks"
run "zshrc" ln -s $TARGET/zshrc $USERHOME/.zshrc
run "vimrc" ln -s $TARGET/vimrc $USERHOME/.vimrc
run "gvimrc" ln -s $TARGET/gvimrc $USERHOME/.gvimrc
run "nvimrc" ln -s $TARGET/vimrc $USERHOME/.nvimrc
run "nvim" ln -s $USERHOME/.vim $USERHOME/.nvim
}
# Prepare vim
setup_vim() {
log "Setting up VIM"
run "Make extra .vim subdirectories" mkdir -p $USERHOME/.vim/backup $USERHOME/.vim/swap $USERHOME/.vim/colors
run "Clone Vundle" git clone https://github.com/gmarik/Vundle.vim.git $USERHOME/.vim/bundle/Vundle.vim
run "Download Molokai" eval "curl https://raw.githubusercontent.com/tomasr/molokai/master/colors/molokai.vim > $USERHOME/.vim/colors/molokai.vim"
run "Install plugins" eval "vim +PluginInstall +qall > /dev/null" # Avoid garbage
sleep 0.5
run "Ensure xon isn't set" eval "stty -ixon || true"
run "Make tty sane" eval "stty sane || true"
}
# Prepare antigen
setup_zsh() {
log "Setting up zsh"
run "Downloading zgen" eval "curl https://raw.githubusercontent.com/tarjoilija/zgen/master/zgen.zsh > $USERHOME/.zgen.zsh"
run "Initialising zsh" eval "zsh $USERHOME/.zshrc > /dev/null" # Avoid garbage
run "Changing user shell" sudo chsh -s $(which zsh) $USER
}
# Setup dispatcher
setup() {
is_set $OPT_GITCLONE && setup_git
setup_symlinks
setup_vim
is_set $OPT_SHELL && setup_zsh
}
###############################################################################
# #
# OS X specific stuff #
# #
# TODO setup powerline fonts #
###############################################################################
# Set defaults
osx_conf() {
log "Configuring OS X"
run "Be silent on boot" sudo nvram SystemAudioVolume=" "
run "Increasing window resize speed" defaults write NSGlobalDomain NSWindowResizeTime -float 0.001
run "Increasing mission control animation speed" defaults write com.apple.dock expose-animation-duration -float 0.1
run "Setting fast key repeat" defaults write NSGlobalDomain KeyRepeat -int 0
run "Always use sub-pixel font rendering" defaults write NSGlobalDomain AppleFontSmoothing -int 2
run "Setting Dock scaling effect" defaults write com.apple.dock mineffect -string "scale"
run "Setting Terminal.app UTF-8 mode" defaults write com.apple.terminal StringEncodings -array 4
run "Unhiding ~/Library" chflags nohidden $USERHOME/Library
}
# Install brew
brew_install() {
run "Install brew" ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
run "Making paths file" sudo tee /etc/paths <<EOS
/usr/local/bin
/usr/local/opt/coreutils/libexec/gnubin
/usr/bin
/bin
/usr/local/sbin
/usr/sbin
/sbin
EOS
eval $(/usr/libexec/path_helper -s)
}
# Setup brew and install packages
pre_osx() {
is_set $OPT_CONF && osx_conf
log "Installing packages"
in_path brew || brew_install
is_set $OPT_UPDATE && run "Updating brew" brew update
is_set $OPT_UPGRADE && run "Upgrading brew" brew upgrade
is_set $OPT_VERIFY && run "Verifying brew" brew doctor
is_set $OPT_DUPES && run "Installing dupe tap" brew tap homebrew/dupes
is_set $OPT_CASK && run "Setting up cask" brew install caskroom/cask/brew-cask
# TODO zsh is technically a dupe, as zsh is bundled in old version
is_set $OPT_SHELL && run "Shell" brew install tmux zsh
is_set $OPT_DUPES && run "Newer shell utils" brew install coreutils findutils grep
run "Shell utils" brew install ascii
run "Version control" brew install git mercurial
run "Code assist" brew install ctags
is_set $OPT_TOOLCHAIN && run "Toolchain" brew install autoconf automake go
# editor stuff
is_set $OPT_DUPES && run "VIM" brew install vim
is_set $OPT_CASK && run "MacVIM" brew cask install macvim flashlight iterm2 arduino
}
# Cleanup after brew and git
post_osx() {
log "Cleaning up"
run "Git" git gc --aggressive
run "Brew" brew cleanup
}
###############################################################################
# #
# Linux #
# #
# TODO: Add pacman support. #
###############################################################################
# Install packages
pre_linux() {
if in_path apt-get
then
log "Installing packages with APT"
is_set $OPT_UPDATE && run "Updating APT" sudo apt-get -y update
is_set $OPT_UPGRADE && run "Upgrading packages" sudo apt-get -y upgrade
is_set $OPT_SHELL && run "Shell" sudo apt-get -y install tmux zsh
run "Shell utils" sudo apt-get -y install ascii
run "Version control" sudo apt-get -y install git mercurial
run "Code assist" sudo apt-get -y install ctags
is_set $OPT_TOOLCHAIN && run "Toolchain" sudo apt-get -y install binutils autoconf automake gdb clang golang
# editor stuff
run "VIM" sudo apt-get -y install vim
elif in_path yum
then
log "Installing packages with YUM"
is_set $OPT_UPGRADE && run "Updating YUM" sudo yum -y update
is_set $OPT_SHELL && run "Shell" sudo yum -y install tmux zsh
run "Shell utils" sudo yum -y install ascii
run "Version control" sudo yum -y install git mercurial
run "Code assist" sudo yum -y install ctags
is_set $OPT_TOOLCHAIN && run "Toolchain" sudo yum -y install binutils autoconf automake gdb clang golang
run "VIM" sudo yum -y install vim
elif in_path pacman
then
log "Installing packages with Pacman"
is_set $OPT_UPDATE && run "Updating pacman" sudo pacman --noconfirm -Sy
is_set $OPT_UPGRADE && run "Upgrading pacman" sudo pacman --noconfirm -Su
run "Shell" sudo pacman --noconfirm -S tmux zsh
run "Shell utils" sudo pacman --noconfirm -S ascii
run "Version control" sudo pacman --noconfirm -S git mercurial
run "Code assist" sudo pacman --noconfirm -S ctags
is_set $OPT_TOOLCHAIN && run "Toolchain" sudo pacman --noconfirm -S base-devel go
run "VIM" sudo pacman --noconfirm -S vim
else
error "Package manager unknown"
fi
}
# Cleanup apt and git
post_linux() {
log "Cleaning up"
run "Git" git gc --aggressive
in_path apt-get && run "APT" sudo apt-get clean
}
###############################################################################
# #
# BSD #
# #
###############################################################################
# Install packages
pre_bsd() {
if in_path pkg
then
log "Installing packages with pkg"
is_set $OPT_SHELL && run "Shell" sudo ASSUME_ALWAYS_YES=true pkg install tmux zsh
run "Version control" sudo ASSUME_ALWAYS_YES=true pkg install git mercurial
run "Code assist" sudo ASSUME_ALWAYS_YES=true pkg install ctags
is_set $OPT_TOOLCHAIN && run "Toolchain" sudo ASSUME_ALWAYS_YES=true pkg install binutils autoconf automake gdb clang-devel llvm-devel go
# editor stuff
run "VIM" sudo ASSUME_ALWAYS_YES=true pkg install vim
else
error "Package manager unknown"
fi
}
# Cleanup apt and git
post_bsd() {
log "Cleaning up"
run "Git" git gc --aggressive
in_path pkg && run "pkg" sudo ASSUME_ALWAYS_YES=true pkg clean
}
###############################################################################
# #
# Main #
# #
###############################################################################
#
# Handle parameters
#
# TODO: Add force OS option
mkdir -p $TARGET
for i in $@
do
case $i in
--no-upgrade)
OPT_UPGRADE=1
;;
--no-update)
OPT_UPDATE=1
;;
--no-verify)
OPT_VERIFY=1
;;
--no-cask)
OPT_CASK=1
;;
--no-conf)
OPT_CONF=1
;;
--no-toolchain)
OPT_TOOLCHAIN=1
;;
--no-shell)
OPT_SHELL=1
;;
--no-dupes)
OPT_DUPES=1
;;
--no-gitclone)
OPT_GITCLONE=1
;;
--dry-run)
OPT_DRYRUN=0
;;
--verbose)
OPT_VERBOSE=0
;;
*)
error "Unknown parameter: $i"
;;
esac
done
log "Starting setup"
run "Entering directory" cd $TARGET
run "Requesting sudo rights" sudo -v
#
# OS detect
#
darwin() {
log "OS X detected"
pre_osx
setup
post_osx
}
linux() {
log "Linux detected"
pre_linux
setup
post_linux
}
bsd() {
log "BSD detected"
pre_bsd
setup
post_bsd
}
os=$(uname)
case "$os" in
Darwin)
darwin
;;
Linux)
linux
;;
FreeBSD)
bsd
;;
*)
# We might just be on a dash-based OS which doesn't give us OSTYPE (ubuntu/debian)
if [ -e /etc/debian_version ]
then
pre_linux
setup
post_linux
else
error "Platform of type $OSTYPE not supported"
fi
;;
esac
log "All done"