Krolyxon
Commit 38e5a0b

Branches

Refs →

aurorainstall.sh

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