-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.bash
executable file
·330 lines (276 loc) · 7.09 KB
/
install.bash
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
#!/usr/bin/env bash
source "$(dirname "$0")/utils.bash"
set -x
# $1 - file
# $2 - line
ensure_exists_and_contains () {
if [[ ! -e "$1" ]]; then
echo "$2" > "$1"
else
found="$(true && grep "^$2$" "$1")"
if [[ -z "$found" ]]; then
echo "$2" >> "$1"
fi
fi
}
make_symlink () {
mkdir -p "$(dirname "$1")"
if [[ -e "$1" ]]; then
rm -rf "$1"
fi
ln -sf "$2" "$1"
}
# $1 - link
# $2 - target
maybe_symlink () {
mkdir -p "$(dirname "$1")"
if [[ ! -e "$1" ]]; then
make_symlink "$1" "$2"
fi
}
# Symlinks all contents of the target directory into the source directory
symlink_contents () {
for f in $2/*; do
if [[ -e "$f" ]]; then
if [[ ! -d "$f" ]]; then
echo "linking $1/$(basename $f) -> $f"
make_symlink "$1/$(basename $f)" "$f"
fi
fi
done
return 0
}
# Directory of this repo
CONFIG="$(dirname "$(realpath "$0")")"
# Make sure ~/install/bin exists for future steps
BIN="$(readlink -fm "$HOME/install/bin")"
mkdir -p "$BIN"
install_base () {
# If ~/.bashrc doesn't exist, make it
source_config="source \"$CONFIG/.bashrc\""
ensure_exists_and_contains "$HOME/.bashrc" "$source_config"
# If ~/.bash_profile doesn't exist, make it and source bashrc
source_bashrc="source ~/.bashrc"
ensure_exists_and_contains "$HOME/.bash_profile" "$source_bashrc"
# If ~/.bash_completion.d doesn't exist, make it
if [[ ! -e "$HOME/.bash_completion.d" ]]; then
mkdir "$HOME/.bash_completion.d"
fi
make_symlink "$HOME/.ackrc" "$CONFIG/.ackrc"
make_symlink "$HOME/.alacritty.yml" "$CONFIG/.alacritty.yml"
}
build_ncurses() {
# TODO: check if this has already been configured/built
pushd "$CONFIG/ncurses"
./configure --prefix="$CONFIG/ncurses" && make
make_res=$?
popd
if [[ "$make_res" != 0 ]]; then
echo "ncurses build failed"
return 1
fi
}
install_vim () {
# TODO: check installed version vs checked-in version, uninstall and reinstall if stale, alternatively have a '--force' option
# Check if vim is already installed with clipboard support
#if which vim > /dev/null; then
# if [[ -n "$(vim --version | grep +clipboard)" ]]; then
# return 0
# fi
#fi
build_ncurses
# TODO: needed libx11-dev, libxt-dev, and tinfo-dev installed
ncurses_lib="$CONFIG/ncurses/lib/"
#configure_flags="--with-x --with-features=normal --prefix=$CONFIG/vim --with-tlib=tinfo"
configure_flags="--with-features=normal --prefix=$CONFIG/vim --enable-multibyte --with-tlib=ncurses --enable-gui=no"
pushd "$CONFIG/vim"
./configure $configure_flags && pushd src && make install && popd
make_res=$?
popd
if [[ "$make_res" != 0 ]]; then
echo "vim build failed"
return 1
fi
echo source: $BIN
echo target: $CONFIG/vim/bin
symlink_contents $BIN $CONFIG/vim/bin
}
configure_vim() {
# Symlink vimrc - overwrite any existing one
make_symlink "$HOME/.vimrc" "$CONFIG/.vimrc"
return 0
}
install_vim_modules() {
# Symlink vim resources to this repo if missing
make_symlink "$HOME/.vim/colors/custom.vim" "$CONFIG/.vim/colors/custom.vim"
make_symlink "$HOME/.vim/autoload/pathogen.vim" "$CONFIG/vim-pathogen/autoload/pathogen.vim"
make_symlink "$HOME/.vim/bundle/vim-airline" "$CONFIG/vim-airline"
make_symlink "$HOME/.vim/bundle/vim-airline-themes" "$CONFIG/vim-airline-themes"
make_symlink "$HOME/.vim/bundle/vim-cooklang" "$CONFIG/vim-cooklang"
make_symlink "$HOME/.vim/bundle/vim-fugitive" "$CONFIG/vim-fugitive"
make_symlink "$HOME/.vim/bundle/vim-jsx" "$CONFIG/vim-jsx-improve"
make_symlink "$HOME/.vim/bundle/vim-toml" "$CONFIG/vim-toml"
make_symlink "$HOME/.vim/bundle/typescript-vim" "$CONFIG/typescript-vim"
make_symlink "$HOME/.vim/bundle/tagbar" "$CONFIG/tagbar"
return 0
}
install_gitconfig() {
gitconfig="$CONFIG/.gitconfig"
if [[ -z "$(git config --global --get-all include.path | grep "^$gitconfig$")" ]]; then
git config --global --add include.path "$gitconfig"
fi
}
install_clang () {
if which clang++ > /dev/null; then
return 0
fi
}
install_gcc () {
if which g++ > /dev/null; then
return 0
fi
}
install_nvm () {
# This loads nvm
\. "$CONFIG/.nvm/nvm.sh"
# Our bashrc already points to the submodule, just install a node version
nvm install --lts
nvm install-latest-npm
return 0
}
install_node () {
return 0
}
install_rbenv () {
if which rbenv > /dev/null; then
return 0
fi
git submodule init rbenv
make_symlink "$HOME/.rbenv" "$CONFIG/rbenv"
# TODO: make sure there aren't more things added at runtime
symlink_contents "$BIN" "$CONFIG/rbenv/bin"
}
install_gvm () {
if which gvm > /dev/null; then
return 0
fi
GVM_NO_UPDATE_PROFILE=true bash "$CONFIG/gvm/binscripts/gvm-installer"
}
install_go () {
source ~/.gvm/scripts/gvm
# Later versions of go require a go compiler to build, install v1.4 from binary
gvm install go1.4 -B
gvm use go1.4
export GOROOT_BOOTSTRAP=$GOROOT
gvm install go1.13.3
gvm use go1.13.3 --default
}
install_gotags () {
if which gotags > /dev/null; then
return 0
fi
go get -u github.com/jstemmer/gotags
}
install_pyenv () {
if which pyenv > /dev/null; then
return 0
fi
git submodule init pyenv
make_symlink "$HOME/.pyenv" "$CONFIG/pyenv"
# TODO: this probably won't work because the python link isn't there yet
symlink_contents "$BIN" "$CONFIG/pyenv/bin"
}
install_ipython () {
if which ipython > /dev/null; then
return 0
fi
}
configure_ipython() {
make_symlink "$HOME/.ipython" "$CONFIG/.ipython"
return 0
}
install_rustup () {
if which rustup > /dev/null; then
return 0
fi
curl https://sh.rustup.rs -sSf | sh -s -- -y
}
default_install=(base vim git)
all=(${default_install[@]} c++ node ruby go python rust)
for name in $@; do
case "$name" in
all)
to_install+=$all
;;
*)
to_install+=("$name")
;;
esac
done
if [[ -z "$to_install" ]]; then
to_install=${default_install[@]}
fi
to_install=($(for v in "${to_install[@]}"; do echo "$v"; done | sort | uniq | xargs))
echo "Initializing submodules"
git submodule init
echo "Updating submodules"
git submodule update
echo "to install: ${to_install[@]}"
for name in "${to_install[@]}"; do
case "$name" in
base)
echo "installing base configuration"
install_base
;;
vim)
echo "installing vim"
install_vim
configure_vim
install_vim_modules
;;
vim-config)
echo "configuring vim"
configure_vim
install_vim_modules
;;
git)
echo "installing git"
install_gitconfig
;;
c++)
echo "installing c++"
install_clang
install_gcc
;;
node)
echo "installing node"
install_nvm
install_node
;;
ruby)
echo "installing ruby"
install_rbenv
;;
go)
echo "installing go"
install_gvm
install_go
install_gotags
;;
python)
echo "installing python"
install_pyenv
install_ipython
configure_ipython
;;
rust)
echo "installing rust"
install_rustup
;;
*)
echo "Unrecognized environment: $name"
esac
done
# TODO: make it easy to set up ssh key with github
# maybe generate a key and print it for copy/paste?
# open in a browser: https://github.com/settings/keys