Krolyxon
Commit 4ddf45c

Branches

Refs →

aurorainstall.sh

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