-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall
More file actions
executable file
·392 lines (327 loc) · 11 KB
/
Copy pathinstall
File metadata and controls
executable file
·392 lines (327 loc) · 11 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
#!/usr/bin/env bash
# Modernized dotfiles installation script
# This script sets up the environment using dotbot and handles vim plugin installation.
set -euo pipefail
# --- Configuration ---
CONFIG="install.conf.yaml"
DOTBOT_DIR="dotbot"
DOTBOT_BIN="bin/dotbot"
# Get the absolute path of the script directory
BASEDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# --- Colors for output ---
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
# --- Helper Functions ---
backup_existing_files() {
log_info "Backing up existing regular files that should be symlinks..."
# Extract target paths from the config file
# We look for lines containing '~/' and a ':'
grep '~/' "${BASEDIR}/${CONFIG}" | grep ':' | sed 's/ *:.*//' | sed 's/^ *//' \
| while IFS= read -r target; do
local full_path="${target/#\~/$HOME}"
if [[ -f "$full_path" && ! -L "$full_path" ]]; then
local backup_path="${full_path}.bak"
log_warn "Backing up existing regular file: $full_path -> $backup_path"
mv -f "$full_path" "$backup_path"
fi
done
log_success "Backup completed."
}
check_dependencies() {
log_info "Checking dependencies..."
local deps=("git" "python3")
for dep in "${deps[@]}"; do
if ! command -v "$dep" &> /dev/null; then
log_error "Required dependency '$dep' is not installed. Please install it and try again."
exit 1
fi
done
log_success "All dependencies found."
}
setup_dotbot() {
log_info "Updating dotbot submodule..."
# Init first (required on fresh clones), then sync nested submodules
git -C "${BASEDIR}" submodule update --init --recursive "${DOTBOT_DIR}"
git -C "${BASEDIR}/${DOTBOT_DIR}" submodule sync --quiet --recursive
log_success "Dotbot submodule updated."
}
run_dotbot() {
log_info "Running dotbot to link configuration files..."
local dotbot_path="${BASEDIR}/${DOTBOT_DIR}/${DOTBOT_BIN}"
if [[ ! -x "$dotbot_path" ]]; then
log_error "Dotbot binary not found or not executable at $dotbot_path"
exit 1
fi
# Execute dotbot with provided arguments
"${dotbot_path}" -d "${BASEDIR}" -c "${CONFIG}" "${@}"
log_success "Dotbot execution completed."
}
install_vim_plugins() {
if ! command -v vim &> /dev/null; then
log_warn "Vim not found, skipping plugin installation."
return 0
fi
if [[ ! -t 0 ]]; then
log_warn "No TTY available, skipping Vim plugin installation."
return 0
fi
log_info "Installing and updating Vim plugins..."
vim +PluginInstall +PluginUpdate +qall
log_success "Vim plugins updated."
}
# --- Arch Linux / CachyOS Packages Installation ---
is_arch_or_cachyos() {
if [[ ! -f /etc/os-release ]]; then
return 1
fi
local ID="" ID_LIKE=""
. /etc/os-release
[[ "$ID" == "arch" || "$ID" == "cachyos" || "$ID_LIKE" =~ arch ]]
}
# --- Interactive Menu Helpers ---
ESC=$(printf '\033')
cursor_up() { printf "\033[%dA" "$1" >&2; }
hide_cursor() { printf "\033[?25l" >&2; }
show_cursor() { printf "\033[?25h" >&2; }
read_key() {
local key
IFS= read -r -s -n 1 key
if [[ "$key" == "$ESC" ]]; then
read -r -s -n 2 key
if [[ "$key" == "[A" ]]; then
echo "UP"
elif [[ "$key" == "[B" ]]; then
echo "DOWN"
fi
elif [[ "$key" == " " ]]; then
echo "SPACE"
elif [[ "$key" == "" || "$key" == $'\r' || "$key" == $'\n' ]]; then
echo "ENTER"
fi
}
draw_menu() {
local active_idx=$1
for i in "${!options[@]}"; do
local prefix=" "
if (( i == active_idx )); then
prefix="${BLUE}➔${NC} "
fi
local check="[ ]"
if [[ "${selected[i]}" == "1" ]]; then
check="[${GREEN}*${NC}]"
fi
if (( i == active_idx )); then
printf "%b%b %b\n" "$prefix" "$check" "${BLUE}${options[i]}${NC}" >&2
else
printf "%b%b %b\n" "$prefix" "$check" "${options[i]}" >&2
fi
done
}
show_multi_select() {
local -a options=("${@}")
local -a selected=()
for i in "${!options[@]}"; do
selected[i]=1
done
local active=0
local num_options=${#options[@]}
hide_cursor
draw_menu "$active"
while true; do
local key
key=$(read_key)
case "$key" in
UP)
if (( active > 0 )); then
active=$((active - 1))
else
active=$((num_options - 1))
fi
;;
DOWN)
if (( active < num_options - 1 )); then
active=$((active + 1))
else
active=0
fi
;;
SPACE)
if [[ "${selected[active]}" == "1" ]]; then
selected[active]=0
else
selected[active]=1
fi
;;
ENTER)
break
;;
esac
cursor_up "$num_options"
draw_menu "$active"
done
show_cursor
local results=()
for i in "${!options[@]}"; do
if [[ "${selected[i]}" == "1" ]]; then
results+=("$i")
fi
done
if (( ${#results[@]} > 0 )); then
echo "${results[@]}"
fi
}
ensure_aur_helper() {
if command -v paru &> /dev/null; then
AUR_HELPER="paru"
elif command -v yay &> /dev/null; then
AUR_HELPER="yay"
else
log_info "No AUR helper (paru or yay) found, which is needed to install AUR packages."
local choice
read -rp "Would you like to install yay? [Y/n] " choice < /dev/tty
if [[ "$choice" =~ ^[Nn]$ ]]; then
log_warn "Skipping AUR helper installation. AUR packages might fail to install."
AUR_HELPER="sudo pacman"
else
log_info "Installing yay..."
local tmpdir
tmpdir=$(mktemp -d)
trap "rm -rf '$tmpdir'" EXIT
if git clone https://aur.archlinux.org/yay-bin.git "$tmpdir/yay-bin" &>/dev/null; then
(cd "$tmpdir/yay-bin" && makepkg -si --noconfirm)
AUR_HELPER="yay"
log_success "yay installed successfully!"
else
log_error "Failed to clone yay-bin. Falling back to sudo pacman."
AUR_HELPER="sudo pacman"
fi
rm -rf "$tmpdir"
trap - EXIT
fi
fi
}
install_arch_packages() {
if ! is_arch_or_cachyos; then
return 0
fi
log_info "Detected Arch Linux or CachyOS system."
local packages_dir="${BASEDIR}/dist/arch/packages"
if [[ ! -d "$packages_dir" ]]; then
log_warn "Packages directory not found at $packages_dir. Skipping package installation."
return 0
fi
# Find all package files (*.txt)
local files=()
while IFS= read -r -d '' file; do
files+=("$file")
done < <(find "$packages_dir" -maxdepth 1 -name "*.txt" -print0 | sort -z)
if (( ${#files[@]} == 0 )); then
log_warn "No package files (*.txt) found in $packages_dir."
return 0
fi
# Prepare display options
local options=()
for file in "${files[@]}"; do
options+=("$(basename "$file" .txt)")
done
log_info "Select the package categories you would like to install."
echo -e "Use ${BLUE}Up/Down Arrow${NC} keys to navigate, ${BLUE}Space${NC} to toggle, and ${BLUE}Enter${NC} to confirm:\n" >&2
# Set up exit trap for cursor restoration
trap show_cursor EXIT
local selected_idxs=()
selected_idxs=($(show_multi_select "${options[@]}"))
if (( ${#selected_idxs[@]} == 0 )); then
log_warn "No categories selected. Skipping package installation."
return 0
fi
# Read packages from selected files
local all_pkgs=()
for idx in "${selected_idxs[@]}"; do
local file="${files[idx]}"
log_info "Reading packages from $(basename "$file")..."
while IFS= read -r line || [[ -n "$line" ]]; do
line="${line#"${line%%[![:space:]]*}"}"
line="${line%"${line##*[![:space:]]}"}"
if [[ -n "$line" && ! "$line" =~ ^# ]]; then
all_pkgs+=("$line")
fi
done < "$file"
done
if (( ${#all_pkgs[@]} == 0 )); then
log_warn "No packages found in selected categories."
return 0
fi
# Filter out already installed packages
local to_install=()
local installed_count=0
local -A installed_pkgs
while IFS= read -r pkg; do
installed_pkgs["$pkg"]=1
done < <(pacman -Qq 2>/dev/null)
for pkg in "${all_pkgs[@]}"; do
if [[ -n "${installed_pkgs[$pkg]+x}" ]]; then
installed_count=$((installed_count + 1))
else
to_install+=("$pkg")
fi
done
log_info "Package status: ${installed_count} already installed, ${#to_install[@]} to install."
if (( ${#to_install[@]} == 0 )); then
log_success "All selected packages are already installed!"
return 0
fi
log_info "Packages to install: ${to_install[*]}"
# Ensure AUR helper is available
local AUR_HELPER=""
ensure_aur_helper
log_info "Installing packages using $AUR_HELPER..."
if [[ "$AUR_HELPER" == "sudo pacman" ]]; then
sudo pacman -S --needed "${to_install[@]}"
else
$AUR_HELPER -S --needed "${to_install[@]}"
fi
log_success "Package installation completed successfully!"
}
apply_live_changes() {
log_info "Applying system and desktop configuration changes..."
# Rebuild font cache
if command -v fc-cache &> /dev/null; then
log_info "Rebuilding font cache..."
fc-cache -f || log_warn "Failed to rebuild font cache"
fi
# Merge Xresources
if command -v xrdb &> /dev/null && [[ -f "$HOME/.Xresources" ]]; then
log_info "Reloading X resources..."
xrdb -merge "$HOME/.Xresources" || log_warn "Failed to reload X resources"
fi
# Reload Mako notification daemon
if command -v makoctl &> /dev/null && pgrep -x mako &> /dev/null; then
log_info "Reloading Mako configuration..."
makoctl reload || log_warn "Failed to reload Mako"
fi
# Reload Waybar
if pgrep -x waybar &> /dev/null; then
log_info "Reloading Waybar..."
pkill -USR2 waybar || log_warn "Failed to signal Waybar to reload"
fi
}
main() {
log_info "Starting dotfiles installation..."
check_dependencies
install_arch_packages
backup_existing_files
setup_dotbot
run_dotbot "$@"
install_vim_plugins
apply_live_changes
log_success "Dotfiles installation completed successfully!"
}
# Start the script
main "$@"