Krolyxon
Commit 37a6873

Branches

Refs →

aurorainstall.sh

275 lines · 7.0 KB · Bourne Again Shell (bash)

1#!/bin/env bash
2
3log() {
4 local level="$1"
5 shift
6
7 local color reset='\033[0m'
8 case "$level" in
9 INFO) color='\033[0;34m' ;; # Blue
10 WARN) color='\033[0;33m' ;; # Yellow
11 ERROR) color='\033[0;31m' ;; # Red
12 SUCCESS) color='\033[0;32m' ;; # Green
13 *) color='\033[0m' ;;
14 esac
15
16 printf '%b[%s] [%s]%b %s\n' \
17 "$color" "$(date '+%H:%M:%S')" "$level" "$reset" "$*" >&2
18}
19
20
21## Prevent user from running this script as root
22if [[ "$EUID" -eq 0 ]]; then
23 log ERROR "This script must NOT be run as root."
24 log INFO "If you need elevated privileges, the script will ask for sudo when required."
25 exit 1
26fi
27
28
29## Check if gum is installed
30if ! command -v gum >/dev/null 2>&1; then
31 echo "gum is required. Install it first."
32 exit 1
33fi
34
35## Check if git is installed
36if ! command -v git >/dev/null 2>&1; then
37 echo "git is required. Install it first."
38 exit 1
39fi
40
41
42currentDir="$(dirname "$(readlink -f "$0")")"
43cd "$currentDir"
44
45
46choose_packages() {
47 local -n arr=$1
48 gum choose --no-limit \
49 --selected "$(IFS=,; echo "${arr[*]}")" \
50 "${arr[@]}"
51}
52
53prompt_style() {
54 gum style --border rounded \
55 --border double \
56 --padding "0 1" \
57 "$1"
58}
59
60gum_warn(){
61 gum style --bold --foreground 196 "⚠ $1"
62}
63
64gum_to_array() {
65 mapfile -t "$1"
66}
67
68#################
69## GATEKEEPING ##
70#################
71
72DISCLAIMER=$(gum style \
73 --border double \
74 --border-foreground 196 \
75 --padding "1 2" \
76 --bold \
77"⚠️ DISCLAIMER
78
79This script is provided AS IS, WITHOUT ANY WARRANTY.
80There is NO guarantee that it will work on your system.
81
82It may:
83• Modify system files
84• Overwrite or DELETE existing configuration
85• Potentially break your setup
86
87You are STRONGLY ADVISED to back up:
88• ~/.config
89• ~/.local
90• /etc (if modified)
91
92Proceed at your OWN RISK."
93)
94
95gum confirm --default=false "$DISCLAIMER
96
97Do you understand the risks and want to continue?" || exit 1
98
99
100###########
101## UTILS ##
102###########
103source "$currentDir/packages/pkg_utils.sh"
104prompt_style "Important utilities (Most likely go with defaults)"
105gum_to_array UTILITY_PKGS < <(choose_packages pkg_utils)
106
107
108###############
109## DEV TOOLS ##
110###############
111source "$currentDir/packages/pkg_dev_tools.sh"
112prompt_style "Select Development Tools"
113gum_to_array DEV_PKGS < <(choose_packages pkg_dev_tools)
114
115
116#######################
117## OPTIONAL PACKAGES ##
118#######################
119source "$currentDir/packages/pkg_optional.sh"
120prompt_style "Select Optional Desktop Packages"
121gum_to_array OPTIONAL_PKGS < <(choose_packages pkg_optional)
122
123
124#################
125## GPU DRIVERS ##
126#################
127source "$currentDir/packages/pkg_gpu.sh"
128prompt_style "Select GPU drivers"
129gum_to_array GPU_PKGS < <(choose_packages pkg_gpu)
130
131##########################
132## Configure Everything ##
133##########################
134WARNING=$(gum style \
135 --border double \
136 --border-foreground 196 \
137 --padding "1 2" \
138 --bold \
139 "⚠️ This will DELETE any conflicting files and replace them with symlinks from this repo.
140Make sure you have already backed up all your existing config files (~/.config)")
141
142if gum confirm --default=false "$WARNING
143
144Proceed with system configuration (stow, nvim, shell, keyd)?"; then
145 ###################
146 ## Stow dotfiles ##
147 ###################
148 log INFO "Detecting conflicts..."
149 conflicts=$(stow . --no-folding -nv 2>&1 | \
150 sed -n 's/.*existing target \(.*\) since neither.*/\1/p')
151
152 if [[ -z "$conflicts" ]]; then
153 log INFO "No conflicts. Running stow normally..."
154 stow . --no-folding \
155 && log SUCCESS "Dotfiles stowed successfully" \
156 || log ERROR "Stow failed"
157 else
158 log WARN "These paths conflict and will be removed:"
159 printf ' %s\n' $conflicts
160 read -rp "Proceed with deleting these files? (y/N): " ok
161 if [[ ! "$ok" =~ ^[Yy]$ ]]; then
162 echo "Aborted."
163 fi
164
165 # Remove conflicts relative to $HOME
166 for path in $conflicts; do
167 rm -rf "$HOME/$path" && log INFO "Removed $HOME/$path"
168 done
169
170 log INFO "Running stow..."
171 stow . --no-folding \
172 && log INFO "✅ Dotfiles stowed with overwrite." \
173 || log ERROR "Stow failed"
174 fi
175
176 ###########################
177 ## Setup neovim dotfiles ##
178 ###########################
179 log INFO "Setting up neovim configuration"
180 log INFO "Taking backup of neovim config (if already exists)"
181 mv ~/.config/nvim{,.bak}
182 mv ~/.local/share/nvim{,.bak}
183 mv ~/.local/state/nvim{,.bak}
184 mv ~/.cache/nvim{,.bak}
185 git clone --depth=1 https://github.com/krolyxon/nvim.git ~/.config/nvim
186
187 #################################
188 ## Change default shell to zsh ##
189 #################################
190 log INFO "Changing the default shell to ZSH"
191 if [[ "$SHELL" != "$(which zsh)" ]]; then
192 chsh -s $(which zsh) \
193 && log SUCCESS "Default shell successfully set to zsh" \
194 || log ERROR "Default shell could not be set to zsh"
195 else
196 log INFO "Skipping: zsh is already the default shell"
197 fi
198else
199 log WARN "Aborted configuration, didn't configure anything"
200 exit 1
201fi
202
203##################
204## AUR PACKAGES ##
205##################
206source "$currentDir/packages/pkg_aur.sh"
207prompt_style "Select AUR packages"
208gum_to_array AUR_PKGS < <(choose_packages pkg_aur)
209if [[ ${#AUR_PKGS[@]} -eq 0 ]]; then
210 log WARN "No AUR packages selected"
211else
212 if ! command -v paru >/dev/null 2>&1; then
213 log INFO "Installing Paru (AUR package manager)"
214 git clone https://aur.archlinux.org/paru.git
215 cd paru
216 makepkg -sri
217 cd ..
218 rm -rf paru
219 else
220 log INFO "Paru already in PATH, Skipping...."
221 fi
222
223 if [[ ${#AUR_PKGS[@]} -eq 0 ]]; then
224 log WARN "No AUR packages selected, Skipping...."
225 else
226 paru -S --needed "${AUR_PKGS[@]}"
227 fi
228fi
229
230
231############################
232## Setup Keyd ##
233############################
234if command -v keyd >/dev/null 2>&1; then
235 if gum confirm --default=false "Configure and enable keyd? "; then
236 log INFO "Copying keyd configuration to /etc/keyd/default.conf"
237 sudo cp "$currentDir/system/etc/keyd/default.conf" /etc/keyd/
238 sudo systemctl enable --now keyd.service \
239 && log SUCCESS "Successfully enabled keyd.service" \
240 || log ERROR "Couldn't enable keyd.service"
241 fi
242fi
243
244########################
245## Install Everything ##
246########################
247source "$currentDir/packages/pkg_desktop.sh"
248ALL_PKGS=(
249 "${DEV_PKGS[@]}"
250 "${OPTIONAL_PKGS[@]}"
251 "${GPU_PKGS[@]}"
252 "${UTILITY_PKGS[@]}"
253 "${pkg_desktop[@]}"
254)
255
256if [[ ${#ALL_PKGS[@]} -eq 0 ]]; then
257 log WARN "No packages selected."
258else
259 if gum confirm --default=false "Install all the selected packages?"; then
260 log INFO "Installing selected packages..."
261 sudo pacman -Sy --needed "${ALL_PKGS[@]}"
262 fi
263fi
264
265
266gum style \
267 --border rounded \
268 --padding "1 2" \
269 --bold \
270 --foreground 42 \
271"🎉 Installation Complete!
272
273Your system has been successfully configured.
274
275You may now reboot the system for all the changes to apply."