Krolyxon
Commit ea8f173

Branches

Refs →

aurorainstall.sh

354 lines · 8.3 KB · Bourne Again Shell (bash)

1#!/usr/bin/env bash
2
3trap 'log WARN "Interrupted by user"; exit 130' INT
4
5INSTALL_STATUS="none" # none | partial | complete | failed
6AUTO_YES=0
7
8#######################
9## Arguement Parsing ##
10#######################
11for arg in "$@"; do
12 case "$arg" in
13 --yes|--ci|--non-interactive)
14 AUTO_YES=1
15 ;;
16 esac
17done
18
19log() {
20 local level="$1"
21 shift
22
23 local color reset='\033[0m'
24 case "$level" in
25 INFO) color='\033[0;34m' ;; # Blue
26 WARN) color='\033[0;33m' ;; # Yellow
27 ERROR) color='\033[0;31m' ;; # Red
28 SUCCESS) color='\033[0;32m' ;; # Green
29 *) color='\033[0m' ;;
30 esac
31
32 printf '%b[%s] [%s]%b %s\n' \
33 "$color" "$(date '+%H:%M:%S')" "$level" "$reset" "$*" >&2
34}
35
36
37## Prevent user from running this script as root
38if [[ "$EUID" -eq 0 ]]; then
39 log ERROR "This script must NOT be run as root."
40 log INFO "If you need elevated privileges, the script will ask for sudo when required."
41 exit 1
42fi
43
44
45check_install() {
46 if ! command -v $1 >/dev/null 2>&1; then
47 echo "$1 is required. Install it first."
48 exit 1
49 fi
50}
51
52
53choose_packages() {
54 local -n arr=$1
55 gum choose --no-limit \
56 --selected "$(IFS=,; echo "${arr[*]}")" \
57 "${arr[@]}"
58}
59
60prompt_style() {
61 gum style \
62 --border rounded \
63 --padding "0 1" \
64 "$1"
65}
66
67gum_warn(){
68 gum style --bold --foreground 196 "⚠ $1"
69}
70
71gum_to_array() {
72 local -n arr="$1"
73 mapfile -t arr
74 local cleaned=()
75 for item in "${arr[@]}"; do
76 [[ -n "$item" ]] && cleaned+=("$item")
77 done
78 arr=("${cleaned[@]}")
79}
80
81confirm() {
82 local msg="$1"
83 if ((AUTO_YES)); then
84 log INFO "[auto] $msg → yes"
85 return 0
86 fi
87 gum confirm --default=false "$msg"
88}
89
90#################
91## GATEKEEPING ##
92#################
93
94## Add checks for prerequisites
95check_install git
96check_install gum
97check_install stow
98
99currentDir="$(dirname "$(readlink -f "$0")")"
100cd "$currentDir"
101
102
103DISCLAIMER=$(gum style \
104 --border double \
105 --border-foreground 196 \
106 --padding "1 2" \
107 --bold \
108"⚠️ DISCLAIMER
109
110This script is provided AS IS, WITHOUT ANY WARRANTY.
111There is NO guarantee that it will work on your system.
112
113It may:
114• Modify system files
115• Overwrite or DELETE existing configuration
116• Potentially break your setup
117
118You are STRONGLY ADVISED to back up:
119• ~/.config
120• ~/.local
121• /etc (if modified)
122
123Proceed at your OWN RISK."
124)
125
126confirm "$DISCLAIMER
127
128Do you understand the risks and want to continue?" || exit 1
129
130
131###########
132## UTILS ##
133###########
134source "$currentDir/packages/pkg_utils.sh"
135prompt_style "Important utilities (Most likely go with defaults)"
136if ((AUTO_YES)); then
137 DEV_PKGS=("${pkg_utils[@]}")
138else
139 gum_to_array UTILITY_PKGS < <(choose_packages pkg_utils)
140fi
141
142
143###############
144## DEV TOOLS ##
145###############
146source "$currentDir/packages/pkg_dev_tools.sh"
147prompt_style "Select Development Tools"
148if ((AUTO_YES)); then
149 DEV_PKGS=("${pkg_dev_tools[@]}")
150else
151 gum_to_array DEV_PKGS < <(choose_packages pkg_dev_tools)
152fi
153
154
155
156#######################
157## OPTIONAL PACKAGES ##
158#######################
159source "$currentDir/packages/pkg_optional.sh"
160prompt_style "Select Optional Desktop Packages"
161if ((AUTO_YES)); then
162 OPTIONAL_PKGS=("${pkg_optional[@]}")
163else
164 gum_to_array OPTIONAL_PKGS < <(choose_packages pkg_optional)
165fi
166
167
168
169#################
170## GPU DRIVERS ##
171#################
172source "$currentDir/packages/pkg_gpu.sh"
173prompt_style "Select GPU drivers"
174if ((AUTO_YES)); then
175 GPU_PKGS=("${pkg_gpu[@]}")
176else
177 gum_to_array GPU_PKGS < <(choose_packages pkg_gpu)
178fi
179
180
181##################
182## AUR PACKAGES ##
183##################
184source "$currentDir/packages/pkg_aur.sh"
185prompt_style "Select AUR packages"
186
187if ((AUTO_YES)); then
188 AUR_PKGS=("${pkg_aur[@]}")
189else
190 gum_to_array AUR_PKGS < <(choose_packages pkg_aur)
191fi
192
193
194
195##########################
196## Configure Everything ##
197##########################
198WARNING=$(gum style \
199 --border double \
200 --border-foreground 196 \
201 --padding "1 2" \
202 --bold \
203 "⚠️ This will DELETE any conflicting files and replace them with symlinks from this repo.
204Make sure you have already backed up all your existing config files (~/.config)")
205
206if confirm "$WARNING
207
208Proceed with system configuration (stow, shell)?"; then
209 ###################
210 ## Stow dotfiles ##
211 ###################
212 log INFO "Detecting conflicts..."
213 conflicts=$(stow . --no-folding -nv 2>&1 | \
214 sed -n 's/.*existing target \(.*\) since neither.*/\1/p')
215
216 if [[ -z "$conflicts" ]]; then
217 log INFO "No conflicts. Running stow normally..."
218 stow . --no-folding \
219 && log SUCCESS "Dotfiles stowed successfully" \
220 || log ERROR "Stow failed"
221 else
222 log WARN "These paths conflict and will be removed:"
223 printf ' %s\n' $conflicts
224 read -rp "Proceed with deleting these files? (y/N): " ok
225 if [[ ! "$ok" =~ ^[Yy]$ ]]; then
226 log WARN "Aborted."
227 exit 1
228 fi
229
230 # Remove conflicts relative to $HOME
231 for path in $conflicts; do
232 [[ -n "$path" && "$path" != "/" ]] && rm -rf "$HOME/$path" && log INFO "Deleted $path"
233 done
234
235 log INFO "Running stow..."
236 stow . --no-folding \
237 && log INFO "Dotfiles stowed with overwrite." \
238 || log ERROR "Stow failed"
239 fi
240
241 #################################
242 ## Change default shell to zsh ##
243 #################################
244 log INFO "Changing the default shell to ZSH"
245 if [[ "$SHELL" != "$(command -v zsh)" ]]; then
246 chsh -s $(which zsh) \
247 && log SUCCESS "Default shell successfully set to zsh" \
248 || log ERROR "Default shell could not be set to zsh"
249 else
250 log INFO "Skipping: zsh is already the default shell"
251 fi
252else
253 log ERROR "Aborted stow, didn't configure or install anything"
254 exit 1
255fi
256
257
258
259source "$currentDir/packages/pkg_desktop.sh"
260ALL_PKGS=(
261 "${DEV_PKGS[@]}"
262 "${OPTIONAL_PKGS[@]}"
263 "${GPU_PKGS[@]}"
264 "${UTILITY_PKGS[@]}"
265 "${AUR_PKGS[@]}"
266 "${pkg_desktop[@]}"
267)
268
269########################
270## Install Everything ##
271########################
272if ((${#ALL_PKGS[@]})); then
273 if confirm "Install all the selected packages?"; then
274 log INFO "Installing selected packages..."
275
276 ## Installing paru if not installed already
277 if ! command -v paru >/dev/null 2>&1; then
278 log INFO "Installing Paru (AUR package manager)"
279 git clone https://aur.archlinux.org/paru.git
280 (cd paru && makepkg -sri)
281 rm -rf paru
282 fi
283
284 if paru -Syu --needed "${ALL_PKGS[@]}"; then
285 INSTALL_STATUS="complete"
286 else
287 INSTALL_STATUS="failed"
288 fi
289 else
290 log WARN "Package installation skipped by user"
291 INSTALL_STATUS="partial"
292 fi
293else
294 log WARN "No packages selected"
295 INSTALL_STATUS="partial"
296fi
297
298
299
300################
301## Setup Keyd ##
302################
303if command -v keyd >/dev/null 2>&1; then
304 if confirm "Configure and enable keyd? "; then
305 log INFO "Copying keyd configuration to /etc/keyd/default.conf"
306 sudo cp "$currentDir/system/etc/keyd/default.conf" /etc/keyd/
307 sudo systemctl enable --now keyd.service \
308 && log SUCCESS "Successfully enabled keyd.service" \
309 || log ERROR "Couldn't enable keyd.service"
310 fi
311fi
312
313
314####################
315## Final dialogue ##
316####################
317case "$INSTALL_STATUS" in
318 complete)
319 gum style \
320 --border rounded \
321 --border-foreground 42 \
322 --padding "1 2" \
323 --bold \
324 "✔ Installation Complete!
325
326All selected packages were installed successfully.
327You may now reboot the system for all the changes to apply."
328 ;;
329 partial)
330 gum style \
331 --border rounded \
332 --border-foreground 220 \
333 --padding "1 2" \
334 --bold \
335 "⚠ Setup Finished (Partial)
336
337Some steps were skipped by user choice.
338Your system was NOT fully configured."
339 ;;
340 failed)
341 gum style \
342 --border rounded \
343 --border-foreground 196 \
344 --padding "1 2" \
345 --bold \
346 "❌ Installation Failed
347
348One or more steps did not complete successfully.
349Check the logs above."
350 ;;
351 *)
352 gum style --bold "Finished."
353 ;;
354esac