-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_environment.sh
More file actions
executable file
·399 lines (360 loc) · 11.8 KB
/
setup_environment.sh
File metadata and controls
executable file
·399 lines (360 loc) · 11.8 KB
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
#!/bin/bash
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
print_status() { echo -e "${BLUE}[*]${NC} $1"; }
print_success() { echo -e "${GREEN}[✓]${NC} $1"; }
print_warning() { echo -e "${YELLOW}[!]${NC} $1"; }
print_error() { echo -e "${RED}[✗]${NC} $1"; }
prompt_yes_no() {
local prompt="$1"
local default="${2:-y}"
local response
if [[ "$default" == "y" ]]; then
read -rp "$prompt [Y/n]: " response
response=${response:-y}
else
read -rp "$prompt [y/N]: " response
response=${response:-n}
fi
[[ "$response" =~ ^[Yy]$ ]]
}
DOTFILES_DIR="$HOME/dotfiles"
PACMAN_PACKAGES=(
base-devel git curl wget stow
i3-wm polybar rofi picom dunst feh flameshot
xorg-server xorg-xinit xorg-xrandr xorg-xsetroot xorg-xinput
xss-lock i3lock dex
pipewire pipewire-pulse wireplumber
blueman bluez bluez-utils
brightnessctl playerctl
networkmanager network-manager-applet
ghostty zsh tmux
bat lsd fd ripgrep fzf lazygit neofetch htop btop tree
yazi zoxide eza chafa scrot xclip xsel unzip zip
go python python-pip cmake ninja clang gcc make
docker docker-compose
jdk17-openjdk jdk21-openjdk
ttf-jetbrains-mono-nerd ttf-meslo-nerd noto-fonts noto-fonts-emoji
)
AUR_PACKAGES=(
lazydocker
spring-boot-cli
google-chrome
)
STOW_DIRS=(
dunst
ghostty
i3
ideavimrc
nvim
opencode
picom
polybar
rofi
tmux
tmuxifer
xresources
zshrc
)
command_exists() {
command -v "$1" &>/dev/null
}
install_yay() {
if command_exists yay; then
print_success "yay already installed"
return
fi
print_status "Installing yay..."
sudo pacman -S --needed --noconfirm git base-devel
local temp_dir=$(mktemp -d)
git clone https://aur.archlinux.org/yay.git "$temp_dir/yay"
cd "$temp_dir/yay"
makepkg -si --noconfirm
cd -
rm -rf "$temp_dir"
print_success "yay installed"
}
install_pacman_packages() {
print_status "Installing pacman packages..."
local to_install=()
for pkg in "${PACMAN_PACKAGES[@]}"; do
if ! pacman -Qi "$pkg" &>/dev/null; then
to_install+=("$pkg")
fi
done
if [[ ${#to_install[@]} -gt 0 ]]; then
sudo pacman -S --needed --noconfirm "${to_install[@]}"
print_success "Pacman packages installed"
else
print_success "All pacman packages already installed"
fi
}
install_aur_packages() {
print_status "Installing AUR packages..."
local to_install=()
for pkg in "${AUR_PACKAGES[@]}"; do
if ! yay -Qi "$pkg" &>/dev/null; then
to_install+=("$pkg")
fi
done
if [[ ${#to_install[@]} -gt 0 ]]; then
yay -S --needed --noconfirm "${to_install[@]}"
print_success "AUR packages installed"
else
print_success "All AUR packages already installed"
fi
}
build_neovim() {
if command_exists nvim; then
local current_version=$(nvim --version | head -1 | grep -oP 'v\K[0-9]+\.[0-9]+')
print_warning "Neovim $current_version already installed"
if ! prompt_yes_no "Build latest from source anyway?" "n"; then
return
fi
fi
print_status "Building Neovim from source..."
sudo pacman -S --needed --noconfirm cmake unzip ninja curl gettext
local temp_dir=$(mktemp -d)
git clone https://github.com/neovim/neovim.git "$temp_dir/neovim"
cd "$temp_dir/neovim"
git checkout stable
make CMAKE_BUILD_TYPE=Release
sudo make install
cd -
rm -rf "$temp_dir"
print_success "Neovim built and installed"
}
install_oh_my_zsh() {
if [[ -d "$HOME/.oh-my-zsh" ]]; then
print_success "oh-my-zsh already installed"
return
fi
print_status "Installing oh-my-zsh..."
RUNZSH=no KEEP_ZSHRC=yes sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
print_success "oh-my-zsh installed"
}
install_zsh_plugins() {
local zsh_custom="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}"
if [[ ! -d "$zsh_custom/plugins/zsh-autosuggestions" ]]; then
print_status "Installing zsh-autosuggestions..."
git clone https://github.com/zsh-users/zsh-autosuggestions "$zsh_custom/plugins/zsh-autosuggestions"
else
print_success "zsh-autosuggestions already installed"
fi
if [[ ! -d "$zsh_custom/plugins/fast-syntax-highlighting" ]]; then
print_status "Installing fast-syntax-highlighting..."
git clone https://github.com/zdharma-continuum/fast-syntax-highlighting "$zsh_custom/plugins/fast-syntax-highlighting"
else
print_success "fast-syntax-highlighting already installed"
fi
}
install_tpm() {
if [[ -d "$HOME/.tmux/plugins/tpm" ]]; then
print_success "TPM already installed"
return
fi
print_status "Installing TPM..."
git clone https://github.com/tmux-plugins/tpm "$HOME/.tmux/plugins/tpm"
print_success "TPM installed"
}
install_tmuxifier() {
if [[ -d "$HOME/.tmuxifier" ]]; then
print_success "tmuxifier already installed"
return
fi
print_status "Installing tmuxifier..."
git clone https://github.com/jimeh/tmuxifier.git "$HOME/.tmuxifier"
print_success "tmuxifier installed"
}
install_nvm() {
if [[ -d "$HOME/.nvm" ]]; then
print_success "NVM already installed"
else
print_status "Installing NVM..."
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
print_success "NVM installed"
fi
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
if ! command_exists node; then
print_status "Installing Node.js LTS..."
nvm install --lts
nvm use --lts
print_success "Node.js LTS installed"
fi
}
install_bun() {
if command_exists bun; then
print_success "Bun already installed"
return
fi
print_status "Installing Bun..."
curl -fsSL https://bun.sh/install | bash
print_success "Bun installed"
}
install_deno() {
if command_exists deno || [[ -f "$HOME/.deno/bin/deno" ]]; then
print_success "Deno already installed"
return
fi
print_status "Installing Deno..."
curl -fsSL https://deno.land/install.sh | sh
print_success "Deno installed"
}
install_pnpm() {
if command_exists pnpm; then
print_success "pnpm already installed"
return
fi
print_status "Installing pnpm..."
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
npm install -g pnpm
print_success "pnpm installed"
}
install_flutter() {
local flutter_dir="$HOME/flutter"
if [[ -d "$flutter_dir" ]]; then
print_success "Flutter already installed at $flutter_dir"
else
print_status "Installing Flutter..."
git clone https://github.com/flutter/flutter.git -b stable "$flutter_dir"
print_success "Flutter installed"
fi
export PATH="$flutter_dir/bin:$PATH"
}
setup_android_sdk() {
local android_home="$HOME/Android/Sdk"
local cmdline_tools="$android_home/cmdline-tools/latest"
if [[ -d "$cmdline_tools" ]]; then
print_success "Android SDK already set up"
else
print_status "Setting up Android SDK..."
mkdir -p "$android_home"
local temp_dir=$(mktemp -d)
local cmdline_zip="$temp_dir/commandlinetools.zip"
curl -o "$cmdline_zip" https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip
unzip -q "$cmdline_zip" -d "$temp_dir"
mkdir -p "$cmdline_tools"
mv "$temp_dir/cmdline-tools/"* "$cmdline_tools/"
rm -rf "$temp_dir"
print_success "Android command-line tools installed"
fi
export ANDROID_HOME="$android_home"
export PATH="$cmdline_tools/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/emulator:$PATH"
print_status "Installing Android SDK components..."
yes | sdkmanager --licenses 2>/dev/null || true
sdkmanager "platform-tools" "platforms;android-34" "build-tools;34.0.0" "emulator" 2>/dev/null || true
print_success "Android SDK setup complete"
}
install_opencode() {
if command_exists opencode || [[ -f "$HOME/.opencode/bin/opencode" ]]; then
print_success "OpenCode already installed"
return
fi
print_status "Installing OpenCode..."
curl -fsSL https://opencode.ai/install | bash
print_success "OpenCode installed"
}
configure_java() {
print_status "Configuring Java..."
if command_exists archlinux-java; then
sudo archlinux-java set java-21-openjdk
print_success "Java 21 set as default"
fi
}
stow_dotfiles() {
print_status "Stowing dotfiles..."
cd "$DOTFILES_DIR"
for dir in "${STOW_DIRS[@]}"; do
if [[ -d "$dir" ]]; then
stow -v --restow "$dir" 2>/dev/null || stow -v "$dir"
fi
done
cd -
print_success "Dotfiles stowed"
}
enable_services() {
print_status "Enabling services..."
sudo systemctl enable --now docker.service 2>/dev/null || true
sudo systemctl enable --now bluetooth.service 2>/dev/null || true
sudo systemctl enable --now NetworkManager.service 2>/dev/null || true
print_success "Services enabled"
}
add_user_to_groups() {
print_status "Adding user to groups..."
sudo usermod -aG docker "$USER" 2>/dev/null || true
sudo usermod -aG video "$USER" 2>/dev/null || true
sudo usermod -aG input "$USER" 2>/dev/null || true
print_success "User added to groups"
}
change_shell() {
if [[ "$SHELL" != *"zsh"* ]]; then
print_status "Changing default shell to zsh..."
chsh -s "$(which zsh)"
print_success "Shell changed to zsh"
else
print_success "Already using zsh"
fi
}
print_post_install() {
echo ""
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN} Installation Complete!${NC}"
echo -e "${GREEN}========================================${NC}"
echo ""
echo -e "${YELLOW}Post-installation steps:${NC}"
echo "1. Log out and log back in for group changes"
echo "2. Start tmux and press: prefix + I (to install plugins)"
echo "3. Open nvim and let Mason install LSP servers"
echo "4. Run 'flutter doctor' to verify Flutter setup"
echo ""
echo -e "${YELLOW}Your keybindings:${NC}"
echo " Alt + Return : Open Ghostty terminal"
echo " Alt + d/Space : Open Rofi launcher"
echo " Alt + h/j/k/l : Navigate windows (vim-style)"
echo " Ctrl + Space : Tmux prefix"
echo ""
}
main() {
echo -e "${BLUE}"
echo "╔═══════════════════════════════════════════════════════════╗"
echo "║ Arch Linux Dotfiles Setup ║"
echo "║ Rose Pine Theme | i3 + Neovim + Tmux ║"
echo "╚═══════════════════════════════════════════════════════════╝"
echo -e "${NC}"
if [[ ! -d "$DOTFILES_DIR" ]]; then
print_error "Dotfiles directory not found at $DOTFILES_DIR"
exit 1
fi
install_yay
install_pacman_packages
install_aur_packages
if prompt_yes_no "Build Neovim from source (latest stable)?" "y"; then
build_neovim
fi
install_oh_my_zsh
install_zsh_plugins
install_tpm
install_tmuxifier
install_nvm
install_bun
install_deno
install_pnpm
if prompt_yes_no "Install Flutter and Android SDK?" "y"; then
install_flutter
setup_android_sdk
fi
install_opencode
configure_java
stow_dotfiles
enable_services
add_user_to_groups
change_shell
print_post_install
}
main "$@"