| 1 | #!/bin/env bash |
| 2 | |
| 3 | log() { |
| 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 |
| 22 | if [[ "$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 |
| 26 | fi |
| 27 | |
| 28 | |
| 29 | ## Check if gum is installed |
| 30 | if ! command -v gum >/dev/null 2>&1; then |
| 31 | echo "gum is required. Install it first." |
| 32 | exit 1 |
| 33 | fi |
| 34 | |
| 35 | ## Check if git is installed |
| 36 | if ! command -v git >/dev/null 2>&1; then |
| 37 | echo "git is required. Install it first." |
| 38 | exit 1 |
| 39 | fi |
| 40 | |
| 41 | |
| 42 | currentDir="$(dirname "$(readlink -f "$0")")" |
| 43 | cd "$currentDir" |
| 44 | |
| 45 | |
| 46 | choose_packages() { |
| 47 | local -n arr=$1 |
| 48 | gum choose --no-limit \ |
| 49 | --selected "$(IFS=,; echo "${arr[*]}")" \ |
| 50 | "${arr[@]}" |
| 51 | } |
| 52 | |
| 53 | prompt_style() { |
| 54 | gum style --border rounded \ |
| 55 | --border double \ |
| 56 | --padding "0 1" \ |
| 57 | "$1" |
| 58 | } |
| 59 | |
| 60 | gum_warn(){ |
| 61 | gum style --bold --foreground 196 "⚠ $1" |
| 62 | } |
| 63 | |
| 64 | gum_to_array() { |
| 65 | mapfile -t "$1" |
| 66 | } |
| 67 | |
| 68 | ################# |
| 69 | ## GATEKEEPING ## |
| 70 | ################# |
| 71 | |
| 72 | DISCLAIMER=$(gum style \ |
| 73 | --border double \ |
| 74 | --border-foreground 196 \ |
| 75 | --padding "1 2" \ |
| 76 | --bold \ |
| 77 | "⚠️ DISCLAIMER |
| 78 | |
| 79 | This script is provided AS IS, WITHOUT ANY WARRANTY. |
| 80 | There is NO guarantee that it will work on your system. |
| 81 | |
| 82 | It may: |
| 83 | • Modify system files |
| 84 | • Overwrite or DELETE existing configuration |
| 85 | • Potentially break your setup |
| 86 | |
| 87 | You are STRONGLY ADVISED to back up: |
| 88 | • ~/.config |
| 89 | • ~/.local |
| 90 | • /etc (if modified) |
| 91 | |
| 92 | Proceed at your OWN RISK." |
| 93 | ) |
| 94 | |
| 95 | gum confirm --default=false "$DISCLAIMER |
| 96 | |
| 97 | Do you understand the risks and want to continue?" || exit 1 |
| 98 | |
| 99 | |
| 100 | ########### |
| 101 | ## UTILS ## |
| 102 | ########### |
| 103 | source "$currentDir/packages/pkg_utils.sh" |
| 104 | prompt_style "Important utilities (Most likely go with defaults)" |
| 105 | gum_to_array UTILITY_PKGS < <(choose_packages pkg_utils) |
| 106 | |
| 107 | |
| 108 | ############### |
| 109 | ## DEV TOOLS ## |
| 110 | ############### |
| 111 | source "$currentDir/packages/pkg_dev_tools.sh" |
| 112 | prompt_style "Select Development Tools" |
| 113 | gum_to_array DEV_PKGS < <(choose_packages pkg_dev_tools) |
| 114 | |
| 115 | |
| 116 | ####################### |
| 117 | ## OPTIONAL PACKAGES ## |
| 118 | ####################### |
| 119 | source "$currentDir/packages/pkg_optional.sh" |
| 120 | prompt_style "Select Optional Desktop Packages" |
| 121 | gum_to_array OPTIONAL_PKGS < <(choose_packages pkg_optional) |
| 122 | |
| 123 | |
| 124 | ################# |
| 125 | ## GPU DRIVERS ## |
| 126 | ################# |
| 127 | source "$currentDir/packages/pkg_gpu.sh" |
| 128 | prompt_style "Select GPU drivers" |
| 129 | gum_to_array GPU_PKGS < <(choose_packages pkg_gpu) |
| 130 | |
| 131 | ########################## |
| 132 | ## Configure Everything ## |
| 133 | ########################## |
| 134 | WARNING=$(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. |
| 140 | Make sure you have already backed up all your existing config files (~/.config)") |
| 141 | |
| 142 | if gum confirm --default=false "$WARNING |
| 143 | |
| 144 | Proceed 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 |
| 198 | else |
| 199 | log WARN "Aborted configuration, didn't configure anything" |
| 200 | exit 1 |
| 201 | fi |
| 202 | |
| 203 | ################## |
| 204 | ## AUR PACKAGES ## |
| 205 | ################## |
| 206 | source "$currentDir/packages/pkg_aur.sh" |
| 207 | prompt_style "Select AUR packages" |
| 208 | gum_to_array AUR_PKGS < <(choose_packages pkg_aur) |
| 209 | if [[ ${#AUR_PKGS[@]} -eq 0 ]]; then |
| 210 | log WARN "No AUR packages selected" |
| 211 | else |
| 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 |
| 228 | fi |
| 229 | |
| 230 | |
| 231 | ############################ |
| 232 | ## Setup Keyd ## |
| 233 | ############################ |
| 234 | if 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 |
| 242 | fi |
| 243 | |
| 244 | ######################## |
| 245 | ## Install Everything ## |
| 246 | ######################## |
| 247 | source "$currentDir/packages/pkg_desktop.sh" |
| 248 | ALL_PKGS=( |
| 249 | "${DEV_PKGS[@]}" |
| 250 | "${OPTIONAL_PKGS[@]}" |
| 251 | "${GPU_PKGS[@]}" |
| 252 | "${UTILITY_PKGS[@]}" |
| 253 | "${pkg_desktop[@]}" |
| 254 | ) |
| 255 | |
| 256 | if [[ ${#ALL_PKGS[@]} -eq 0 ]]; then |
| 257 | log WARN "No packages selected." |
| 258 | else |
| 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 |
| 263 | fi |
| 264 | |
| 265 | |
| 266 | gum style \ |
| 267 | --border rounded \ |
| 268 | --padding "1 2" \ |
| 269 | --bold \ |
| 270 | --foreground 42 \ |
| 271 | "🎉 Installation Complete! |
| 272 | |
| 273 | Your system has been successfully configured. |
| 274 | |
| 275 | You may now reboot the system for all the changes to apply." |