-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·377 lines (319 loc) · 9.93 KB
/
setup.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
#!/bin/zsh
set -e
set -o pipefail
common_software=(
git stow make cmake fzf ripgrep tmux zsh unzip
)
detect_distro() {
if [ "$CODESPACES" = "true" ]; then
echo "codespace"
elif [ -f /etc/os-release ]; then
. /etc/os-release
echo "$ID"
elif [ "$(uname)" = "Darwin" ]; then
echo "darwin"
else
echo "Unknown"
fi
}
install_common_software() {
local installer="$1"
local install_cmd="$2"
for pkg in "${common_software[@]}"; do
echo "Installing $pkg..."
$install_cmd "$pkg"
done
}
install_tmux_tpm() {
echo "Checking if TPM is already installed..."
local target_dir="$HOME/.tmux/plugins/tpm"
if [ -d "$target_dir" ]; then
echo "TPM is already installed at $target_dir."
return 0
fi
echo "Cloning TPM repository..."
if git clone https://github.com/tmux-plugins/tpm "$target_dir"; then
echo "TPM has been successfully installed at $target_dir."
else
echo "Error: Failed to clone the TPM repository."
return 1
fi
}
install_lazy_Git() {
echo "Install lazygit"
LAZYGIT_VERSION=$(curl -s "https://api.github.com/repos/jesseduffield/lazygit/releases/latest" | \grep -Po '"tag_name": *"v\K[^"]*')
curl -Lo lazygit.tar.gz "https://github.com/jesseduffield/lazygit/releases/download/v${LAZYGIT_VERSION}/lazygit_${LAZYGIT_VERSION}_Linux_x86_64.tar.gz"
tar xf lazygit.tar.gz lazygit
sudo install lazygit -D -t /usr/local/bin/
sudo rm -rf lazygit lazygit.tar.gz
}
update_and_upgrade() {
echo "Updating package list and upgrading installed packages..."
sudo apt-get update -y && sudo apt-get upgrade -y
sudo apt-get install software-properties-common -y
}
install_starship() {
if [[ $CODESPACES == "true" ]]; then
echo "In a GitHub Codespace environment, skipping Starship installation."
elif command -v starship &> /dev/null; then
echo "Starship is already installed!"
else
echo "Starship is not installed. Installing now..."
curl -sS https://starship.rs/install.sh | sh
fi
}
install_common_packages() {
for pkg in "${common_software[@]}"; do
if ! dpkg -s "$pkg" &> /dev/null; then
echo "Installing $pkg..."
sudo apt-get install -y "$pkg"
else
echo "$pkg is already installed."
fi
done
}
install_ubuntu_specific_packages() {
local ubuntu_packages=(
manpages-dev man-db manpages-posix-dev zoxide
libsecret-1-dev gnome-keyring default-jre libgbm-dev
)
for pkg in "${ubuntu_packages[@]}"; do
if ! dpkg -s "$pkg" &> /dev/null; then
echo "Installing $pkg..."
sudo apt-get install -y "$pkg"
else
echo "$pkg is already installed."
fi
done
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.10
sudo apt-get install python3.10-venv -y
}
install_nvm() {
echo "Installing NVM and Node.js..."
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
nvm install --lts
}
setup_python_environment() {
echo "Setting up Python environment..."
python3 -m venv ~/.local/state/python3
source ~/.local/state/python3/bin/activate
pip install --upgrade pip pynvim requests
}
clean_unneeded_software() {
echo "Cleaning up unneeded software..."
sudo apt autoremove
}
setup_dotfiles() {
echo "Setting up dotfiles symlinks..."
cd ~/projects/dotfiles/
if [[ $CODESPACES == "true" ]]; then
stow . -t ~ --ignore='.zshrc' --ignore='.zshenv' --ignore='.bashrc' --ignore='.gitconfig'
else
stow . --adopt -t ~
fi
}
# Install Neovim on Ubuntu/Debian
install_neovim_ubuntu() {
echo "Adding Neovim PPA and installing Neovim..."
if ! command -v nvim &> /dev/null; then
sudo add-apt-repository ppa:neovim-ppa/unstable -y
sudo apt-get update -y
sudo apt-get install neovim -y
else
echo "Neovim is already installed."
fi
}
# Arch Linux package installation function
install_packages_arch() {
echo "Updating package list and upgrading installed packages..."
yay -Syu --noconfirm
install_common_software "yay" "yay -S --noconfirm"
# Additional packages specific to Arch Linux
local arch_packages=(
man-db man-pages libsecret gnome-keyring jdk-openjdk
brave-bin acpi qmk-git obsidian deno mermaid-cli d2
plantuml imagemagick
)
for pkg in "${arch_packages[@]}"; do
if ! yay -Qi "$pkg" &> /dev/null; then
echo "Installing $pkg..."
yay -S --noconfirm "$pkg"
else
echo "$pkg is already installed."
fi
done
install_neovim_arch
}
# Install yay on Arch Linux
install_yay() {
if ! command -v yay &> /dev/null; then
echo "Installing yay AUR helper..."
sudo pacman -S --needed --noconfirm git base-devel
git clone https://aur.archlinux.org/yay.git /tmp/yay
cd /tmp/yay
makepkg -si --noconfirm
cd -
rm -rf /tmp/yay
else
echo "yay is already installed."
fi
}
# Install Neovim on Arch Linux using yay
install_neovim_arch() {
echo "Installing Neovim..."
if ! command -v nvim &> /dev/null; then
yay -S --noconfirm neovim
else
echo "Neovim is already installed."
fi
}
# Homebrew and software installation for macO
install_homebrew_mac() {
if ! command -v brew &> /dev/null; then
echo "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
brew update
brew upgrade
for software in "${common_software[@]}"; do
echo "Installing $software..."
brew install "$software"
done
# Additional software for macOS
local mac_software=(
coreutils moreutils findutils bash bash-completion2 wget
openssh screen git-lfs lua pv p7zip pigz rename ssh-copy-id
vbindiff zopfli gnu-sed rust node deno hugo lazygit bat zoxide
fish sha256sum imagemagick pkg-config pngpaste
brave-browser
)
for software in "${mac_software[@]}"; do
echo "Checking for updates for $software..."
if brew outdated | grep -q "^$software"; then
echo "Updating $software..."
brew upgrade "$software" >/dev/null 2>&1
else
echo "$software is up-to-date."
fi
done
# Cask installations for macOS
local mac_casks=(
alacritty karabiner-elements kitty@nightly
)
for cask in "${mac_casks[@]}"; do
echo "Installing $cask..."
brew install --cask "$cask"
done
brew install --cask font-fira-code-nerd-font
brew install jesseduffield/lazydocker/lazydocker
# Python environment setup
brew install pyenv
pyenv install 3.12.0
pyenv global 3.12.0
python3 -m venv ~/.local/state/python3
source ~/.local/state/python3/bin/activate
pip install --upgrade pip pynvim requests
# Enable third-party application support
sudo spctl --master-disable
curl -fsSL https://bun.sh/install | bash
}
clone_repositories() {
cd ~
if [ ! -d ~/projects ]; then
mkdir ~/projects
fi
# List of repositories to clone
REPOSITORIES=(
"[email protected]:eduuh/byte_safari.git"
"[email protected]:eduuh/keyboard.git"
"[email protected]:eduuh/homelab.git"
"[email protected]:eduuh/nvim.git"
"[email protected]:eduuh/dotfiles.git"
)
if [ "$CODESPACES" = "true" ]; then
REPOSITORIES=(
"https://github.com/eduuh/nvim.git"
"https://github.com/eduuh/dotfiles.git"
)
else
REPOSITORIES=(
"[email protected]:eduuh/byte_safari.git"
"[email protected]:eduuh/keyboard.git"
"[email protected]:eduuh/homelab.git"
"[email protected]:eduuh/nvim.git"
"[email protected]:eduuh/dotfiles.git"
)
fi
for REPO in "${REPOSITORIES[@]}"; do
REPO_NAME=$(basename "$REPO" .git)
TARGET_DIR=~/projects/"$REPO_NAME"
if [[ "$REPO_NAME" == "nvim" ]]; then
if [ ! -d "$TARGET_DIR" ]; then
echo "Cloning $REPO_NAME into $TARGET_DIR..."
git clone "$REPO" "$TARGET_DIR"
fi
echo "Creating symbolic link for $REPO_NAME at ~/.config/nvim..."
sudo ln -sf "$TARGET_DIR" ~/.config/nvim
else
if [ -d "$TARGET_DIR" ]; then
echo "Skipping $REPO_NAME: Already exists at $TARGET_DIR."
else
echo "Cloning $REPO_NAME into $TARGET_DIR..."
git clone "$REPO" "$TARGET_DIR"
fi
fi
done
install_tmux_tpm
}
install_packages_ubuntu() {
update_and_upgrade
install_starship
install_common_packages
install_ubuntu_specific_packages
if [[ $CODESPACES != "true" ]]; then
install_nvm
fi
install_neovim_ubuntu
install_lazy_Git
setup_python_environment
clean_unneeded_software
setup_dotfiles
}
main() {
local distro=$(detect_distro)
case "$distro" in
ubuntu|debian)
echo "Detected Ubuntu/Debian"
clone_repositories
install_packages_ubuntu
sudo chsh -s /bin/zsh
;;
arch)
echo "Detected Arch Linux"
install_yay
clone_repositories
install_packages_arch
;;
codespace)
echo "Detected Codespace environment"
clone_repositories
install_packages_ubuntu
;;
darwin)
echo "Detected macOS"
clone_repositories
install_homebrew_mac
;;
*)
echo "Unsupported distribution: $distro"
exit 1
;;
esac
}
main