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