Krolyxon
Commit 5e5930f

Branches

Refs →

aurorainstall.sh

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