-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·355 lines (323 loc) · 12.9 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·355 lines (323 loc) · 12.9 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
#!/usr/bin/env bash
# Dotfiles installer using GNU Stow
# https://www.gnu.org/software/stow/
set -e
DOTFILES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PACKAGES_DIR="$DOTFILES_DIR/packages"
TARGET_DIR="$HOME"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# All available packages (directories in packages/)
get_packages() {
local packages=()
for dir in "$PACKAGES_DIR"/*/; do
dir_name=$(basename "$dir")
packages+=("$dir_name")
done
echo "${packages[@]}"
}
usage() {
echo -e "${BLUE}Dotfiles Installer${NC}"
echo ""
echo "Usage: $0 [OPTIONS] [PACKAGES...]"
echo ""
echo "Options:"
echo " -l, --list List all available packages"
echo " -a, --all Install all packages"
echo " -u, --unstow Uninstall (unstow) packages"
echo " -r, --restow Restow packages (useful after updates)"
echo " -n, --dry-run Show what would be done without making changes"
echo " -s, --setup-system Run optional system-level configuration (requires sudo)"
echo " -h, --help Show this help message"
echo ""
echo "Examples:"
echo " $0 -l # List available packages"
echo " $0 -a # Install all packages"
echo " $0 nvim zsh tmux # Install specific packages"
echo " $0 -u nvim # Uninstall nvim package"
echo " $0 -r nvim # Restow nvim (after pulling updates)"
echo " $0 -n -a # Dry-run: show what would be installed"
echo " $0 -s # Run system-level configuration prompts"
echo ""
}
list_packages() {
echo -e "${BLUE}Available packages:${NC}"
echo ""
for pkg in $(get_packages); do
if is_stowed "$pkg"; then
echo -e " ${GREEN}[installed]${NC} $pkg"
else
echo -e " ${YELLOW}[available]${NC} $pkg"
fi
done
echo ""
}
is_stowed() {
local pkg="$1"
local pkg_dir="$PACKAGES_DIR/$pkg"
# Check for root-level dotfiles
for item in "$pkg_dir"/.*; do
if [[ -e "$item" && "$(basename "$item")" != "." && "$(basename "$item")" != ".." ]]; then
local target="$TARGET_DIR/$(basename "$item")"
if [[ -L "$target" ]]; then
return 0
fi
fi
done
# Check for .config directory items
if [[ -d "$pkg_dir/.config" ]]; then
for item in "$pkg_dir/.config"/*; do
if [[ -e "$item" ]]; then
local target="$TARGET_DIR/.config/$(basename "$item")"
if [[ -L "$target" ]]; then
return 0
fi
fi
done
fi
return 1
}
stow_package() {
local pkg="$1"
local action="$2"
local dry_run="$3"
local stow_opts=("-v" "-t" "$TARGET_DIR" "-d" "$PACKAGES_DIR")
if [[ "$dry_run" == "true" ]]; then
stow_opts+=("-n")
fi
case "$action" in
install)
echo -e "${GREEN}Installing${NC} $pkg..."
stow "${stow_opts[@]}" "$pkg"
;;
unstow)
echo -e "${YELLOW}Uninstalling${NC} $pkg..."
stow "${stow_opts[@]}" -D "$pkg"
;;
restow)
echo -e "${BLUE}Restowing${NC} $pkg..."
stow "${stow_opts[@]}" -R "$pkg"
;;
esac
}
setup_system() {
echo -e "${BLUE}System-level configuration${NC}"
echo ""
# OpenVPN3 + systemd-resolved DNS integration
if command -v openvpn3 &> /dev/null && command -v openvpn3-admin &> /dev/null; then
local current_config
current_config=$(sudo cat /var/lib/openvpn3/netcfg.json 2>/dev/null || echo "")
if echo "$current_config" | grep -q '"systemd_resolved" : true'; then
echo -e " ${GREEN}[configured]${NC} openvpn3 systemd-resolved DNS"
else
echo -n -e " ${YELLOW}[available]${NC} Configure openvpn3 to use systemd-resolved for DNS? [y/N] "
read -r answer
if [[ "$answer" =~ ^[Yy]$ ]]; then
sudo mkdir -p /var/lib/openvpn3
sudo openvpn3-admin netcfg-service --config-set systemd-resolved true
echo -e " ${GREEN}[configured]${NC} openvpn3 systemd-resolved DNS"
else
echo -e " ${YELLOW}[skipped]${NC} openvpn3 systemd-resolved DNS"
fi
fi
fi
# openvpn3-tun-dns@tun0 — attach CloudConnexa DNS to the tunnel link.
# netcfg doesn't apply the VPN-pushed DNS, so internal DT hosts won't resolve
# without this. WantedBy the tun0 device unit, so it re-runs on every connect.
if command -v openvpn3 &> /dev/null; then
local tundns_script_src="$DOTFILES_DIR/scripts/openvpn3-tun-dns"
local tundns_script_dst="/usr/local/bin/openvpn3-tun-dns"
local tundns_unit_src="$DOTFILES_DIR/etc/systemd/system/openvpn3-tun-dns@.service"
local tundns_unit_dst="/etc/systemd/system/openvpn3-tun-dns@.service"
if [[ -x "$tundns_script_dst" ]] && cmp -s "$tundns_script_src" "$tundns_script_dst" \
&& [[ -f "$tundns_unit_dst" ]] && cmp -s "$tundns_unit_src" "$tundns_unit_dst" \
&& systemctl is-enabled openvpn3-tun-dns@tun0.service &>/dev/null; then
echo -e " ${GREEN}[configured]${NC} openvpn3-tun-dns@tun0 DNS hook"
else
echo -n -e " ${YELLOW}[available]${NC} Install openvpn3 tunnel DNS hook (resolves internal DT hosts)? [y/N] "
read -r answer
if [[ "$answer" =~ ^[Yy]$ ]]; then
sudo install -Dm755 "$tundns_script_src" "$tundns_script_dst"
sudo install -Dm644 "$tundns_unit_src" "$tundns_unit_dst"
sudo systemctl daemon-reload
sudo systemctl enable openvpn3-tun-dns@tun0.service
echo -e " ${GREEN}[configured]${NC} openvpn3-tun-dns@tun0 DNS hook"
else
echo -e " ${YELLOW}[skipped]${NC} openvpn3-tun-dns@tun0 DNS hook"
fi
fi
fi
# hyprpm pacman hook — rebuild plugins after Hyprland upgrades
if command -v hyprpm &> /dev/null; then
local hook_src="$DOTFILES_DIR/etc/pacman.d/hooks/hyprpm.hook"
local hook_dst="/etc/pacman.d/hooks/hyprpm.hook"
if [[ -f "$hook_dst" ]] && sudo grep -q "su $USER -c" "$hook_dst" 2>/dev/null; then
echo -e " ${GREEN}[configured]${NC} hyprpm pacman hook"
else
echo -n -e " ${YELLOW}[available]${NC} Install pacman hook to rebuild hyprpm plugins after Hyprland upgrades? [y/N] "
read -r answer
if [[ "$answer" =~ ^[Yy]$ ]]; then
sed "s/__USER__/$USER/g" "$hook_src" | sudo install -Dm644 /dev/stdin "$hook_dst"
echo -e " ${GREEN}[configured]${NC} hyprpm pacman hook"
else
echo -e " ${YELLOW}[skipped]${NC} hyprpm pacman hook"
fi
fi
fi
# Hyprland launcher — sets NVIDIA/Wayland env then execs Hyprland's own
# watchdog (/usr/bin/start-hyprland). Must be named hypr-launch, NOT
# start-hyprland, or it shadows Hyprland's launcher on PATH.
local launch_src="$DOTFILES_DIR/scripts/hypr-launch"
local launch_dst="/usr/local/bin/hypr-launch"
if [[ -x "$launch_dst" ]] && cmp -s "$launch_src" "$launch_dst"; then
echo -e " ${GREEN}[configured]${NC} hypr-launch launcher"
else
echo -n -e " ${YELLOW}[available]${NC} Install Hyprland launcher to $launch_dst? [y/N] "
read -r answer
if [[ "$answer" =~ ^[Yy]$ ]]; then
sudo install -Dm755 "$launch_src" "$launch_dst"
# Remove the old same-named wrapper that shadowed /usr/bin/start-hyprland.
[[ -e /usr/local/bin/start-hyprland ]] && sudo rm -f /usr/local/bin/start-hyprland
echo -e " ${GREEN}[configured]${NC} hypr-launch launcher"
else
echo -e " ${YELLOW}[skipped]${NC} hypr-launch launcher"
fi
fi
# NVIDIA app profile — the driver hoards VRAM freed by Wayland compositors
# in a per-process reuse pool and never trims it (1-2GB/day of window
# churn). GLVidHeapReuseRatio=0 for Hyprland makes it return freed buffers
# immediately. Read at compositor startup, so needs a session restart.
if [[ -d /proc/driver/nvidia ]]; then
local nvprofile_src="$DOTFILES_DIR/etc/nvidia/nvidia-application-profiles-rc.d/50-limit-free-buffer-pool-in-wayland-compositors.json"
local nvprofile_dst="/etc/nvidia/nvidia-application-profiles-rc.d/50-limit-free-buffer-pool-in-wayland-compositors.json"
if [[ -f "$nvprofile_dst" ]] && cmp -s "$nvprofile_src" "$nvprofile_dst"; then
echo -e " ${GREEN}[configured]${NC} NVIDIA VRAM buffer-pool profile"
else
echo -n -e " ${YELLOW}[available]${NC} Install NVIDIA profile to stop Hyprland VRAM hoarding? [y/N] "
read -r answer
if [[ "$answer" =~ ^[Yy]$ ]]; then
sudo install -Dm644 "$nvprofile_src" "$nvprofile_dst"
echo -e " ${GREEN}[configured]${NC} NVIDIA VRAM buffer-pool profile"
else
echo -e " ${YELLOW}[skipped]${NC} NVIDIA VRAM buffer-pool profile"
fi
fi
fi
# udev rule — keep the TP-Link UB500 BT adapter powered. USB autosuspend
# drops the adapter after 2s idle, disconnecting BT peripherals mid-use
# (ended slurp screenshot drags early via synthesized button release).
local btudev_src="$DOTFILES_DIR/etc/udev/rules.d/50-bt-adapter-no-autosuspend.rules"
local btudev_dst="/etc/udev/rules.d/50-bt-adapter-no-autosuspend.rules"
if [[ -f "$btudev_dst" ]] && cmp -s "$btudev_src" "$btudev_dst"; then
echo -e " ${GREEN}[configured]${NC} BT adapter no-autosuspend udev rule"
else
echo -n -e " ${YELLOW}[available]${NC} Install udev rule to stop BT adapter autosuspend (drops mouse mid-use)? [y/N] "
read -r answer
if [[ "$answer" =~ ^[Yy]$ ]]; then
sudo install -Dm644 "$btudev_src" "$btudev_dst"
sudo udevadm control --reload-rules
echo -e " ${GREEN}[configured]${NC} BT adapter no-autosuspend udev rule"
else
echo -e " ${YELLOW}[skipped]${NC} BT adapter no-autosuspend udev rule"
fi
fi
# rime-umount.service — force-unmount the Rime CIFS share early on shutdown
# so the kernel doesn't block ~180s on the unreachable server (shutdown hang).
local rime_src="$DOTFILES_DIR/etc/systemd/system/rime-umount.service"
local rime_dst="/etc/systemd/system/rime-umount.service"
if [[ -f "$rime_dst" ]] && cmp -s "$rime_src" "$rime_dst" && systemctl is-enabled rime-umount.service &>/dev/null; then
echo -e " ${GREEN}[configured]${NC} rime-umount shutdown service"
else
echo -n -e " ${YELLOW}[available]${NC} Install rime-umount shutdown service (avoids CIFS shutdown hang)? [y/N] "
read -r answer
if [[ "$answer" =~ ^[Yy]$ ]]; then
sudo install -Dm644 "$rime_src" "$rime_dst"
sudo systemctl daemon-reload
sudo systemctl enable rime-umount.service
echo -e " ${GREEN}[configured]${NC} rime-umount shutdown service"
else
echo -e " ${YELLOW}[skipped]${NC} rime-umount shutdown service"
fi
fi
echo ""
echo -e "${GREEN}System configuration complete!${NC}"
}
# Parse arguments
ACTION="install"
DRY_RUN="false"
PACKAGES=()
while [[ $# -gt 0 ]]; do
case "$1" in
-l|--list)
list_packages
exit 0
;;
-a|--all)
PACKAGES=($(get_packages))
shift
;;
-u|--unstow)
ACTION="unstow"
shift
;;
-r|--restow)
ACTION="restow"
shift
;;
-s|--setup-system)
setup_system
exit 0
;;
-n|--dry-run)
DRY_RUN="true"
shift
;;
-h|--help)
usage
exit 0
;;
-*)
echo -e "${RED}Unknown option: $1${NC}"
usage
exit 1
;;
*)
PACKAGES+=("$1")
shift
;;
esac
done
# Check if stow is installed
if ! command -v stow &> /dev/null; then
echo -e "${RED}Error: GNU Stow is not installed.${NC}"
echo "Install it with: sudo pacman -S stow"
exit 1
fi
# If no packages specified, show help
if [[ ${#PACKAGES[@]} -eq 0 ]]; then
usage
exit 0
fi
# Validate packages
VALID_PACKAGES=($(get_packages))
for pkg in "${PACKAGES[@]}"; do
if [[ ! " ${VALID_PACKAGES[*]} " =~ " ${pkg} " ]]; then
echo -e "${RED}Error: Unknown package '$pkg'${NC}"
echo "Run '$0 -l' to see available packages."
exit 1
fi
done
# Process packages
if [[ "$DRY_RUN" == "true" ]]; then
echo -e "${YELLOW}Dry-run mode: showing what would be done${NC}"
echo ""
fi
for pkg in "${PACKAGES[@]}"; do
stow_package "$pkg" "$ACTION" "$DRY_RUN"
done
echo ""
echo -e "${GREEN}Done!${NC}"