| 1 | # shellcheck shell=bash |
| 2 | # Desktop part: packages, dotfiles (stow), zsh, services. Sourced by install.sh; |
| 3 | # runs as the user, asks for sudo when it needs it. |
| 4 | # AURORA_CHROOT=1: run by the full install inside the new system's chroot (unattended, |
| 5 | # nothing is running there yet: no --now, no user bus). |
| 6 | |
| 7 | IN_CHROOT="${AURORA_CHROOT:-0}" |
| 8 | |
| 9 | ################# |
| 10 | ## GATEKEEPING ## |
| 11 | ################# |
| 12 | |
| 13 | ## Prevent user from running this script as root |
| 14 | if [[ "$EUID" -eq 0 ]]; then |
| 15 | log ERROR "This script must NOT be run as root." |
| 16 | log INFO "If you need elevated privileges, the script will ask for sudo when required." |
| 17 | exit 1 |
| 18 | fi |
| 19 | |
| 20 | if [[ ! -f /etc/arch-release ]]; then |
| 21 | log ERROR "This is not Arch Linux. These dotfiles and this script are for Arch only." |
| 22 | exit 1 |
| 23 | fi |
| 24 | |
| 25 | ## Does this look like a system that is already set up? |
| 26 | ## (configs this repo doesn't provide, or another desktop's config) |
| 27 | check_fresh_system() { |
| 28 | local foreign=() desktops=() entry |
| 29 | for entry in "$HOME"/.config/*; do |
| 30 | [[ -e "$entry" ]] || continue |
| 31 | entry="$(basename "$entry")" |
| 32 | [[ -e "$currentDir/.config/$entry" ]] || foreign+=("$entry") |
| 33 | done |
| 34 | for entry in i3 sway niri river awesome bspwm openbox qtile xfce4 \ |
| 35 | kdeglobals plasma-org.kde.plasma.desktop-appletsrc gnome-session; do |
| 36 | [[ -e "$HOME/.config/$entry" ]] && desktops+=("$entry") |
| 37 | done |
| 38 | |
| 39 | ((${#foreign[@]} <= 10 && ${#desktops[@]} == 0)) && return 0 |
| 40 | |
| 41 | printf '\033[1;31m' |
| 42 | echo "==================================================================" |
| 43 | echo " This does NOT look like a fresh Arch install." |
| 44 | echo |
| 45 | ((${#desktops[@]})) && echo " Found another desktop's config: ${desktops[*]}" |
| 46 | ((${#foreign[@]} > 10)) && echo " Found ${#foreign[@]} entries in ~/.config that this repo doesn't provide." |
| 47 | echo |
| 48 | echo " This installer is meant for a freshly installed, unconfigured" |
| 49 | echo " system. On a system you already use it WILL change things you" |
| 50 | echo " care about: your configs get moved aside, your shell changes, and" |
| 51 | echo " lots of packages get installed." |
| 52 | echo "==================================================================" |
| 53 | printf '\033[0m' |
| 54 | local answer |
| 55 | read -rp "Type 'I understand' to continue anyway: " answer |
| 56 | [[ "$answer" == "I understand" ]] || { log WARN "Aborted."; exit 1; } |
| 57 | } |
| 58 | ((IN_CHROOT)) || check_fresh_system |
| 59 | |
| 60 | |
| 61 | # Enable a unit (--user: a user unit). In the chroot nothing runs yet: |
| 62 | # no --now, and user units are enabled offline (--root writes the links into $HOME). |
| 63 | enable_unit() { |
| 64 | if [[ "$1" == --user ]]; then |
| 65 | shift |
| 66 | if ((IN_CHROOT)); then |
| 67 | systemctl --user --root=/ enable "$@" |
| 68 | else |
| 69 | systemctl --user daemon-reload && systemctl --user enable "$@" |
| 70 | fi |
| 71 | elif ((IN_CHROOT)); then |
| 72 | sudo systemctl enable "$@" |
| 73 | else |
| 74 | sudo systemctl enable --now "$@" |
| 75 | fi |
| 76 | } |
| 77 | |
| 78 | install_prerequisites() { |
| 79 | sudo pacman -S --needed --noconfirm stow gum git zsh |
| 80 | } |
| 81 | |
| 82 | ## Installs prerequisites |
| 83 | log INFO "Installing prerequisites: " |
| 84 | install_prerequisites |
| 85 | |
| 86 | |
| 87 | DISCLAIMER=$(gum style \ |
| 88 | --border double \ |
| 89 | --border-foreground 196 \ |
| 90 | --padding "1 2" \ |
| 91 | --bold \ |
| 92 | "⚠️ DISCLAIMER |
| 93 | |
| 94 | These are MY personal dotfiles, built for MY machine |
| 95 | (Lenovo Legion, Intel + NVIDIA hybrid, linux-zen) and the way I work. |
| 96 | They are NOT general purpose. They're public as a reference, |
| 97 | or for people who want exactly the same setup. |
| 98 | |
| 99 | Only run this on a FRESHLY INSTALLED, UNCONFIGURED Arch system. |
| 100 | |
| 101 | This script is provided AS IS, WITHOUT ANY WARRANTY. It will: |
| 102 | • Install a lot of packages (including NVIDIA drivers if selected) |
| 103 | • Move conflicting files in your \$HOME to ~/.aurora-backup/ |
| 104 | • Change your login shell to zsh |
| 105 | • Optionally write /etc/keyd and enable keyd |
| 106 | • Optionally write /etc/pam.d/{login,passwd} (GNOME keyring unlock) |
| 107 | • Enable the aurora-shell.service user unit |
| 108 | |
| 109 | Proceed at your OWN RISK." |
| 110 | ) |
| 111 | |
| 112 | # The full install showed its own summary already |
| 113 | if ! ((IN_CHROOT)); then |
| 114 | confirm "$DISCLAIMER |
| 115 | |
| 116 | Do you understand the risks and want to continue?" || exit 1 |
| 117 | fi |
| 118 | |
| 119 | |
| 120 | ####################### |
| 121 | ## Package selection ## |
| 122 | ####################### |
| 123 | pick_packages |
| 124 | |
| 125 | |
| 126 | ########################## |
| 127 | ## Configure Everything ## |
| 128 | ########################## |
| 129 | WARNING=$(gum style \ |
| 130 | --border double \ |
| 131 | --border-foreground 196 \ |
| 132 | --padding "1 2" \ |
| 133 | --bold \ |
| 134 | "⚠️ Files in your \$HOME that conflict with this repo will be MOVED to |
| 135 | ~/.aurora-backup/<date>/ and replaced with symlinks from this repo.") |
| 136 | |
| 137 | if confirm "$WARNING |
| 138 | |
| 139 | Proceed with system configuration (stow, shell)?"; then |
| 140 | ################### |
| 141 | ## Stow dotfiles ## |
| 142 | ################### |
| 143 | log INFO "Detecting conflicts..." |
| 144 | mapfile -t conflicts < <(stow -t "$HOME" . --no-folding -nv 2>&1 | \ |
| 145 | sed -n 's/.*existing target \(.*\) since neither.*/\1/p') |
| 146 | |
| 147 | if ((${#conflicts[@]} == 0)); then |
| 148 | log INFO "No conflicts. Running stow normally..." |
| 149 | else |
| 150 | log WARN "These paths conflict and will be moved to a backup:" |
| 151 | printf ' %s\n' "${conflicts[@]}" |
| 152 | if ! confirm "Move these files to ~/.aurora-backup/ ?"; then |
| 153 | log WARN "Aborted." |
| 154 | exit 1 |
| 155 | fi |
| 156 | |
| 157 | # Move conflicts (relative to $HOME) into the backup dir, keeping their paths |
| 158 | BACKUP_DIR="$HOME/.aurora-backup/$(date '+%Y%m%d-%H%M%S')" |
| 159 | for path in "${conflicts[@]}"; do |
| 160 | [[ -n "$path" && "$path" != "/" ]] || continue |
| 161 | mkdir -p "$BACKUP_DIR/$(dirname "$path")" |
| 162 | mv "$HOME/$path" "$BACKUP_DIR/$path" && log INFO "Backed up $path" |
| 163 | done |
| 164 | log INFO "Backups are in $BACKUP_DIR" |
| 165 | fi |
| 166 | |
| 167 | stow -t "$HOME" . --no-folding \ |
| 168 | && log SUCCESS "Dotfiles stowed successfully" \ |
| 169 | || log ERROR "Stow failed" |
| 170 | |
| 171 | # Hyprland's Lua plugins are git checkouts, not in this repo (hyprland.lua also fetches them when missing) |
| 172 | "$currentDir/.local/bin/hypr/hypr_update_plugins.sh" \ |
| 173 | && log SUCCESS "Hyprland plugins installed" \ |
| 174 | || log WARN "Couldn't fetch the Hyprland plugins, Hyprland fetches them at its first start" |
| 175 | |
| 176 | ################################# |
| 177 | ## Change default shell to zsh ## |
| 178 | ################################# |
| 179 | log INFO "Changing the default shell to ZSH" |
| 180 | if [[ "$(getent passwd "$USER" | cut -d: -f7)" != "$(command -v zsh)" ]]; then |
| 181 | chsh -s "$(command -v zsh)" \ |
| 182 | && log SUCCESS "Default shell successfully set to zsh" \ |
| 183 | || log ERROR "Default shell could not be set to zsh" |
| 184 | else |
| 185 | log INFO "Skipping: zsh is already the default shell" |
| 186 | fi |
| 187 | else |
| 188 | log ERROR "Aborted stow, didn't configure or install anything" |
| 189 | exit 1 |
| 190 | fi |
| 191 | |
| 192 | |
| 193 | mapfile -t DESKTOP_PKGS < <(read_list desktop) |
| 194 | ALL_PKGS=( |
| 195 | "${DESKTOP_PKGS[@]}" |
| 196 | "${SELECTED_PKGS[@]}" |
| 197 | ) |
| 198 | |
| 199 | ######################## |
| 200 | ## Install Everything ## |
| 201 | ######################## |
| 202 | if ((${#ALL_PKGS[@]})); then |
| 203 | if confirm "Install all the selected packages?"; then |
| 204 | log INFO "Installing selected packages..." |
| 205 | |
| 206 | # --yes: no prompts at all (makepkg, paru's review and provider questions take their defaults) |
| 207 | noconfirm=() |
| 208 | ((AUTO_YES)) && noconfirm=(--noconfirm) |
| 209 | |
| 210 | ## Installing paru if not installed already |
| 211 | if ! command -v paru >/dev/null 2>&1; then |
| 212 | log INFO "Installing Paru (AUR package manager)" |
| 213 | sudo pacman -S --needed --noconfirm base-devel |
| 214 | build="$(mktemp -d)" |
| 215 | git clone https://aur.archlinux.org/paru.git "$build/paru" \ |
| 216 | && (cd "$build/paru" && makepkg -sri "${noconfirm[@]}") |
| 217 | rm -rf "$build" |
| 218 | fi |
| 219 | |
| 220 | ((AUTO_YES)) && noconfirm+=(--skipreview) |
| 221 | if paru -Syu --needed "${noconfirm[@]}" "${ALL_PKGS[@]}"; then |
| 222 | INSTALL_STATUS="complete" |
| 223 | else |
| 224 | INSTALL_STATUS="failed" |
| 225 | fi |
| 226 | else |
| 227 | log WARN "Package installation skipped by user" |
| 228 | INSTALL_STATUS="partial" |
| 229 | fi |
| 230 | else |
| 231 | log WARN "No packages selected" |
| 232 | INSTALL_STATUS="partial" |
| 233 | fi |
| 234 | |
| 235 | |
| 236 | |
| 237 | ################ |
| 238 | ## Setup Keyd ## |
| 239 | ################ |
| 240 | if command -v keyd >/dev/null 2>&1; then |
| 241 | if confirm "Configure and enable keyd? "; then |
| 242 | log INFO "Copying keyd configuration to /etc/keyd/default.conf" |
| 243 | sudo install -Dm644 "$currentDir/system/etc/keyd/default.conf" /etc/keyd/default.conf |
| 244 | enable_unit keyd.service \ |
| 245 | && log SUCCESS "Successfully enabled keyd.service" \ |
| 246 | || log ERROR "Couldn't enable keyd.service" |
| 247 | fi |
| 248 | fi |
| 249 | |
| 250 | |
| 251 | ############################ |
| 252 | ## GNOME keyring on login ## |
| 253 | ############################ |
| 254 | # pam_gnome_keyring unlocks the "login" keyring with the login password (tty login and hyprlock, |
| 255 | # whose PAM file includes login); passwd keeps the keyring password in sync. |
| 256 | if confirm "Unlock GNOME keyring at login (writes /etc/pam.d/login and passwd)?"; then |
| 257 | log INFO "Copying PAM files to /etc/pam.d" |
| 258 | sudo cp "$currentDir/system/etc/pam.d/login" "$currentDir/system/etc/pam.d/passwd" /etc/pam.d/ \ |
| 259 | && log SUCCESS "GNOME keyring unlocks at login" \ |
| 260 | || log ERROR "Couldn't write /etc/pam.d" |
| 261 | fi |
| 262 | |
| 263 | |
| 264 | ############## |
| 265 | ## Services ## |
| 266 | ############## |
| 267 | # What the desktop expects to be running (all optional packages: only if installed) |
| 268 | if confirm "Enable bluetooth, power-profiles-daemon and mpd-mpris (if installed)?"; then |
| 269 | for unit in bluetooth power-profiles-daemon; do |
| 270 | [[ -f "/usr/lib/systemd/system/$unit.service" ]] || continue |
| 271 | enable_unit "$unit.service" \ |
| 272 | && log SUCCESS "Enabled $unit.service" \ |
| 273 | || log ERROR "Couldn't enable $unit.service" |
| 274 | done |
| 275 | # media keys reach mpd through mpd-mpris (playerctl) |
| 276 | if [[ -f /usr/lib/systemd/user/mpd-mpris.service ]]; then |
| 277 | enable_unit --user mpd-mpris.service \ |
| 278 | && log SUCCESS "Enabled mpd-mpris.service" \ |
| 279 | || log ERROR "Couldn't enable mpd-mpris.service" |
| 280 | fi |
| 281 | fi |
| 282 | |
| 283 | |
| 284 | ######################### |
| 285 | ## Enable aurora shell ## |
| 286 | ######################### |
| 287 | # User unit, stowed to ~/.config/systemd/user. Hyprland starts it at login, |
| 288 | # enabling it also ties it to graphical-session.target. No --now: no session yet. |
| 289 | if [[ -f "$HOME/.config/systemd/user/aurora-shell.service" ]]; then |
| 290 | if confirm "Enable aurora-shell.service (the desktop shell)?"; then |
| 291 | enable_unit --user aurora-shell.service \ |
| 292 | && log SUCCESS "Successfully enabled aurora-shell.service" \ |
| 293 | || log ERROR "Couldn't enable aurora-shell.service (run 'systemctl --user enable aurora-shell' after logging in)" |
| 294 | fi |
| 295 | else |
| 296 | log WARN "aurora-shell.service is not stowed, skipping" |
| 297 | fi |
| 298 | |
| 299 | |
| 300 | #################### |
| 301 | ## Final dialogue ## |
| 302 | #################### |
| 303 | BACKUP_NOTE="" |
| 304 | [[ -n "$BACKUP_DIR" ]] && BACKUP_NOTE=" |
| 305 | |
| 306 | Your old conflicting files are in: |
| 307 | $BACKUP_DIR" |
| 308 | |
| 309 | case "$INSTALL_STATUS" in |
| 310 | complete) |
| 311 | gum style \ |
| 312 | --border rounded \ |
| 313 | --border-foreground 42 \ |
| 314 | --padding "1 2" \ |
| 315 | --bold \ |
| 316 | "✔ Installation Complete! |
| 317 | |
| 318 | All selected packages were installed successfully. |
| 319 | You may now reboot the system for all the changes to apply.$BACKUP_NOTE" |
| 320 | ;; |
| 321 | partial) |
| 322 | gum style \ |
| 323 | --border rounded \ |
| 324 | --border-foreground 220 \ |
| 325 | --padding "1 2" \ |
| 326 | --bold \ |
| 327 | "⚠ Setup Finished (Partial) |
| 328 | |
| 329 | Some steps were skipped by user choice. |
| 330 | Your system was NOT fully configured.$BACKUP_NOTE" |
| 331 | ;; |
| 332 | failed) |
| 333 | gum style \ |
| 334 | --border rounded \ |
| 335 | --border-foreground 196 \ |
| 336 | --padding "1 2" \ |
| 337 | --bold \ |
| 338 | "❌ Installation Failed |
| 339 | |
| 340 | One or more steps did not complete successfully. |
| 341 | Check the logs above.$BACKUP_NOTE" |
| 342 | ;; |
| 343 | *) |
| 344 | gum style --bold "Finished.$BACKUP_NOTE" |
| 345 | ;; |
| 346 | esac |
| 347 | |
| 348 | # the full install looks at this |
| 349 | [[ "$INSTALL_STATUS" != failed ]] |