-
Notifications
You must be signed in to change notification settings - Fork 9
/
install.sh
executable file
·244 lines (230 loc) · 5.5 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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#!/usr/bin/env bash
set -euo pipefail
DIRNAME="$(dirname "$0")"
DIR="$(cd "$DIRNAME" && pwd)"
echoerr() {
echo "$@" 1>&2
}
usage() {
echo "usage: $(basename "$0") <command>"
echo ''
echo 'Available commands:'
echo ' link Install symbolic links'
echo ' asdf Install asdf'
echo ' brew Install Homebrew on macOS (or Linux)'
echo ' chruby Install chruby'
echo ' formulae Install Homebrew formulae using Brewfile'
echo ' mise Install mise'
echo ' n Install n'
echo ' pyenv Install pyenv with pyenv-virtualenv'
echo ' rbenv Install rbenv'
echo ' ruby-install Install ruby-install'
echo ' rustup Install rustup'
echo ' rvm Install RVM'
echo ' weechat Install WeeChat configuration'
}
init_submodules() {
(cd "$DIR" && git submodule init)
(cd "$DIR" && git submodule update)
}
git_clone() {
if [ ! -e "$HOME/$2" ]; then
echo "Cloning '$1'..."
git clone "$1" "$HOME/$2"
else
# shellcheck disable=SC2088
echoerr "~/$2 already exists."
fi
}
rename_with_backup() {
if [ ! -e "$2" ]; then
if mv "$1" "$2"; then
return 0
fi
else
local num
num=1
while [ -e "$2.~$num~" ]; do
(( num++ ))
done
if mv "$2" "$2.~$num~" && mv "$1" "$2"; then
return 0
fi
fi
return 1
}
replace_file() {
DEST=${2:-.$1}
if [ -e "$DIR/$1" ]; then
SRC="$DIR/$1"
else
SRC="$HOME/$1"
if [ ! -e "$SRC" ]; then
echoerr "Failed to find $1"
return
fi
fi
# http://www.tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html
# File exists and is a directory.
[ ! -d "$(dirname "$HOME/$DEST")" ] && mkdir -p "$(dirname "$HOME/$DEST")"
# FILE exists and is a symbolic link.
if [ -h "$HOME/$DEST" ]; then
if rm "$HOME/$DEST" && ln -s "$SRC" "$HOME/$DEST"; then
echo "Updated ~/$DEST"
else
echoerr "Failed to update ~/$DEST"
fi
# FILE exists.
elif [ -e "$HOME/$DEST" ]; then
if rename_with_backup "$HOME/$DEST" "$HOME/$DEST.old"; then
echo "Renamed ~/$DEST to ~/$DEST.old"
if ln -s "$SRC" "$HOME/$DEST"; then
echo "Created ~/$DEST"
else
echoerr "Failed to create ~/$DEST"
fi
else
echoerr "Failed to rename ~/$DEST to ~/$DEST.old"
fi
else
if ln -s "$SRC" "$HOME/$DEST"; then
echo "Created ~/$DEST"
else
echoerr "Failed to create ~/$DEST"
fi
fi
}
install_link() {
init_submodules
for FILENAME in \
'aliases' \
'bashrc' \
'ctags' \
'gemrc' \
'git-templates' \
'gitattributes_global' \
'gitconfig' \
'gitignore_global' \
'ideavimrc' \
'inputrc' \
'irbrc' \
'minttyrc' \
'npmrc' \
'p10k.zsh' \
'profile' \
'screenrc' \
'tmux.conf' \
'vimrc' \
'vintrc.yaml' \
'zprofile' \
'zshrc'
do
replace_file "$FILENAME"
done
replace_file 'bat/config' '.config/bat/config'
replace_file 'gdb-dashboard/.gdbinit' '.gdbinit'
replace_file 'gdbinit.d'
if [ "$(uname)" = 'Darwin' ]; then
replace_file 'lazygit/config.yml' 'Library/Application Support/lazygit/config.yml'
else
replace_file 'lazygit/config.yml' '.config/lazygit/config.yml'
fi
replace_file 'pip.conf' '.pip/pip.conf'
replace_file 'tpm' '.tmux/plugins/tpm'
[ ! -d "$HOME/.vim" ] && mkdir "$HOME/.vim"
replace_file '.vim' '.config/nvim'
replace_file 'vimrc' '.config/nvim/init.vim'
for FILENAME in \
'diff-highlight' \
'diff-hunk-list' \
'pyg' \
'server'
do
replace_file "bin/$FILENAME" "bin/$FILENAME"
done
echo 'Done.'
}
if [ "$#" -ne 1 ]; then
usage
exit 1
fi
case "$1" in
link)
install_link
;;
asdf)
if [ "$(uname)" = 'Darwin' ]; then
brew install asdf
else
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.13.1
fi
;;
brew)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
;;
chruby)
if [ "$(uname)" = 'Darwin' ]; then
brew install chruby
else
wget https://github.com/postmodern/chruby/releases/download/v0.3.9/chruby-0.3.9.tar.gz
tar -xzvf chruby-0.3.9.tar.gz
cd chruby-0.3.9/
sudo make install
fi
;;
formulae)
brew bundle --file="${DIR}/Brewfile" --no-lock --no-upgrade
;;
mise)
if [ "$(uname)" = 'Darwin' ]; then
brew install mise
else
curl https://mise.run | sh
fi
;;
n)
if [ "$(uname)" = 'Darwin' ]; then
brew install n
else
curl -L https://bit.ly/n-install | N_PREFIX="$HOME/.n" bash -s -- -y
fi
;;
pyenv)
if [ "$(uname)" = 'Darwin' ]; then
brew install pyenv
brew install pyenv-virtualenv
else
curl https://pyenv.run | bash
fi
;;
rbenv)
if [ "$(uname)" = 'Darwin' ]; then
brew install rbenv
else
git_clone https://github.com/rbenv/rbenv.git .rbenv
git_clone https://github.com/rbenv/ruby-build.git .rbenv/plugins/ruby-build
fi
;;
ruby-install)
if [ "$(uname)" = 'Darwin' ]; then
brew install ruby-install
else
wget https://github.com/postmodern/ruby-install/releases/download/v0.9.2/ruby-install-0.9.2.tar.gz
tar -xzvf ruby-install-0.9.2.tar.gz
cd ruby-install-0.9.2/
sudo make install
fi
;;
rustup)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
;;
rvm)
\curl -sSL https://get.rvm.io | bash -s stable
;;
weechat)
replace_file 'weechat'
;;
*)
usage
;;
esac