Krolyxon
Commit e0977f3

Branches

Refs →

aurorainstalllib.sh

121 lines · 3.2 KB · Bourne Again Shell (bash)

1# shellcheck shell=bash
2# Shared helpers, sourced by install.sh.
3
4log() {
5 local level="$1"
6 shift
7
8 local color reset='\033[0m'
9 case "$level" in
10 INFO) color='\033[0;34m' ;; # Blue
11 WARN) color='\033[0;33m' ;; # Yellow
12 ERROR) color='\033[0;31m' ;; # Red
13 SUCCESS) color='\033[0;32m' ;; # Green
14 *) color='\033[0m' ;;
15 esac
16
17 printf '%b[%s] [%s]%b %s\n' \
18 "$color" "$(date '+%H:%M:%S')" "$level" "$reset" "$*" >&2
19}
20
21usage() {
22 # install.sh's header comment, up to the first line that isn't a comment
23 sed -n '3,/^[^#]/s/^# \{0,1\}//p' "$currentDir/install.sh"
24}
25
26###################
27## Package lists ##
28###################
29# packages/*.txt: one package per line, '#' comments.
30# A trailing '!' (e.g. "blender !") means: listed, but not pre-selected in the picker.
31
32# All packages in a list
33read_list() {
34 sed 's/#.*//' "$PKG_DIR/$1.txt" | awk 'NF { print $1 }'
35}
36
37# Packages of a list that are pre-selected in the picker
38preselected() {
39 sed 's/#.*//' "$PKG_DIR/$1.txt" | awk 'NF && $2 != "!" { print $1 }'
40}
41
42check_packages() {
43 local listed installed aur
44 listed=$(for f in "$PKG_DIR"/*.txt; do read_list "$(basename "$f" .txt)"; done | sort -u)
45 installed=$(pacman -Qqe | sort -u)
46 aur=$(pacman -Qqm | sort -u)
47
48 echo "Installed explicitly, but not in any packages/*.txt:"
49 comm -23 <(echo "$installed") <(echo "$listed") | while read -r p; do
50 if grep -qx "$p" <<< "$aur"; then echo " $p (aur)"; else echo " $p"; fi
51 done
52
53 echo
54 echo "Listed, but not installed:"
55 comm -13 <(pacman -Qq | sort -u) <(echo "$listed") | sed 's/^/ /'
56}
57
58choose_packages() {
59 local list="$1"
60 gum choose --no-limit \
61 --selected "$(preselected "$list" | paste -sd,)" \
62 $(read_list "$list")
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# Package pickers -> SELECTED_PKGS (desktop.txt is always installed, it has no picker).
96# --picks FILE (from the full install) replaces them.
97pick_packages() {
98 SELECTED_PKGS=()
99 if [[ -n "$PICKS" ]]; then
100 gum_to_array SELECTED_PKGS < "$PICKS"
101 return
102 fi
103
104 local list picked
105 for list in utils dev gpu optional aur; do
106 case "$list" in
107 utils) prompt_style "Important utilities (Most likely go with defaults)" ;;
108 dev) prompt_style "Select Development Tools" ;;
109 gpu) prompt_style "Select GPU drivers" ;;
110 optional) prompt_style "Select Optional Desktop Packages" ;;
111 aur) prompt_style "Select AUR packages" ;;
112 esac
113
114 if ((AUTO_YES)); then
115 mapfile -t picked < <(preselected "$list")
116 else
117 gum_to_array picked < <(choose_packages "$list")
118 fi
119 SELECTED_PKGS+=("${picked[@]}")
120 done
121}