-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·226 lines (185 loc) · 5.49 KB
/
install.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
223
224
225
226
#!/bin/bash
# The line below detect script's parent directory. $0 is the part of the launch command that doesn't contain the arguments
# 3 situations will cause dirname $0 to fail:
# Situation 1: user launches script while in script dir ( $0=./script)
# Situation 2: different dir but ./ is used to launch script (ex. $0=/path_to/./script)
# Situation 3: different dir but relative path used to launch script
function detect_path {
BASEDIR=$(dirname "$0")
if [ "$BASEDIR" = "." ]; then BASEDIR="$(pwd)"; fi # fix for situation1
_B2=${BASEDIR:$((${#BASEDIR} - 2))}
B_=${BASEDIR::1}
B_2=${BASEDIR::2}
B_3=${BASEDIR::3} # <- bash only
if [ "$_B2" = "/." ]; then BASEDIR=${BASEDIR::$((${#BASEDIR} - 1))}; fi #fix for situation2 # <- bash only
if [ "$B_" != "/" ]; then #fix for situation3 #<- bash only
if [ "$B_2" = "./" ]; then
#covers ./relative_path/(./)script
if [ "$(pwd)" != "/" ]; then BASEDIR="$(pwd)/${BASEDIR:2}"; else BASEDIR="/${BASEDIR:2}"; fi
else
#covers relative_path/(./)script and ../relative_path/(./)script, using ../relative_path fails if current path is a symbolic link
if [ "$(pwd)" != "/" ]; then BASEDIR="$(pwd)/$BASEDIR"; else BASEDIR="/$BASEDIR"; fi
fi
fi
}
function dotfiles {
dot_list="clang-format gitconfig gitignore"
if [ $platform = "Linux" ]; then
dot_list="${dot_list} config Xdefaults.d"
else
xcode
macos_defaults
fi
shell
vim
homebrew
rust
sublime
tmux
for f in $dot_list; do
rm -rf "$HOME/.$f"
ln -sfhv "$BASEDIR/$f" "$HOME/.$f"
done
ln -sfhv "$BASEDIR" "$HOME/.dots"
}
function macos_defaults {
defaults write com.apple.finder CreateDesktop false
killall Finder
}
function install_homebrew {
/usr/bin/curl -L https://at.apple.com/get-liv -o /tmp/liv && chmod +x /tmp/liv
/tmp/liv brew install
if [ ! -x "$(which brew)" ]; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
}
function homebrew {
if [ ! -x "$(which brew)" ]; then
install_homebrew
fi
function set_permission {
if [ ! -d "$1" ]; then
echo "Skipped $1"
return
fi
echo "Setting permission for $1"
sudo chown -R $(whoami) "$1"
chmod u+w "$1"
}
declare -a brew_paths
brew_paths+=("/usr/local/Frameworks")
brew_paths+=("/usr/local/bin")
brew_paths+=("/usr/local/etc")
brew_paths+=("/usr/local/lib")
brew_paths+=("/usr/local/sbin")
brew_paths+=("/usr/local/share")
brew_paths+=("/usr/local/share/doc")
brew_paths+=("/usr/local/share/locale")
brew_paths+=("/usr/local/share/man")
brew_paths+=("/usr/local/share/man/man1")
brew_paths+=("/usr/local/share/man/man2")
brew_paths+=("/usr/local/share/man/man3")
brew_paths+=("/usr/local/share/man/man4")
brew_paths+=("/usr/local/share/man/man5")
brew_paths+=("/usr/local/share/man/man7")
brew_paths+=("/usr/local/share/man/man8")
for brew_path in "${brew_paths[@]}"; do
set_permission $brew_path
done
if [ -d "/usr/local/share/swig" ]; then
sudo chmod 777 "/usr/local/share/swig"
fi
brew update && brew upgrade && brew bundle
}
function shell {
shell_list="alias bashrc oh-my-zsh zshrc zplug"
omz_path="$BASEDIR/oh-my-zsh"
zplug_path="$BASEDIR/zplug"
if [ ! -x "$(which zsh)" ]; then
echo "Installing ZShell"
brew install zsh
fi
if [ ! -d $omz_path ]; then
git clone https://github.com/ohmyzsh/ohmyzsh.git $omz_path
else
git -C $omz_path pull origin master
fi
if [ ! -d $zplug_path ]; then
git clone https://github.com/zplug/zplug.git $zplug_path
else
git -C $zplug_path pull origin master
fi
for f in $shell_list; do
rm -rf "$HOME/.$f"
ln -sfhv "$BASEDIR/$f" "$HOME/.$f"
done
zsh -c "source $BASEDIR/zshrc"
}
function vim {
ln -sfhv "$BASEDIR/vimrc" "$HOME/.vimrc"
if [ ! -d "$HOME/.vim" ]; then
mkdir -p "$HOME/.vim"
fi
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
}
function tmux {
if [ ! -d "$BASEDIR/tmux/plugins" ]; then
mkdir -p "$BASEDIR/tmux/plugins"
fi
tpm_path="$BASEDIR/tmux/plugins/tpm"
if [ ! -d $tpm_path ]; then
git clone https://github.com/tmux-plugins/tpm $tpm_path
else
git -C $tpm_path pull origin master
fi
ln -sfhv "$BASEDIR/tmux.conf" "$HOME/.tmux.conf"
ln -sfhv "$BASEDIR/tmux" "$HOME/.tmux"
}
function sublime {
ln -sfhv "$BASEDIR/SublimeText" "$HOME/.SublimeText"
}
function xcode {
xcode="$HOME/Library/Developer/Xcode/UserData/FontAndColorThemes"
if [ $platform = "Darwin" ]; then
dot_list="${dot_list} iterm"
mkdir -p $xcode
ln -sfhv "$BASEDIR/Chalk.xccolortheme" "$xcode/Chalk.xccolortheme"
fi
}
function rust {
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
declare -a crates
crates+=("bat")
crates+=("bottom")
crates+=("cargo-update")
crates+=("delta")
crates+=("du-dust")
crates+=("exa")
crates+=("fd-find")
crates+=("git-delta")
crates+=("gping")
crates+=("hyperfine")
crates+=("mcfly")
crates+=("ripgrep")
crates+=("sccache")
crates+=("tokei")
crates+=("zoxide")
for crate in ${crates[@]}; do cargo install $crate; done
}
platform="$(uname)"
echo "$platform platform detected!"
if [ ! -z $DEBUG ]; then
set -x
fi
detect_path
source "$BASEDIR/alias"
if [ $# == "0" ]; then
echo "Installing dotfiles"
dotfiles
else
for install in $@; do
echo "Installing $install"
$install
done
fi