Krolyxon
Commit 1658e95

Branches

Refs →

aurora1658e95

add better error handling for install script, add --yes flag.

Author
krolxon
Date
2026-01-07 23:06 +0530
Parent
9e1bc68
Commit
1658e9527a6c14e01ced5b9a0add3d75c9fda526

+126 −56

1 file changed

  1. M install.sh +126 −56
M install.sh View
@@ -1,4 +1,17 @@
1−#!/bin/env bash
1+#!/usr/bin/env bash
2+
3+trap 'log WARN "Interrupted by user"; exit 130' INT
4+
5+INSTALL_STATUS="none" # none | partial | complete | failed
6+AUTO_YES=0
7+
8+for arg in "$@"; do
9+ case "$arg" in
10+ --yes|--ci|--non-interactive)
11+ AUTO_YES=1
12+ ;;
13+ esac
14+done
215
316 log() {
417 local level="$1"
@@ -51,10 +64,10 @@ choose_packages() {
5164 }
5265
5366 prompt_style() {
54− gum style --border rounded \
55− --border double \
56− --padding "0 1" \
57− "$1"
67+ gum style \
68+ --border rounded \
69+ --padding "0 1" \
70+ "$1"
5871 }
5972
6073 gum_warn(){
@@ -62,7 +75,22 @@ gum_warn(){
6275 }
6376
6477 gum_to_array() {
65− mapfile -t "$1"
78+ local -n arr="$1"
79+ mapfile -t arr
80+ local cleaned=()
81+ for item in "${arr[@]}"; do
82+ [[ -n "$item" ]] && cleaned+=("$item")
83+ done
84+ arr=("${cleaned[@]}")
85+}
86+
87+confirm() {
88+ local msg="$1"
89+ if ((AUTO_YES)); then
90+ log INFO "[auto] $msg → yes"
91+ return 0
92+ fi
93+ gum confirm --default=false "$msg"
6694 }
6795
6896 #################
@@ -92,7 +120,7 @@ You are STRONGLY ADVISED to back up:
92120 Proceed at your OWN RISK."
93121 )
94122
95−gum confirm --default=false "$DISCLAIMER
123+confirm "$DISCLAIMER
96124
97125 Do you understand the risks and want to continue?" || exit 1
98126
@@ -102,7 +130,11 @@ Do you understand the risks and want to continue?" || exit 1
102130 ###########
103131 source "$currentDir/packages/pkg_utils.sh"
104132 prompt_style "Important utilities (Most likely go with defaults)"
105−gum_to_array UTILITY_PKGS < <(choose_packages pkg_utils)
133+if ((AUTO_YES)); then
134+ DEV_PKGS=("${pkg_utils[@]}")
135+else
136+ gum_to_array UTILITY_PKGS < <(choose_packages pkg_utils)
137+fi
106138
107139
108140 ###############
@@ -110,7 +142,12 @@ gum_to_array UTILITY_PKGS < <(choose_packages pkg_utils)
110142 ###############
111143 source "$currentDir/packages/pkg_dev_tools.sh"
112144 prompt_style "Select Development Tools"
113−gum_to_array DEV_PKGS < <(choose_packages pkg_dev_tools)
145+if ((AUTO_YES)); then
146+ DEV_PKGS=("${pkg_dev_tools[@]}")
147+else
148+ gum_to_array DEV_PKGS < <(choose_packages pkg_dev_tools)
149+fi
150+
114151
115152
116153 #######################
@@ -118,7 +155,12 @@ gum_to_array DEV_PKGS < <(choose_packages pkg_dev_tools)
118155 #######################
119156 source "$currentDir/packages/pkg_optional.sh"
120157 prompt_style "Select Optional Desktop Packages"
121−gum_to_array OPTIONAL_PKGS < <(choose_packages pkg_optional)
158+if ((AUTO_YES)); then
159+ OPTIONAL_PKGS=("${pkg_optional[@]}")
160+else
161+ gum_to_array OPTIONAL_PKGS < <(choose_packages pkg_optional)
162+fi
163+
122164
123165
124166 #################
@@ -126,7 +168,12 @@ gum_to_array OPTIONAL_PKGS < <(choose_packages pkg_optional)
126168 #################
127169 source "$currentDir/packages/pkg_gpu.sh"
128170 prompt_style "Select GPU drivers"
129−gum_to_array GPU_PKGS < <(choose_packages pkg_gpu)
171+if ((AUTO_YES)); then
172+ GPU_PKGS=("${pkg_gpu[@]}")
173+else
174+ gum_to_array GPU_PKGS < <(choose_packages pkg_gpu)
175+fi
176+
130177
131178 ##########################
132179 ## Configure Everything ##
@@ -139,9 +186,9 @@ WARNING=$(gum style \
139186 "⚠️ This will DELETE any conflicting files and replace them with symlinks from this repo.
140187 Make sure you have already backed up all your existing config files (~/.config)")
141188
142−if gum confirm --default=false "$WARNING
189+if confirm "$WARNING
143190
144−Proceed with system configuration (stow, nvim, shell, keyd)?"; then
191+Proceed with system configuration (stow, shell)?"; then
145192 ###################
146193 ## Stow dotfiles ##
147194 ###################
@@ -159,12 +206,13 @@ Proceed with system configuration (stow, nvim, shell, keyd)?"; then
159206 printf ' %s\n' $conflicts
160207 read -rp "Proceed with deleting these files? (y/N): " ok
161208 if [[ ! "$ok" =~ ^[Yy]$ ]]; then
162− echo "Aborted."
209+ log WARN "Aborted."
210+ exit 1
163211 fi
164212
165213 # Remove conflicts relative to $HOME
166214 for path in $conflicts; do
167− rm -rf "$HOME/$path" && log INFO "Removed $HOME/$path"
215+ [[ -n "$path" && "$path" != "/" ]] && rm -rf "$HOME/$path" && log INFO "Deleted $path"
168216 done
169217
170218 log INFO "Running stow..."
@@ -173,22 +221,11 @@ Proceed with system configuration (stow, nvim, shell, keyd)?"; then
173221 || log ERROR "Stow failed"
174222 fi
175223
176− ###########################
177− ## Setup neovim dotfiles ##
178− ###########################
179− log INFO "Setting up neovim configuration"
180− log INFO "Taking backup of neovim config (if already exists)"
181− mv ~/.config/nvim{,.bak}
182− mv ~/.local/share/nvim{,.bak}
183− mv ~/.local/state/nvim{,.bak}
184− mv ~/.cache/nvim{,.bak}
185− git clone --depth=1 https://github.com/krolyxon/nvim.git ~/.config/nvim
186−
187224 #################################
188225 ## Change default shell to zsh ##
189226 #################################
190227 log INFO "Changing the default shell to ZSH"
191− if [[ "$SHELL" != "$(which zsh)" ]]; then
228+ if [[ "$SHELL" != "$(command -v zsh)" ]]; then
192229 chsh -s $(which zsh) \
193230 && log SUCCESS "Default shell successfully set to zsh" \
194231 || log ERROR "Default shell could not be set to zsh"
@@ -205,26 +242,23 @@ fi
205242 ##################
206243 source "$currentDir/packages/pkg_aur.sh"
207244 prompt_style "Select AUR packages"
208−gum_to_array AUR_PKGS < <(choose_packages pkg_aur)
209−if [[ ${#AUR_PKGS[@]} -eq 0 ]]; then
210− log WARN "No AUR packages selected"
245+
246+if ((AUTO_YES)); then
247+ AUR_PKGS=("${pkg_aur[@]}")
211248 else
212− if ! command -v paru >/dev/null 2>&1; then
249+ gum_to_array AUR_PKGS < <(choose_packages pkg_aur)
250+fi
251+
252+if ((${#AUR_PKGS[@]})); then
253+ if ! command -v paru >/dev/null 2>&1; then
213254 log INFO "Installing Paru (AUR package manager)"
214255 git clone https://aur.archlinux.org/paru.git
215− cd paru
216− makepkg -sri
217− cd ..
256+ (cd paru && makepkg -sri)
218257 rm -rf paru
219− else
220− log INFO "Paru already in PATH, Skipping...."
221− fi
222−
223− if [[ ${#AUR_PKGS[@]} -eq 0 ]]; then
224− log WARN "No AUR packages selected, Skipping...."
225− else
226− paru -S --needed "${AUR_PKGS[@]}"
227258 fi
259+ paru -S --needed "${AUR_PKGS[@]}"
260+else
261+ log WARN "No AUR packages selected"
228262 fi
229263
230264
@@ -232,7 +266,7 @@ fi
232266 ## Setup Keyd ##
233267 ############################
234268 if command -v keyd >/dev/null 2>&1; then
235− if gum confirm --default=false "Configure and enable keyd? "; then
269+ if confirm "Configure and enable keyd? "; then
236270 log INFO "Copying keyd configuration to /etc/keyd/default.conf"
237271 sudo cp "$currentDir/system/etc/keyd/default.conf" /etc/keyd/
238272 sudo systemctl enable --now keyd.service \
@@ -253,23 +287,59 @@ ALL_PKGS=(
253287 "${pkg_desktop[@]}"
254288 )
255289
256−if [[ ${#ALL_PKGS[@]} -eq 0 ]]; then
257− log WARN "No packages selected."
258−else
259− if gum confirm --default=false "Install all the selected packages?"; then
290+if ((${#ALL_PKGS[@]})); then
291+ if confirm "Install all the selected packages?"; then
260292 log INFO "Installing selected packages..."
261− sudo pacman -Sy --needed "${ALL_PKGS[@]}"
293+ if sudo pacman -Syu --needed "${ALL_PKGS[@]}"; then
294+ INSTALL_STATUS="complete"
295+ else
296+ INSTALL_STATUS="failed"
297+ fi
298+ else
299+ log WARN "Package installation skipped by user"
300+ INSTALL_STATUS="partial"
262301 fi
302+else
303+ log WARN "No packages selected"
304+ INSTALL_STATUS="partial"
263305 fi
264306
265307
266−gum style \
267− --border rounded \
268− --padding "1 2" \
269− --bold \
270− --foreground 42 \
271−"🎉 Installation Complete!
272−
273−Your system has been successfully configured.
308+case "$INSTALL_STATUS" in
309+ complete)
310+ gum style \
311+ --border rounded \
312+ --border-foreground 42 \
313+ --padding "1 2" \
314+ --bold \
315+ "✔ Installation Complete!
274316
317+All selected packages were installed successfully.
275318 You may now reboot the system for all the changes to apply."
319+ ;;
320+ partial)
321+ gum style \
322+ --border rounded \
323+ --border-foreground 220 \
324+ --padding "1 2" \
325+ --bold \
326+ "⚠ Setup Finished (Partial)
327+
328+Some steps were skipped by user choice.
329+Your system was NOT fully configured."
330+ ;;
331+ failed)
332+ gum style \
333+ --border rounded \
334+ --border-foreground 196 \
335+ --padding "1 2" \
336+ --bold \
337+ "❌ Installation Failed
338+
339+One or more steps did not complete successfully.
340+Check the logs above."
341+ ;;
342+ *)
343+ gum style --bold "Finished."
344+ ;;
345+esac