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