Krolyxon
Commit cdd7d03

Branches

Refs →

aurorainstall.sh

350 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
42check_install() {
43 if ! command -v $1 >/dev/null 2>&1; then
44 echo "$1 is required. Install it first."
45 exit 1
46 fi
47}
48
49## Add checks for prerequisites
50check_install git
51check_install gum
52check_install stow
53
54currentDir="$(dirname "$(readlink -f "$0")")"
55cd "$currentDir"
56
57
58choose_packages() {
59 local -n arr=$1
60 gum choose --no-limit \
61 --selected "$(IFS=,; echo "${arr[*]}")" \
62 "${arr[@]}"
63}
64
65prompt_style() {
66 gum style \
67 --border rounded \
68 --padding "0 1" \
69 "$1"
70}
71
72gum_warn(){
73 gum style --bold --foreground 196 "⚠ $1"
74}
75
76gum_to_array() {
77 local -n arr="$1"
78 mapfile -t arr
79 local cleaned=()
80 for item in "${arr[@]}"; do
81 [[ -n "$item" ]] && cleaned+=("$item")
82 done
83 arr=("${cleaned[@]}")
84}
85
86confirm() {
87 local msg="$1"
88 if ((AUTO_YES)); then
89 log INFO "[auto] $msg → yes"
90 return 0
91 fi
92 gum confirm --default=false "$msg"
93}
94
95#################
96## GATEKEEPING ##
97#################
98
99DISCLAIMER=$(gum style \
100 --border double \
101 --border-foreground 196 \
102 --padding "1 2" \
103 --bold \
104"⚠️ DISCLAIMER
105
106This script is provided AS IS, WITHOUT ANY WARRANTY.
107There is NO guarantee that it will work on your system.
108
109It may:
110• Modify system files
111• Overwrite or DELETE existing configuration
112• Potentially break your setup
113
114You are STRONGLY ADVISED to back up:
115• ~/.config
116• ~/.local
117• /etc (if modified)
118
119Proceed at your OWN RISK."
120)
121
122confirm "$DISCLAIMER
123
124Do you understand the risks and want to continue?" || exit 1
125
126
127###########
128## UTILS ##
129###########
130source "$currentDir/packages/pkg_utils.sh"
131prompt_style "Important utilities (Most likely go with defaults)"
132if ((AUTO_YES)); then
133 DEV_PKGS=("${pkg_utils[@]}")
134else
135 gum_to_array UTILITY_PKGS < <(choose_packages pkg_utils)
136fi
137
138
139###############
140## DEV TOOLS ##
141###############
142source "$currentDir/packages/pkg_dev_tools.sh"
143prompt_style "Select Development Tools"
144if ((AUTO_YES)); then
145 DEV_PKGS=("${pkg_dev_tools[@]}")
146else
147 gum_to_array DEV_PKGS < <(choose_packages pkg_dev_tools)
148fi
149
150
151
152#######################
153## OPTIONAL PACKAGES ##
154#######################
155source "$currentDir/packages/pkg_optional.sh"
156prompt_style "Select Optional Desktop Packages"
157if ((AUTO_YES)); then
158 OPTIONAL_PKGS=("${pkg_optional[@]}")
159else
160 gum_to_array OPTIONAL_PKGS < <(choose_packages pkg_optional)
161fi
162
163
164
165#################
166## GPU DRIVERS ##
167#################
168source "$currentDir/packages/pkg_gpu.sh"
169prompt_style "Select GPU drivers"
170if ((AUTO_YES)); then
171 GPU_PKGS=("${pkg_gpu[@]}")
172else
173 gum_to_array GPU_PKGS < <(choose_packages pkg_gpu)
174fi
175
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
255source "$currentDir/packages/pkg_desktop.sh"
256ALL_PKGS=(
257 "${DEV_PKGS[@]}"
258 "${OPTIONAL_PKGS[@]}"
259 "${GPU_PKGS[@]}"
260 "${UTILITY_PKGS[@]}"
261 "${AUR_PKGS[@]}"
262 "${pkg_desktop[@]}"
263)
264
265########################
266## Install Everything ##
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################
297## Setup Keyd ##
298################
299if command -v keyd >/dev/null 2>&1; then
300 if confirm "Configure and enable keyd? "; then
301 log INFO "Copying keyd configuration to /etc/keyd/default.conf"
302 sudo cp "$currentDir/system/etc/keyd/default.conf" /etc/keyd/
303 sudo systemctl enable --now keyd.service \
304 && log SUCCESS "Successfully enabled keyd.service" \
305 || log ERROR "Couldn't enable keyd.service"
306 fi
307fi
308
309
310####################
311## Final dialogue ##
312####################
313case "$INSTALL_STATUS" in
314 complete)
315 gum style \
316 --border rounded \
317 --border-foreground 42 \
318 --padding "1 2" \
319 --bold \
320 "✔ Installation Complete!
321
322All selected packages were installed successfully.
323You may now reboot the system for all the changes to apply."
324 ;;
325 partial)
326 gum style \
327 --border rounded \
328 --border-foreground 220 \
329 --padding "1 2" \
330 --bold \
331 "⚠ Setup Finished (Partial)
332
333Some steps were skipped by user choice.
334Your system was NOT fully configured."
335 ;;
336 failed)
337 gum style \
338 --border rounded \
339 --border-foreground 196 \
340 --padding "1 2" \
341 --bold \
342 "❌ Installation Failed
343
344One or more steps did not complete successfully.
345Check the logs above."
346 ;;
347 *)
348 gum style --bold "Finished."
349 ;;
350esac