-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
executable file
·533 lines (492 loc) · 16.1 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
#!/usr/bin/env bash
# Use this script to automate initial environment setup.
# Supports MacOS, Ubuntu flavored Linux, and WSL.
# https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
set -ueE -o pipefail
#set -euxo pipefail # uncomment for debugging
# Check if SSH key was created
function check_ssh_key() {
if [[ ! -f $HOME/.ssh/id_rsa || ! -f $HOME/.ssh/id_rsa.pub ]]; then
echo "$BASH_SOURCE: Please put your ssh keys at ~/.ssh and retry" >&2
exit 1
fi
}
# Install Corsair unofficial driver (https://github.com/ckb-next/ckb-next):
function install_corsair_drivers() {
echo "-----> Install Corsair unofficial driver"
sudo add-apt-repository -y ppa:tatokis/ckb-next
sudo apt-get update
sudo apt install -y ckb-next
}
# Install Logitech unofficial management software (https://github.com/pwr-Solaar/Solaar):
function install_logitech_software() {
echo "-----> Install Logitech unofficial management software"
sudo add-apt-repository -y ppa:solaar-unifying/stable
sudo apt-get update
sudo apt install -y solaar
}
# Install Spotify (https://www.spotify.com/us/download/linux/):
function install_spotify() {
echo "-----> Install Spotify"
curl -sS https://download.spotify.com/debian/pubkey_0D811D58.gpg | sudo apt-key add -
echo "deb http://repository.spotify.com stable non-free" | sudo tee /etc/apt/sources.list.d/spotify.list
sudo apt-get update
sudo apt install -y spotify-client
}
# Accept EULA for Microsoft fonts before installation:
function accept_ms_eula() {
echo "-----> Accept EULA for Microsoft fonts"
echo msttcorefonts msttcorefonts/accepted-mscorefonts-eula select true | \
sudo debconf-set-selections
}
# Install Debian packages:
function install_packages() {
echo "-----> Install packages with apt"
local packages=(
curl wget
git zsh gnome-terminal
vim-gtk3 nano man feh
build-essential zlib1g-dev x11-utils xz-utils
zip unzip unrar p7zip-full p7zip-rar gzip pigz bzip2
python3-pip python3-dev python3-venv
pandoc python3-docutils rst2pdf
g++ clang cmake
ruby-full hugo
xclip traceroute
silversearcher-ag ack gawk
htop tree hardinfo blueman
dos2unix jq thefuck tidy
ascii screenfetch
dconf-cli dconf-editor
tmux freerdp2-x11 dbus-x11
flashplugin-installer
ttf-mscorefonts-installer fonts-symbola
docker.io docker-compose
awscli ec2-ami-tools
fd-find bat fzf
ripgrep
gparted deluge bleachbit filezilla
remmina remmina-plugin-rdp remmina-plugin-vnc
vlc
mypaint gimp-plugin-registry
virtualbox keepassxc
)
sudo apt-get update
sudo bash -c 'DEBIAN_FRONTEND=noninteractive apt-get -o DPkg::options::=--force-confdef \
-o DPkg::options::=--force-confold upgrade -y'
sudo apt-get upgrade -y
sudo apt-get install -y "${packages[@]}" || (echo -e " Try cleaning dpkg cache:\n\
sudo dpkg -i --force-overwrite PROBLEMATIC_PACKAGE_FROM_ERROR_MESSAGE\n\
To fix broken packages run:\n\
sudo apt -f install\n\
Then, run the install.sh script again" && return 1)
sudo apt-get autoremove -y
sudo apt-get autoclean
}
# Install minimal Debian packages:
function install_minimal_packages() {
echo "-----> Install minimal packages with apt"
local packages=(
curl wget
git zsh
vim nano man feh
build-essential zlib1g-dev xz-utils
zip unzip unrar p7zip-full p7zip-rar gzip pigz bzip2
python3-pip python3-dev python3-venv
pandoc python3-docutils rst2pdf
g++ clang cmake
ruby-full hugo
xclip traceroute
silversearcher-ag ack gawk
htop tree hardinfo
dos2unix jq thefuck tidy
ascii screenfetch
dconf-cli dconf-editor
tmux xdg-utils
ttf-mscorefonts-installer fonts-symbola
docker.io docker-compose
awscli ec2-ami-tools
fd-find bat fzf
ripgrep
)
sudo apt-get update
sudo bash -c 'DEBIAN_FRONTEND=noninteractive apt-get -o DPkg::options::=--force-confdef \
-o DPkg::options::=--force-confold upgrade -y'
sudo apt-get upgrade -y
sudo apt-get install -y "${packages[@]}" || (echo -e " Try cleaning dpkg cache:\n\
sudo dpkg -i --force-overwrite PROBLEMATIC_PACKAGE_FROM_ERROR_MESSAGE\n\
To fix broken packages run:\n\
sudo apt -f install\n\
Then, run the install.sh script again" && return 1)
sudo apt-get autoremove -y
sudo apt-get autoclean
}
# Install Debian packages of WSL:
function install_packages_in_wsl() {
echo "-----> Install packages with apt in WSL"
local packages=(
curl wget
git zsh gnome-terminal
vim-gtk3 nano man feh
build-essential zlib1g-dev x11-utils xz-utils
zip unzip unrar p7zip-full p7zip-rar gzip pigz bzip2
python3-pip python3-dev python3-venv
pandoc python3-docutils rst2pdf
g++ clang cmake
ruby-full hugo
xclip traceroute
silversearcher-ag ack gawk
htop tree hardinfo
dos2unix jq thefuck tidy
ascii screenfetch
dconf-cli xdg-utils
tmux dbus-x11
awscli ec2-ami-tools
fd-find bat fzf
ripgrep
)
sudo apt-get update
sudo bash -c 'DEBIAN_FRONTEND=noninteractive apt-get -o DPkg::options::=--force-confdef \
-o DPkg::options::=--force-confold upgrade -y'
sudo apt-get upgrade -y
sudo apt-get install -y "${packages[@]}" || (echo -e " Try cleaning dpkg cache:\n\
sudo dpkg -i --force-overwrite PROBLEMATIC_PACKAGE_FROM_ERROR_MESSAGE\n\
To fix broken packages run:\n\
sudo apt -f install\n\
Then, run the install.sh script again" && return 1)
sudo apt-get autoremove -y
sudo apt-get autoclean
}
# Install MacOS packages:
function install_macos_packages() {
echo "-----> Install MacOS packages with brew"
local formulae=(
python virtualenv virtualenvwrapper poetry black bumpversion
go
liquibase
curl wget
gpg pinentry-mac
git svn zsh
nano tldr
zip unzip gzip pigz bzip2 p7zip gnu-tar gnu-sed
pandoc docutils
make cmake
swig scons icu4c krb5
ruby hugo
perl lua
xclip coreutils
ack gawk grep
htop tree
dos2unix jq thefuck tidy-html5
ascii screenfetch
tmux
awscli ec2-ami-tools Azure/kubelogin/kubelogin
fd bat fzf ripgrep
kubernetes-cli helm k3d k9s
)
local casks=(
font-sauce-code-pro-nerd-font
rar keka kekaexternalhelper
iterm2 docker
macvim textmate syntax-highlight
vlc gimp deluge
drawio
zoom
camunda-modeler
postman lens cyberduck proxyman
intellij-idea goland pycharm webstorm visual-studio-code
)
brew update
brew upgrade
brew tap homebrew/cask-fonts
brew install "${formulae[@]}" || (echo -e " Failed to install packages.\n\
Run 'brew doctor' to check brew status.\n\
Try to install failed packages manually.\n\
Then, run the install.sh script again" && return 1)
brew install --cask "${casks[@]}" || (echo -e " Failed to install casks.\n\
Run 'brew doctor' to check brew status.\n\
Try to install failed packages manually.\n\
Then, run the install.sh script again" && return 1)
brew tap homebrew/cask-fonts && brew install --cask font-sauce-code-pro-nerd-font
brew cleanup
}
# Remove unused packages:
function remove_packages() {
local packages_to_remove=(
blueberry rhythmbox transmission-gtk transmission-common
)
for pkg in "${packages_to_remove[@]}"; do
$(dpkg --status $pkg &> /dev/null) || continue
sudo apt-get remove -y $pkg
done
sudo apt-get autoremove -y
sudo apt-get autoclean
}
# Install custom applets and extensions:
function install_applets_and_extensions() {
echo "-----> Install custom applets and extensions"
local applets=(
multicore-sys-monitor@ccadeptic23 qredshift@quintao SpicesUpdate@claudiux weather@mockturtl
)
local extensions=(
transparent-panels@germanfr
)
# applets - download, extract and delete zip:
pushd ${HOME}/.local/share/cinnamon/applets
for i in "${applets[@]}"
do
[ ! -d "$i" ] && wget "https://cinnamon-spices.linuxmint.com/files/applets/$i.zip" && \
unzip -q "$i.zip" && rm -f "$i.zip" || true
done
popd
# extensions - download, extract and delete zip:
pushd ${HOME}/.local/share/cinnamon/extensions
for i in "${extensions[@]}"
do
[ ! -d "$i" ] && wget "https://cinnamon-spices.linuxmint.com/files/extensions/$i.zip" && \
unzip -q "$i.zip" && rm -f "$i.zip" || true
done
popd
}
# Load dconf configuration files:
function load_dconf_files() {
echo "-----> Load dconf configuration files"
# load gnome-terminal profile:
dconf load /org/gnome/terminal/legacy/profiles:/ < \
$HOME/.dotfiles/dconf-files/gnome-terminal-profiles.dconf
# load cinnamon configuration (key-bindings, panels, enabled applets, terminal launcher
# configuration):
dconf load /org/cinnamon/ < $HOME/.dotfiles/dconf-files/cinnamon.dconf
}
# Edit desktop shortcuts to start GNOME terminal and VIM maximized:
function edit_gnome_terminal_shortcuts() {
echo "-----> Edit gnome-terminal shortcuts"
mkdir -p $HOME/.local/share/applications
# Edit system menu shortcut:
cp /usr/share/applications/org.gnome.Terminal.desktop \
$HOME/.local/share/applications/org.gnome.Terminal.desktop
sed -i 's/Exec=gnome-terminal/Exec=gnome-terminal --window --maximize/g' \
$HOME/.local/share/applications/org.gnome.Terminal.desktop
# Edit VIM shortcut:
cp /usr/share/applications/vim.desktop $HOME/.local/share/applications/
perl -i -0777 -pe "s/Exec=vim %F\nTerminal=true/Exec=gnome-terminal --window --maximize -e \
'vim %F'\nTerminal=false/g" $HOME/.local/share/applications/vim.desktop
}
# Install SDKMAN and Java JDK and build tools (must be run from zsh):
function install_java() {
echo "-----> Install SDKMAN and Java JDK and build tools"
zsh $HOME/.dotfiles/sdkman.sh
sudo ln -s $HOME/.sdkman/candidates/java/current/bin/* /usr/bin/ 2>/dev/null || true
}
# Install go:
function install_go() {
local version=1.21.5
! command -v go &>/dev/null || [[ "$(go version)" != *"$version"* ]] || return 0
echo "-----> Install Golang $version"
dwfile="go${version}.linux-amd64.tar.gz"
curl -O "https://storage.googleapis.com/golang/${dwfile}"
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf $dwfile
rm $dwfile
}
# Copy custom fonts:
function copy_custom_fonts() {
echo "-----> Copy custom fonts"
# Get shell font
mkdir -p $HOME/.local/share/fonts
curl -fLo "$HOME/.local/share/fonts/Sauce Code Pro Nerd Font Complete.ttf" \
https://github.com/ryanoasis/nerd-fonts/blob/master/patched-fonts/SourceCodePro/Regular/complete\
/Sauce%20Code%20Pro%20Nerd%20Font%20Complete.ttf?raw=true
yes | cp -fa $HOME/.dotfiles/.local/share/fonts/. $HOME/.local/share/fonts && echo "Done"
sudo fc-cache -f -v
}
# Beautify ZSH:
function beautify_shell() {
echo "-----> Beautify shell"
# Install oh-my-zsh
[ ! -d "$HOME/.oh-my-zsh" ] && \
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" \
"" --unattended || true
# Install Zsh syntax highlighting
rm -rf $HOME/.oh-my-zsh/plugins/zsh-syntax-highlighting 2>/dev/null || true
git clone --depth=1 https://github.com/zsh-users/zsh-syntax-highlighting.git \
$HOME/.oh-my-zsh/plugins/zsh-syntax-highlighting
# Install powerlevel10k theme
[ ! -d "$HOME/.oh-my-zsh/themes/powerlevel10k" ] && git clone --depth=1 \
https://github.com/romkatv/powerlevel10k.git $HOME/.oh-my-zsh/themes/powerlevel10k || true
}
# Set ZSH as default shell:
function change_shell() {
echo "-----> Change shell to zsh"
chsh -s $(which zsh) || echo "Failed changing shell" && return
}
# Link $HOME dotfiles to .dotfiles folder:
function create_links() {
echo "-----> Create symlinks"
declare -A src2dest
src2dest[".bashrc"]="$HOME/.bashrc"
src2dest[".zshrc"]="$HOME/.zshrc"
src2dest[".p10k.zsh"]="$HOME/.p10k.zsh"
src2dest[".gitconfig"]="$HOME/.gitconfig"
src2dest[".tmux.conf"]="$HOME/.tmux.conf"
src2dest[".vimrc"]="$HOME/.vimrc"
backup_dir=$HOME/.dotfiles_backup
rm -rf $backup_dir
mkdir -p $backup_dir
for key in "${!src2dest[@]}"; do
[ -L "${src2dest[$key]}" ] && rm "${src2dest[$key]}"
if [ -f "${src2dest[$key]}" ] || [ -d "${src2dest[$key]}" ]; then
echo "Backing up original file: ${src2dest[$key]}"
temp_dir=$(dirname ${src2dest[$key]})
mkdir -p "$backup_dir/$temp_dir"
mv -f "${src2dest[$key]}" "$backup_dir/$temp_dir"
fi
ln -s "$HOME/.dotfiles/$key" "${src2dest[$key]}" || echo "Can not create symlink. File still exists at \
${src2dest[$key]}"
done
rmdir $backup_dir || echo "Old dotfiles where backed up to $backup_dir"
}
# Install nvm and then npm and yarn:
function install_nvm_npm_yarn() {
local node_version=18
! command -v node &>/dev/null || [[ "$(node -v)" != *"$node_version"* ]] || return 0
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.nvm/nvm.sh
nvm install ${node_version}
nvm alias default
nvm use default
npm install --global yarn
}
# Create vim undo directory for temporary vim files:
function create_vim_undo_dir() {
echo "-----> Create vim undo directory"
mkdir -p "$HOME/.vim/undodir"
}
# Run vim :PlugInstall to install vim plugins:
function install_vim_plugins() {
echo "-----> Install vim plugins"
vim +PlugInstall +qall!
}
# Install tmux plugin manager and plugins on initial setup:
function install_tmux_plugins() {
if [[ -v TMUX && "$TMUX" != "" ]]; then
return 0;
fi
echo "-----> Install tmux plugin manager"
TMUX_DIR=${HOME}/.tmux
rm -rf "${TMUX_DIR}/plugins/tpm" 2>/dev/null || true
git clone --depth=1 https://github.com/tmux-plugins/tpm ${TMUX_DIR}/plugins/tpm && \
bash ${TMUX_DIR}/plugins/tpm/bin/install_plugins
}
# Manually install ripgrep until https://bugs.launchpad.net/ubuntu/+source/rust-bat/+bug/1868517 is solved
function install_ripgrep() {
apt-get download ripgrep
sudo dpkg --force-overwrite -i ripgrep*.deb
rm -f ripgrep*
}
# Force generate en_GB and en_US locales
function generate_locale() {
sudo locale-gen en_GB.UTF-8 en_US.UTF-8
}
# Run script:
if [[ "$(id -u)" == 0 ]]; then
echo "$BASH_SOURCE: Please run as non-root" >&2
exit 1
fi
if [ ! -d $HOME ]; then
echo "Home directory doesn't exist or \$HOME variable not set"
exit 1
fi
umask g-w,o-w
if [[ "$(uname -s)" == *[Dd]arwin* ]] 2>/dev/null; then # Check if Darwin (MacOS)
echo "MacOS detected"
check_ssh_key
install_macos_packages
install_java
beautify_shell
create_links
install_nvm_npm_yarn
create_vim_undo_dir
install_vim_plugins
install_tmux_plugins
elif [[ "$(uname -s)" == *[Ll]inux* ]] 2>/dev/null; then # Check if Linux
echo "Linux detected"
# Selection menu:
COLUMNS=1
echo "Options:"
PS3="Please select a number and press Enter: "
options=(
"Full installation, visual aspects like applets and themes, i/o drivers, cinnamon configuration"
"Minimal installation, suitable for virtual machines"
"Exit")
select opt in "${options[@]}"
do
case $opt in
"Full installation, visual aspects like applets and themes, i/o drivers, cinnamon configuration")
echo "Full installation"
check_ssh_key
install_corsair_drivers
install_logitech_software
install_spotify
accept_ms_eula
install_packages
remove_packages
install_applets_and_extensions
load_dconf_files
edit_gnome_terminal_shortcuts
install_java
install_go
copy_custom_fonts
beautify_shell
change_shell
create_links
install_nvm_npm_yarn
create_vim_undo_dir
install_vim_plugins
install_tmux_plugins
install_ripgrep
break
;;
"Minimal installation, suitable for virtual machines")
echo "Minimal installation"
accept_ms_eula
install_minimal_packages
remove_packages
install_java
install_go
copy_custom_fonts
beautify_shell
change_shell
create_links
install_nvm_npm_yarn
create_vim_undo_dir
install_vim_plugins
install_tmux_plugins
install_ripgrep
generate_locale
break
;;
"Exit")
exit 0
;;
*) echo "Invalid option $REPLY";;
esac
done
else # Assume WSL
echo "WSL detected"
install_packages_in_wsl
remove_packages
install_java
install_go
copy_custom_fonts
beautify_shell
change_shell
create_links
install_nvm_npm_yarn
create_vim_undo_dir
install_vim_plugins
install_tmux_plugins
install_ripgrep
fi
echo "Success"
echo "Please reboot to apply all changes"