-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·231 lines (205 loc) · 6.1 KB
/
install.sh
File metadata and controls
executable file
·231 lines (205 loc) · 6.1 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
#!/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
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}"