-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstall.sh
430 lines (357 loc) · 12 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
#!/bin/zsh
#
# This script should be run via curl:
# zsh -c "$(curl -fsSL https://raw.githubusercontent.com/LucaAngioloni/.dotfiles/main/install.sh)"
# or via wget:
# zsh -c "$(wget -qO- https://raw.githubusercontent.com/LucaAngioloni/.dotfiles/main/install.sh)"
# or via fetch:
# zsh -c "$(fetch -o - https://raw.githubusercontent.com/LucaAngioloni/.dotfiles/main/install.sh)"
#
# As an alternative, you can first download the install script and run it afterwards:
# wget https://raw.githubusercontent.com/LucaAngioloni/.dotfiles/main/install.sh
# zsh install.sh
set -e
# Make sure important variables exist if not already defined
#
# $USER is defined by login(1) which is not always executed (e.g. containers)
# POSIX: https://pubs.opengroup.org/onlinepubs/009695299/utilities/id.html
USER=${USER:-$(id -u -n)}
# $HOME is defined at the time of login, but it could be unset. If it is unset,
# a tilde by itself (~) will not be expanded to the current user's home directory.
# POSIX: https://pubs.opengroup.org/onlinepubs/009696899/basedefs/xbd_chap08.html#tag_08_03
HOME="${HOME:-$(getent passwd $USER 2>/dev/null | cut -d: -f6)}"
# macOS does not have getent, but this works even if $HOME is unset
HOME="${HOME:-$(eval echo ~$USER)}"
PLATFORM='none'
case "$(uname -s)" in
Darwin)
PLATFORM='mac'
;;
Linux)
PLATFORM='linux'
;;
*)
PLATFORM='other'
;;
esac
if [ "$PLATFORM" = 'other' ]; then
echo "Cannot install on this platform!"
exit 1
fi
ARCHITECTURE=$(uname -m)
command_exists() {
command -v "$@" >/dev/null 2>&1
}
user_can_sudo() {
# Check if sudo is installed
command_exists sudo || return 1
# The following command has 3 parts:
#
# 1. Run `sudo` with `-v`. Does the following:
# • with privilege: asks for a password immediately.
# • without privilege: exits with error code 1 and prints the message:
# Sorry, user <username> may not run sudo on <hostname>
#
# 2. Pass `-n` to `sudo` to tell it to not ask for a password. If the
# password is not required, the command will finish with exit code 0.
# If one is required, sudo will exit with error code 1 and print the
# message:
# sudo: a password is required
#
# 3. Check for the words "may not run sudo" in the output to really tell
# whether the user has privileges or not. For that we have to make sure
# to run `sudo` in the default locale (with `LANG=`) so that the message
# stays consistent regardless of the user's locale.
#
! LANG= sudo -n -v 2>&1 | grep -q "may not run sudo"
}
user_can_sudo || {
echo "You don't have sudo privileges. Please run this script as root."
exit 2
}
# Load colors
autoload colors; colors
# Adding paths to PATH before installing tools so that I can use them right away
export PATH
export PATH=~/.bin:$PATH
export PATH=~/.local/bin:$PATH
if [ "$PLATFORM" = 'mac' ]; then
if [ "$ARCHITECTURE" = 'arm64' ]; then
export PATH="/opt/homebrew/bin:$PATH"
export PATH="/opt/homebrew/sbin:$PATH"
#Ruby
export PATH="/opt/homebrew/opt/ruby/bin:$PATH"
else
export PATH="/usr/local/bin:$PATH"
export PATH="/usr/local/sbin:$PATH"
#Ruby
export PATH="/usr/local/opt/ruby/bin:$PATH"
fi
export PATH=$HOME/bin:$PATH
elif [ "$PLATFORM" = 'linux' ]; then
export PATH=~/.gem/bin:$PATH # Ruby gems if installed with snap
fi
# Installing basic tools
if [ "$PLATFORM" = 'mac' ]; then
if ! command_exists brew; then
echo $fg[green]"Installing Homebrew..."$reset_color
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo ""
fi
echo $fg[green]"Updating Homebrew Formulae..."$reset_color
brew update
echo ""
# Install with brew even though it's already installed by default on macOS. Brew's version is faster.
echo $fg[green]"Installing git..."$reset_color
brew install git
echo ""
# On mac we need to add a non standard shell to the /etc/shells file
# so that when oh-my-zsh tryies to change the shell it doesn't fail
# in case you have zsh installed through brew
echo $fg[green]"Adding zsh to standard shells..."$reset_color
echo /usr/local/bin/zsh | sudo tee -a /etc/shells
echo ""
elif [ "$PLATFORM" = 'linux' ]; then
echo $fg[green]"Updating Aptic Packages..."$reset_color
sudo apt-get update -y
if ! command_exists git; then
echo $fg[green]"Installing git..."$reset_color
sudo apt-get install git -y
echo ""
fi
fi
if [ ! -d "~/.oh-my-zsh" ]; then
# Install Oh My Zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
echo ""
fi
# Change the default shell to zsh
echo $fg[green]"Changing the default shell to zsh..."$reset_color
chsh -s $(which zsh)
echo ""
# source ~/.zshrc
export ZSH_CUSTOM=~/.oh-my-zsh/custom
if [ ! -d "$ZSH_CUSTOM/themes/powerlevel10k" ]; then
echo $fg[green]"Installing Powerlevel10k..."$reset_color
git clone https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10k
echo ""
fi
if [ ! -d "$ZSH_CUSTOM/plugins/zsh-completions" ]; then
echo $fg[green]"Installing zsh-completions..."$reset_color
git clone https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:=~/.oh-my-zsh/custom}/plugins/zsh-completions
echo ""
fi
if [ ! -d "$ZSH_CUSTOM/plugins/zsh-autosuggestions" ]; then
echo $fg[green]"Installing zsh-autosuggestions..."$reset_color
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
echo ""
fi
if [ ! -d "$ZSH_CUSTOM/plugins/fast-syntax-highlighting" ]; then
echo $fg[green]"Installing fast-syntax-highlighting..."$reset_color
git clone https://github.com/zdharma-continuum/fast-syntax-highlighting.git \
${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/fast-syntax-highlighting
echo ""
fi
if [ "$PLATFORM" = 'mac' ]; then
# Starship install
# echo $fg[green]"Installing Starship..."$reset_color
# brew install starship
# echo ""
# Install thefuck
echo $fg[green]"Installing thefuck..."$reset_color
brew install thefuck
echo ""
# Install fd
echo $fg[green]"Installing fd..."$reset_color
brew install fd
echo ""
# Install tree
echo $fg[green]"Installing tree..."$reset_color
brew install tree
echo ""
# Install bat
echo $fg[green]"Installing bat..."$reset_color
brew install bat
echo ""
# Install fzf
echo $fg[green]"Installing fzf..."$reset_color
brew install fzf
# To install useful key bindings and fuzzy completion (run once):
$(brew --prefix)/opt/fzf/install
echo ""
# Install direnv
echo $fg[green]"Installing direnv..."$reset_color
brew install direnv
echo ""
# Install catimg
echo $fg[green]"Installing catimg..."$reset_color
brew install catimg
echo ""
# Install stow
echo $fg[green]"Installing stow..."$reset_color
brew install stow
echo ""
# Install tmux
echo $fg[green]"Installing tmux..."$reset_color
brew install tmux
echo ""
# Install ruby
echo $fg[green]"Installing ruby..."$reset_color
brew install ruby
echo ""
# Install colorls
echo $fg[green]"Installing colorls..."$reset_color
gem install colorls
echo ""
# Install ripgrep
echo $fg[green]"Installing ripgrep..."$reset_color
brew install ripgrep
echo ""
# Install neovim
echo $fg[green]"Installing neovim..."$reset_color
brew install neovim
echo ""
# Install duf
echo $fg[green]"Installing duf..."$reset_color
brew install duf
echo ""
# # Install lsd
# echo $fg[green]"Installing lsd..."$reset_color
# brew install lsd
# echo ""
# Install jq
echo $fg[green]"Installing jq..."$reset_color
brew install jq
echo ""
# Install yazi
echo $fg[green]"Installing yazi..."$reset_color
brew install yazi ffmpegthumbnailer unar poppler font-symbols-only-nerd-font
echo ""
fi
if [ "$PLATFORM" = 'linux' ]; then
mkdir -p ~/.local/bin # For fd and bat
# Starship install
# echo $fg[green]"Installing Starship..."$reset_color
# curl -sS https://starship.rs/install.sh | sh
# echo ""
# Install build-essential
echo $fg[green]"Installing build-essential..."$reset_color
sudo apt-get install build-essential -y
echo ""
# # Install thefuck
# if ! command_exists pip3; then
# echo $fg[green]"Installing pip3..."$reset_color
# sudo apt-get install python3-dev python3-pip python3-setuptools -y
# echo ""
# fi
# echo $fg[green]"Installing thefuck..."$reset_color
# pip3 install thefuck --user --upgrade --break-system-packages
# echo ""
echo $fg[green]"Installing thefuck..."$reset_color
sudo snap install --beta thefuck --classic
echo ""
# Install fd
echo $fg[green]"Installing fd..."$reset_color
sudo apt-get install fd-find -y
ln -s $(which fdfind) ~/.local/bin/fd || true
echo ""
# Install tree
echo $fg[green]"Installing tree..."$reset_color
sudo apt-get install tree -y
echo ""
# Install bat
echo $fg[green]"Installing bat..."$reset_color
sudo apt-get install bat -y
ln -s /usr/bin/batcat ~/.local/bin/bat || true
echo ""
# Install fzf
echo $fg[green]"Installing fzf..."$reset_color
sudo apt-get install fzf -y
cat << EOF > ~/.fzf.zsh
# Auto-completion
# ---------------
source /usr/share/doc/fzf/examples/completion.zsh
# Key bindings
# ------------
source /usr/share/doc/fzf/examples/key-bindings.zsh
EOF
echo ""
# Install direnv
echo $fg[green]"Installing direnv..."$reset_color
sudo apt-get install direnv -y
echo ""
# Install catimg
echo $fg[green]"Installing catimg..."$reset_color
sudo apt-get install catimg -y
echo ""
# Install stow
echo $fg[green]"Installing stow..."$reset_color
sudo apt-get install stow -y
echo ""
# Install tmux
echo $fg[green]"Installing tmux..."$reset_color
sudo apt-get install tmux -y
echo ""
# Install ruby
echo $fg[green]"Installing ruby..."$reset_color
# Install with snap
# sudo snap install ruby --classic
sudo apt-get install ruby-full -y
echo ""
# Install colorls
echo $fg[green]"Installing colorls..."$reset_color
sudo gem install colorls
echo ""
# Install ripgrep
echo $fg[green]"Installing ripgrep..."$reset_color
sudo apt-get install ripgrep -y
echo ""
# Install neovim
echo $fg[green]"Installing neovim..."$reset_color
sudo snap install nvim --classic # Install with snap because apt-get is outdated
echo ""
# Install duf
echo $fg[green]"Installing duf..."$reset_color
sudo apt-get install duf -y
echo ""
# # Install lsd
# echo $fg[green]"Installing lsd..."$reset_color
# sudo apt-get install lsd -y
# echo ""
# Install jq
echo $fg[green]"Installing jq..."$reset_color
sudo apt-get install jq -y
echo ""
# Still not easy to make an installation script for yazi that works on any linux distro (debian)
# # Install yazi
# echo $fg[green]"Installing yazi..."$reset_color
# sudo apt-get install ffmpegthumbnailer unar poppler-utils -y
# sudo apt-get install yazi -y
# echo ""
fi
# if [ ! -d "$HOME/.config/nvim" ]; then
# echo $fg[green]"Installing nvchad..."$reset_color
# git clone https://github.com/NvChad/NvChad ~/.config/nvim --depth 1
# echo ""
# fi
echo $fg[green]"Installing .dotfiles..."$reset_color
git clone https://github.com/LucaAngioloni/.dotfiles.git ~/.dotfiles
if [ -f ~/.zshrc ]; then
mv ~/.zshrc ~/.zshrc.bak
fi
if [ -f ~/.zshenv ]; then
mv ~/.zshenv ~/.zshenv.bak
fi
if [ -f ~/.zprofile ]; then
mv ~/.zprofile ~/.zprofile.bak
fi
if [ -f ~/.bashrc ]; then
mv ~/.bashrc ~/.bashrc.bak
fi
# TODO: do the same thing for every file in the .dotfiles folder that we want to backup before stowing
cd ~/.dotfiles
stow --adopt */ # Stow all the folders in the .dotfiles folder
git restore .
echo ""
cd
exec zsh -l