-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmarzeq-dotfiles
More file actions
executable file
·386 lines (336 loc) · 9.61 KB
/
Copy pathmarzeq-dotfiles
File metadata and controls
executable file
·386 lines (336 loc) · 9.61 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
#!/usr/bin/env bash
set -e
RED_BOLD="\033[1;31m"
BLUE="\033[0;34m"
GREEN_BOLD="\033[1;32m"
RESET="\033[0m"
error() { echo -e "${RED_BOLD}$1${RESET}" >&2; exit 1; }
info() { echo -e "${BLUE}$1${RESET}"; }
if [[ $EUID -eq 0 ]]; then
error "Don't run this script as root."
fi
STATE_DIR="$HOME/.local/share/marzeq"
INSTALLED_FILE="$STATE_DIR/installed_components"
DRY_RUN=false
SKIP_PACKAGES=false
REPO_PATH="$HOME/.local/share/marzeq/dotfiles"
if [[ ! -d "$REPO_PATH/.git" ]]; then
error "Dotfiles repository not found at: $REPO_PATH (run install.sh to bootstrap)."
fi
run_or_echo() {
echo -e "${GREEN_BOLD}> $*${RESET}"
if ! $DRY_RUN; then
"$@"
fi
}
mkdir -p "$STATE_DIR"
SHELLS_DEPS=("stow" "zsh" "bash" "git")
NEOVIM_DEPS=("stow" "neovim" "fzf" "ripgrep" "curl" "tree-sitter-cli" "nodejs")
TERMINAL_DEPS=("stow" "ghostty")
DESKTOP_DEPS=(
"stow" "hyprland"
"swaync"
".AUR:python-ignis"
"python-pillow" "python-numpy" "python-rapidfuzz"
"gnome-bluetooth-3.0" "dart-sass" "brightnessctl" "playerctl"
"python-pam" "python-aiohttp" "python-scikit-learn" "python-narwhals"
"power-profiles-daemon" "bc" "cantarell-fonts"
"gdm"
"xdg-desktop-portal-hyprland" "xdg-desktop-portal-gtk" "polkit-gnome"
"qt5-wayland" "qt6-wayland"
"pipewire" "pipewire-pulse" "pipewire-alsa"
"gst-plugin-pipewire" "alsa-utils"
"swww" "hyprpicker" "hypridle" "hyprlock"
"hyprshot" "grim" "slurp"
"imagemagick" "tesseract" "tesseract-data-eng"
".PARU"
"wl-clipboard"
"pamixer" "pavucontrol"
"nwg-displays"
"adw-gtk-theme"
"pacman-contrib"
"fontconfig"
"nautilus" "gvfs" "gvfs-smb"
"firefox"
"gnome-keyring" "gcr-4"
)
install_paru() {
run_or_echo git clone https://aur.archlinux.org/paru.git /tmp/paru
run_or_echo sudo pacman -S --noconfirm --needed base-devel
run_or_echo bash -c "cd /tmp/paru && makepkg -si"
run_or_echo rm -rf /tmp/paru
}
install_packages() {
local aur_packages=()
local pacman_packages=()
local need_paru=false
for package in "$@"; do
if [[ $package == .AUR:* ]]; then
aur_packages+=("${package:5}")
need_paru=true
elif [[ $package == .PARU ]]; then
need_paru=true
else
pacman_packages+=("$package")
fi
done
if [[ $need_paru == true ]]; then
install_paru
fi
if [[ ${#aur_packages[@]} -gt 0 ]]; then
run_or_echo paru -S --noconfirm "${aur_packages[@]}"
fi
if [[ ${#pacman_packages[@]} -gt 0 ]]; then
run_or_echo sudo pacman -S --noconfirm "${pacman_packages[@]}"
fi
}
install_fonts() {
local os
os="$(uname -s)"
local font_dir=""
case "$os" in
Linux*) font_dir="$HOME/.local/share/fonts" ;;
Darwin*) font_dir="$HOME/Library/Fonts" ;;
*) return 0 ;;
esac
run_or_echo mkdir -p "$font_dir"
for font in "$@"; do
[[ -f "$font" ]] && run_or_echo cp -f "$font" "$font_dir/"
done
[[ "$os" == "Linux" ]] && run_or_echo fc-cache -f "$font_dir"
}
ensure_package() {
local dir="$1"
[[ -d "$REPO_PATH/$dir" ]] || error "Required directory '$dir' not found in repo."
}
record_component() {
local comp="$1"
touch "$INSTALLED_FILE"
if ! grep -Fxq "$comp" "$INSTALLED_FILE" 2>/dev/null; then
printf '%s\n' "$comp" >> "$INSTALLED_FILE"
fi
}
unrecord_component() {
local comp="$1"
if [[ -f "$INSTALLED_FILE" ]]; then
grep -Fxv "$comp" "$INSTALLED_FILE" > "$INSTALLED_FILE.tmp" || true
mv "$INSTALLED_FILE.tmp" "$INSTALLED_FILE"
fi
}
list_components() {
if [[ -f "$INSTALLED_FILE" ]]; then
cat "$INSTALLED_FILE"
fi
}
shells_installed=false
install_shells() {
ensure_package shells
$shells_installed && return
shells_installed=true
if ! $SKIP_PACKAGES; then
info "Installing shells..."
install_packages "${SHELLS_DEPS[@]}"
fi
[[ -f "$HOME/.bashrc" ]] && run_or_echo mv "$HOME/.bashrc" "$HOME/.bashrc.bak"
[[ -f "$HOME/.zshrc" ]] && run_or_echo mv "$HOME/.zshrc" "$HOME/.zshrc.bak"
run_or_echo stow -d "$REPO_PATH" -t "$HOME" shells
if ! $DRY_RUN; then
read -p "Set zsh as default shell? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
run_or_echo chsh -s "$(which zsh)"
info "Default shell set to zsh. You may need to log out and back in for this to take effect."
else
info "Default shell left unchanged."
fi
fi
}
neovim_installed=false
install_neovim() {
ensure_package nvim
$neovim_installed && return
neovim_installed=true
if ! $SKIP_PACKAGES; then
info "Installing neovim..."
install_packages "${NEOVIM_DEPS[@]}"
fi
run_or_echo stow -d "$REPO_PATH" -t "$HOME" nvim
}
terminal_installed=false
install_terminal() {
ensure_package terminal
ensure_package font
$terminal_installed && return
terminal_installed=true
if ! $SKIP_PACKAGES; then
info "Installing terminal..."
install_packages "${TERMINAL_DEPS[@]}"
install_fonts "$REPO_PATH/font"/*.otf
fi
run_or_echo stow -d "$REPO_PATH" -t "$HOME" terminal
}
install_goignis() {
run_or_echo git clone https://aur.archlinux.org/goignis.git /tmp/goignis
run_or_echo sudo pacman -S --noconfirm --needed base-devel
run_or_echo bash -c "cd /tmp/goignis && makepkg --nocheck -si"
run_or_echo rm -rf /tmp/goignis
}
desktop_installed=false
install_desktop() {
ensure_package desktop
install_terminal
$desktop_installed && return
desktop_installed=true
if ! $SKIP_PACKAGES; then
info "Installing desktop..."
install_packages "${DESKTOP_DEPS[@]}"
install_goignis
fi
run_or_echo stow -d "$REPO_PATH" -t "$HOME" desktop
run_or_echo sudo systemctl enable gdm
run_or_echo systemctl --user enable gcr-ssh-agent.socket
run_or_echo mkdir -p "$HOME/.local/share/ignis"
local optsf="$HOME/.config/hypr/opts.lua"
[[ -f "$optsf" ]] || run_or_echo echo "return {}" > "$optsf"
run_or_echo touch \
"$HOME/.local/share/ignis/hyprland.lua" \
"$HOME/.local/share/ignis/hyprlock.conf" \
"$HOME/.config/hypr/monitors.conf" \
"$HOME/.config/hypr/workspaces.conf" \
"$HOME/.config/hypr/hyprland-custom.lua"
if ! $DRY_RUN; then
info "Make sure you run nwg-displays to configure your displays graphically!"
echo -e "${GREEN_BOLD}You can reboot now.${RESET}"
read -p "Reboot now? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
run_or_echo systemctl reboot
fi
fi
}
do_install_component() {
local comp="$1"
case "$comp" in
shells) install_shells ;;
neovim|nvim) install_neovim ;;
terminal) install_terminal ;;
desktop) install_desktop ;;
*) error "Unknown component: $comp" ;;
esac
record_component "$comp"
}
do_remove_component() {
local comp="$1"
if [[ ! -d "$REPO_PATH/$comp" ]]; then
info "Component $comp not present in repo; skipping unstow."
else
run_or_echo stow -d "$REPO_PATH" -t "$HOME" -D "$comp"
fi
unrecord_component "$comp"
}
command_install() {
shift || true
if [[ $# -eq 0 ]]; then
error "install requires at least one component or 'all'"
fi
if [[ $1 == all ]]; then
set -- nvim shells terminal desktop
fi
[[ -f "/etc/arch-release" ]] || error "Arch Linux only."
[[ ! -f "/run/archiso/cowspace" ]] || error "Do not run in live environment. Install Arch and run this script from there."
[[ "$(uname -m)" == "x86_64" ]] || error "x86_64 only."
if ! $DRY_RUN; then
info "ATTENTION! This will install packages and modify your system."
read -p "Proceed? (y/n) " -n 1 -r
echo
[[ $REPLY =~ ^[Yy]$ ]] || error "Aborted."
else
info "Dry run mode: no changes will be made."
fi
run_or_echo sudo pacman -Syy
for comp in "$@"; do
do_install_component "$comp"
done
}
command_update() {
local skip=false
if [[ "$1" == "--skip-packages" || "$1" == "-s" ]]; then
skip=true
fi
if $skip; then
SKIP_PACKAGES=true
info "Updating repository (packages will be skipped)..."
else
info "Updating repository..."
fi
git -C "$REPO_PATH" pull --ff-only || error "Failed to update repo."
if [[ -f "$INSTALLED_FILE" ]]; then
local installed_components=()
mapfile -t installed_components < "$INSTALLED_FILE"
for comp in "${installed_components[@]}"; do
[[ -z "$comp" ]] && continue
info "Reapplying $comp..."
case "$comp" in
shells|neovim|nvim|terminal|desktop)
do_install_component "$comp"
;;
*)
info "Unknown recorded component: $comp; skipping."
;;
esac
done
else
info "No installed components recorded; nothing to update."
fi
SKIP_PACKAGES=false
}
command_list() {
if [[ -f "$INSTALLED_FILE" ]]; then
echo "Installed components:"
nl -w2 -s'. ' "$INSTALLED_FILE"
else
echo "No components recorded as installed."
fi
}
command_remove() {
shift || true
if [[ $# -eq 0 ]]; then
error "remove requires at least one component or 'all'"
fi
if [[ $1 == all ]]; then
if [[ -f "$INSTALLED_FILE" ]]; then
mapfile -t to_remove < "$INSTALLED_FILE"
else
error "No installed components to remove."
fi
else
to_remove=("$@")
fi
for comp in "${to_remove[@]}"; do
do_remove_component "$comp"
done
}
usage() {
cat <<EOF
Usage: $0 [--dry-run] <command> [args]
Commands:
install <component...|all> Install one or more components (shells nvim terminal desktop)
update [--skip-packages|-s] Update repo and reapply recorded components (optional skip packages)
list List recorded installed components
remove <component...|all> Unstow and forget components
--help
EOF
}
if [[ "$1" == "--dry-run" ]]; then
DRY_RUN=true
shift
fi
case "$1" in
install) command_install "$@" ;;
update) command_update "${@:2}" ;;
list) command_list ;;
remove) command_remove "$@" ;;
-h|--help|help) usage ;;
"") usage ;;
*) error "Unknown command: $1" ;;
esac