-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
557 lines (470 loc) · 13.6 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
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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
#!/bin/bash
set -e
usage() {
cat << EOF
usage: options
This script install an opinionated debian environment.
OPTIONS:
--all Install everything
--tools Install tools
--tmux Install tmux
--vim Install vim
--zsh Install zsh
-co, --configure-only Configure only, don't install anything
-h, --help Show this message
EOF
}
CONFIGURE_ONLY=false
INSTALL_ALL=false
INSTALL_VIM=false
INSTALL_TMUX=false
INSTALL_TOOLS=false
INSTALL_ZSH=false
base_packages=(
automake
autoconf
apt-transport-https
bison
build-essential
curl
file
git
htop
libbz2-dev
libffi-dev
liblzma-dev
libncurses5
libncursesw5
libncurses5-dev
libncursesw5-dev
libpq-dev
libsqlite3-dev
libssl-dev
libreadline8
libreadline-dev
libtool
libyaml-dev
libxml2-dev
libxmlsec1-dev
libxslt-dev
linux-headers-generic
llvm
python3-openssl
software-properties-common
ssh
tk-dev
unixodbc-dev
unzip
xdg-utils
xz-utils
zlib1g
zlib1g-dev
)
zsh_packages=(
libuser
zsh
)
brew_base_packages=(
gcc
htop
jq
libpq
net-tools
# openssh - https://github.com/Homebrew/linuxbrew-core/pull/19684
openssl
readline
sqlite3
wget
xz
zlib
)
# Enable or disable colored logs
COLOR_LOG=true
## Color coded logging - https://misc.flogisoft.com/bash/tip_colors_and_formatting
error() {
if [ $COLOR_LOG = true ]; then
echo "[31m$1[0m" # Red FG
else
echo "$1"
fi
}
warn() {
if [ $COLOR_LOG = true ]; then
echo "[33m$1[0m" # Yellow FG
else
echo "$1"
fi
}
info() {
if [ $COLOR_LOG = true ]; then
echo "[32m$1[0m" # Green FG
else
echo "$1"
fi
}
debug() {
if [ $COLOR_LOG = true ]; then
echo "[36m$1[0m" # Cyan FG
else
echo "$1"
fi
}
asdf_install() {
# Performs asdf installs and set the installed version as the global version
# asdf_install [plugin] (version)
# If version is not defined, will install the latest version
info " - Installing $1"
set +e # ignore error
asdf plugin-add "$1"
status_code=$?
if [ $status_code -eq 0 ] || [ $status_code -eq 2 ]; then
echo "$1 is already added"
fi
set -e # exit on errors
# Get latest version so we can install and set it as global
if [ "$2" ]; then
latest="$(asdf latest $1 $2)"
else
latest="$(asdf latest $1)"
fi
# default to passed in version. (needed for java)
if [ ! "$latest" ]; then
latest="$2"
fi
asdf install "$1" "$latest"
asdf global "$1" "$latest"
}
perform_system_update() {
info "Updating packages"
sudo apt update
sudo apt upgrade -y
}
install_packages() {
info "Installing system packages"
packages="${base_packages[@]}"
if [ $INSTALL_ALL = true ]; then
packages="${packages} ${zsh_packages[@]}"
else
if [ $INSTALL_ZSH = true ]; then
packages="${packages} ${zsh_packages[@]}"
fi
fi
sudo apt install -y ${packages}
info "Installed system packages"
}
install_homebrew() {
if [ ! -f "/home/linuxbrew/.linuxbrew/bin/brew" ]; then
info "Installing Homebrew"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" </dev/null
echo 'eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)' >> $HOME/.zprofile
echo 'eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)' >> $HOME/.profile
info "Installed Homebrew"
else
debug "Homebrew is already installed, skipping..."
fi
if [ ! "$(command -v brew)" ]; then
info "Sourcing brew"
eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
fi
info "Installing Homebrew base packages"
brew install "${brew_base_packages[@]}"
info "Installed Homebrew base packages"
}
install_adsf() {
install_homebrew
if [ ! -f "$(brew --prefix asdf)/libexec/asdf.sh" ]; then
info "Installing asdf"
brew install asdf
echo -e "\n. $(brew --prefix asdf)/libexec/asdf.sh" >> ~/.bashrc
echo -e "\n. $(brew --prefix asdf)/etc/bash_completion.d/asdf.bash" >> ~/.bashrc
info "Installed asdf"
else
debug "asdf is already installed, skipping..."
fi
if [ ! "$(command -v asdf)" ]; then
info "Sourcing asdf"
. $(brew --prefix asdf)/libexec/asdf.sh
fi
}
install_zsh() {
info "Installing ZSH"
sudo apt install -y "${zsh_packages[@]}"
}
configure_zsh() {
info "Configuring ZSH"
# Install Antigen - https://github.com/zsh-users/antigen
mkdir -p $HOME/.antigen
curl -L git.io/antigen > $HOME/.antigen/antigen.zsh
wget https://github.com/MichielVanderlee/system_config/raw/master/.zshrc -O $HOME/.zshrc
wget https://github.com/MichielVanderlee/system_config/raw/master/.p10k.zsh -O $HOME/.p10k.zsh
wget https://github.com/MichielVanderlee/system_config/raw/master/.powerlevel9k -O $HOME/.powerlevel9k
info "Updating shell"
sudo chsh -s $(which zsh) $(whoami)
}
install_vim() {
info "Installing Vim and Neovim"
install_homebrew
brew install vim nvim
info "Installed Vim and Neovim"
}
configure_vim() {
info "Configuring Vim and NeoVim"
# Install vim & neovim dependencies
curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
# Need to install via the vim linked python, not pyenv's python
python3 -m pip install --user \
pynvim \
black \
jedi
mkdir -p $HOME/.config/nvim
wget https://github.com/MichielVanderlee/system_config/raw/master/.vimrc -O $HOME/.vimrc
wget https://github.com/MichielVanderlee/system_config/raw/master/init.vim -O $HOME/.config/nvim/init.vim
wget https://github.com/MichielVanderlee/system_config/raw/master/vim.zip
unzip vim.zip -d $HOME
rm vim.zip
info "Configured Vim and NeoVim"
}
install_tmux() {
info "Installing Tmux"
install_adsf
asdf_install tmux
info "Installed Tmux"
}
configure_tmux() {
info "Configuring Tmux"
# Configure tmux
if [ ! -d "$HOME/.tmux/plugins/tpm" ]; then
git clone https://github.com/tmux-plugins/tpm $HOME/.tmux/plugins/tpm
wget https://github.com/MichielVanderlee/system_config/raw/master/.tmux.conf -O $HOME/.tmux.conf
info "Configured Tmux"
else
info "TMUX already configured, skipping..."
fi
}
install_tools() {
info "Installing Tools"
install_vscode
install_adsf
install_pyenv
# Install plugins
asdf_install golang
asdf_install java openjdk
asdf_install maven
asdf_install ruby
info "Installing nodejs"
## Install NVM because that's what I use on windows, so don't mix commands to switch node versions
# asdf plugin-add nodejs
# asdf install nodejs latest:12
# asdf global nodejs "$(asdf latest nodejs 12)"
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
pip install \
awscli \
pgcli
brew install pspg
# ptpython
if [[ ! -d "$HOME/.ptpython" ]]; then
info "Installing ptpython"
pip install ptpython
mkdir $HOME/.ptpython
wget -O $HOME/.ptpython/config.py https://github.com/MichielVanderlee/system_config/raw/master/.ptpython-config.py
fi
# colorls
info "Installing colorls"
$(asdf which gem) install colorls
# ammonite-repl
sudo curl -L https://github.com/lihaoyi/Ammonite/releases/download/1.6.9/2.13-1.6.9 -o /usr/local/bin/amm
sudo chmod +x /usr/local/bin/amm
install_docker
sudo sysctl -w vm.max_map_count=262144
info "Installed Tools"
}
install_pyenv() {
info "Installing PyEnv"
# PyEnv - because asdf does not support virtual environment, yet! - https://github.com/asdf-vm/asdf/issues/636
export PYENV_ROOT="$HOME/.pyenv"
if [[ ! -d "$PYENV_ROOT" ]]; then
# https://github.com/pyenv/pyenv/issues/1479#issuecomment-610683526
debug "Removing linuxbrew from path"
OLD_PATH="$PATH"
export PATH="$(echo $PATH | tr : '\n' | grep -v linuxbrew | paste -s -d:)"
git clone https://github.com/pyenv/pyenv.git $PYENV_ROOT
git clone https://github.com/pyenv/pyenv-virtualenv.git $PYENV_ROOT/plugins/pyenv-virtualenv
git clone https://github.com/momo-lab/pyenv-install-latest.git $PYENV_ROOT/plugins/pyenv-install-latest
git clone https://github.com/jawshooah/pyenv-default-packages.git $PYENV_ROOT/plugins/pyenv-default-packages
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
pyenv install-latest 3.11
pyenv global "$(pyenv install-latest --print 3.11)"
debug "Resetting path"
export PATH=$OLD_PATH
else
# Ensure we initialize pyenv so we can continue in case of reruns
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
info "Already installed PyEnv, skipping..."
fi
}
install_docker() {
info "Installing Docker"
install_homebrew
sudo apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg2 \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository -y \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt-get update
sudo apt-get install -y docker-ce
sudo curl -L "https://github.com/docker/compose/releases/download/v2.17.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo usermod -aG docker $USER
info "Installed Docker"
}
install_vscode() {
info "Installing VSCode"
sudo apt install software-properties-common apt-transport-https wget -y
wget -O- https://packages.microsoft.com/keys/microsoft.asc | sudo gpg --dearmor | sudo tee /usr/share/keyrings/vscode.gpg
echo deb [arch=amd64 signed-by=/usr/share/keyrings/vscode.gpg] https://packages.microsoft.com/repos/vscode stable main | sudo tee /etc/apt/sources.list.d/vscode.list
sudo apt update
sudo apt install code
info "Installed VSCode"
}
configure_gnome_theme(){
info "Configuring Theme"
CURRENT_PIC=$(gsettings get org.gnome.desktop.screensaver picture-uri)
if [ "$CURRENT_PIC" != "'file://$HOME/Pictures/RS_Siege1.jpg'" ]; then
wget -qO "$HOME/Pictures/RS_Siege1.jpg" https://github.com/MichielVanderlee/system_config/raw/master/assets/wallpapers/RS_Siege1.jpg
gsettings set org.gnome.desktop.interface gtk-theme "Adwaita-dark"
gsettings set org.gnome.desktop.interface icon-theme "Humanity-Dark"
gsettings set org.gnome.desktop.background picture-uri "file://$HOME/Pictures/RS_Siege1.jpg"
gsettings set org.gnome.desktop.screensaver picture-uri "file://$HOME/Pictures/RS_Siege1.jpg"
fi
# Install fonts
CURRENT_FONT=$(gsettings get org.gnome.desktop.interface monospace-font-name)
if [ "$CURRENT_FONT" != "'FiraCode Nerd Font 11'" ]; then
info "Install Fonts"
wget https://github.com/ryanoasis/nerd-fonts/releases/download/v3.0.1/FiraCode.zip
mkdir -p $HOME/.fonts/truetype/FiraCode
unzip FiraCode.zip -d $HOME/.fonts/truetype/FiraCode
sudo fc-cache -f -v
gsettings set org.gnome.desktop.interface monospace-font-name "FiraCode Nerd Font 11"
fi
# Set Terminal Theme
info "Setting Terminal Theme"
wget -qO terminal.profile https://github.com/MichielVanderlee/system_config/raw/master/terminal.profile
cat terminal.profile | dconf load /org/gnome/terminal/legacy/profiles:/:b1dcc9dd-5262-4d8d-a863-c897e6d979b9/
info "Configured Theme"
}
install() {
perform_system_update
install_packages
if [[ $INSTALL_ALL = true || $INSTALL_TMUX = true ]]; then
install_tmux
fi
if [[ $INSTALL_ALL = true || $INSTALL_TOOLS = true ]]; then
install_tools
fi
if [[ $INSTALL_ALL = true || $INSTALL_VIM = true ]]; then
install_vim
fi
if [[ $INSTALL_ALL = true || $INSTALL_ZSH = true ]]; then
install_zsh
fi
}
configure() {
if [[ $INSTALL_ALL = true || $INSTALL_TMUX = true ]]; then
configure_tmux
fi
if [[ $INSTALL_ALL = true || $INSTALL_TOOLS = true ]]; then
os_release="$(awk -F= '/^NAME/{print $2}' /etc/os-release | tr -d '"')"
if [ "$os_release" = 'Ubuntu' ]; then
configure_gnome_theme
fi
fi
if [[ $INSTALL_ALL = true || $INSTALL_VIM = true ]]; then
configure_vim
fi
if [[ $INSTALL_ALL = true || $INSTALL_ZSH = true ]]; then
configure_zsh
fi
}
show_manual_next_steps() {
info "Open a new terminal for all changes to take effect."
if [[ $INSTALL_ALL = true || $INSTALL_TMUX = true ]]; then
info " - Then open TMUX and press 'ctrl+a shift+i'. Ensure you're not nested in screen!'"
fi
if [[ $INSTALL_ALL = true || $INSTALL_VIM = true ]]; then
info " - Then open vim, and nvim and run :PlugInstall"
fi
}
main() {
# default to ALL
if [[ $INSTALL_ALL = false && $INSTALL_TMUX = false && $INSTALL_TOOLS = false && $INSTALL_VIM = false && $INSTALL_ZSH = false ]]; then
INSTALL_ALL=true
fi
if [ ! $CONFIGURE_ONLY = true ]; then
install
fi
configure
show_manual_next_steps
}
#############################################
# Parse Arguments
#############################################
while (("$#")); do
case "$1" in
# Add your arguments here
--all)
INSTALL_ALL=true
shift
;;
--tmux)
INSTALL_TMUX=true
shift
;;
--tools)
INSTALL_TOOLS=true
shift
;;
--vim)
INSTALL_VIM=true
shift
;;
--zsh)
INSTALL_ZSH=true
shift
;;
-co|--configure-only)
CONFIGURE_ONLY=true
shift
;;
-nc|--no-color)
COLOR_LOG=false
shift
;;
-h|--help)
usage
exit 0
;;
--) # end argument parsing
shift
break
;;
*)
usage
exit 1
;;
esac
done
# Execute main function
main