Krolyxon
Commit 1658e95

Branches

Refs →

aurorainstall.sh

345 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
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##########################
179## Configure Everything ##
180##########################
181WARNING=$(gum style \
182 --border double \
183 --border-foreground 196 \
184 --padding "1 2" \
185 --bold \
186 "⚠️ This will DELETE any conflicting files and replace them with symlinks from this repo.
187Make sure you have already backed up all your existing config files (~/.config)")
188
189if confirm "$WARNING
190
191Proceed with system configuration (stow, shell)?"; then
192 ###################
193 ## Stow dotfiles ##
194 ###################
195 log INFO "Detecting conflicts..."
196 conflicts=$(stow . --no-folding -nv 2>&1 | \
197 sed -n 's/.*existing target \(.*\) since neither.*/\1/p')
198
199 if [[ -z "$conflicts" ]]; then
200 log INFO "No conflicts. Running stow normally..."
201 stow . --no-folding \
202 && log SUCCESS "Dotfiles stowed successfully" \
203 || log ERROR "Stow failed"
204 else
205 log WARN "These paths conflict and will be removed:"
206 printf ' %s\n' $conflicts
207 read -rp "Proceed with deleting these files? (y/N): " ok
208 if [[ ! "$ok" =~ ^[Yy]$ ]]; then
209 log WARN "Aborted."
210 exit 1
211 fi
212
213 # Remove conflicts relative to $HOME
214 for path in $conflicts; do
215 [[ -n "$path" && "$path" != "/" ]] && rm -rf "$HOME/$path" && log INFO "Deleted $path"
216 done
217
218 log INFO "Running stow..."
219 stow . --no-folding \
220 && log INFO "✅ Dotfiles stowed with overwrite." \
221 || log ERROR "Stow failed"
222 fi
223
224 #################################
225 ## Change default shell to zsh ##
226 #################################
227 log INFO "Changing the default shell to ZSH"
228 if [[ "$SHELL" != "$(command -v zsh)" ]]; then
229 chsh -s $(which zsh) \
230 && log SUCCESS "Default shell successfully set to zsh" \
231 || log ERROR "Default shell could not be set to zsh"
232 else
233 log INFO "Skipping: zsh is already the default shell"
234 fi
235else
236 log WARN "Aborted configuration, didn't configure anything"
237 exit 1
238fi
239
240##################
241## AUR PACKAGES ##
242##################
243source "$currentDir/packages/pkg_aur.sh"
244prompt_style "Select AUR packages"
245
246if ((AUTO_YES)); then
247 AUR_PKGS=("${pkg_aur[@]}")
248else
249 gum_to_array AUR_PKGS < <(choose_packages pkg_aur)
250fi
251
252if ((${#AUR_PKGS[@]})); then
253 if ! command -v paru >/dev/null 2>&1; then
254 log INFO "Installing Paru (AUR package manager)"
255 git clone https://aur.archlinux.org/paru.git
256 (cd paru && makepkg -sri)
257 rm -rf paru
258 fi
259 paru -S --needed "${AUR_PKGS[@]}"
260else
261 log WARN "No AUR packages selected"
262fi
263
264
265############################
266## Setup Keyd ##
267############################
268if command -v keyd >/dev/null 2>&1; then
269 if confirm "Configure and enable keyd? "; then
270 log INFO "Copying keyd configuration to /etc/keyd/default.conf"
271 sudo cp "$currentDir/system/etc/keyd/default.conf" /etc/keyd/
272 sudo systemctl enable --now keyd.service \
273 && log SUCCESS "Successfully enabled keyd.service" \
274 || log ERROR "Couldn't enable keyd.service"
275 fi
276fi
277
278########################
279## Install Everything ##
280########################
281source "$currentDir/packages/pkg_desktop.sh"
282ALL_PKGS=(
283 "${DEV_PKGS[@]}"
284 "${OPTIONAL_PKGS[@]}"
285 "${GPU_PKGS[@]}"
286 "${UTILITY_PKGS[@]}"
287 "${pkg_desktop[@]}"
288)
289
290if ((${#ALL_PKGS[@]})); then
291 if confirm "Install all the selected packages?"; then
292 log INFO "Installing selected packages..."
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"
301 fi
302else
303 log WARN "No packages selected"
304 INSTALL_STATUS="partial"
305fi
306
307
308case "$INSTALL_STATUS" in
309 complete)
310 gum style \
311 --border rounded \
312 --border-foreground 42 \
313 --padding "1 2" \
314 --bold \
315 "✔ Installation Complete!
316
317All selected packages were installed successfully.
318You 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
328Some steps were skipped by user choice.
329Your 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
339One or more steps did not complete successfully.
340Check the logs above."
341 ;;
342 *)
343 gum style --bold "Finished."
344 ;;
345esac