| 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 | # Prevent user from running this script as root |
| 21 | if [[ "$EUID" -eq 0 ]]; then |
| 22 | log ERROR "This script must NOT be run as root." |
| 23 | log INFO "If you need elevated privileges, the script will ask for sudo when required." |
| 24 | exit 1 |
| 25 | fi |
| 26 | |
| 27 | currentDir="$(dirname "$(readlink -f "$0")")" |
| 28 | cd "$currentDir" |
| 29 | |
| 30 | ## Install necessary desktop packages |
| 31 | source "$currentDir/packages/pkg_desktop.sh" |
| 32 | source "$currentDir/packages/pkg_utils.sh" |
| 33 | log INFO "Starting Script" |
| 34 | log INFO "Installing necessary packages for hyprland" |
| 35 | sudo pacman -Sy --needed "${pkg_desktop[@]}" "${pkg_utils[@]}" |
| 36 | |
| 37 | ## Install dev tools |
| 38 | read -rp "Do you wish to install development tools? [y/N]" install_dev_tools |
| 39 | if [[ $install_dev_tools == y ]]; then |
| 40 | log INFO "Installing development tools" |
| 41 | source "$currentDir/packages/pkg_dev_tools.sh" |
| 42 | sudo pacman -S --needed "${pkg_dev_tools[@]}" |
| 43 | fi |
| 44 | |
| 45 | ## Install optional packages |
| 46 | read -rp "Do you wish to install optional packages? [y/N]" install_optional_pkg |
| 47 | if [[ $install_optional_pkg == y ]]; then |
| 48 | log INFO "Installing development tools" |
| 49 | source "$currentDir/packages/pkg_optional.sh" |
| 50 | sudo pacman -S --needed "${pkg_optional[@]}" |
| 51 | fi |
| 52 | |
| 53 | ## Install nvidia drivers |
| 54 | read -rp "Do you wish to install GPU drivers? (Intel & Nvidia) [y/N]" install_gpu_drivers |
| 55 | if [[ $install_gpu_drivers == y ]]; then |
| 56 | log INFO "Installing GPU Drivers" |
| 57 | source "$currentDir/packages/pkg_gpu.sh" |
| 58 | sudo pacman -S --needed "${pkg_gpu[@]}" |
| 59 | fi |
| 60 | |
| 61 | |
| 62 | ## Install aur packages |
| 63 | read -rp "Do you wish to install aur packages? [y/N]" install_aur_pkg |
| 64 | if [[ $install_aur_pkg == y ]]; then |
| 65 | ## Install paru if it isn't already installed |
| 66 | if ! command -v paru >/dev/null 2>&1; then |
| 67 | log INFO "Installing Paru (AUR package manager)" |
| 68 | git clone https://aur.archlinux.org/paru.git |
| 69 | cd paru |
| 70 | makepkg -sri |
| 71 | cd .. |
| 72 | rm -rf paru |
| 73 | else |
| 74 | log INFO "Skipping paru (already in PATH)" |
| 75 | fi |
| 76 | ## Install aur packages |
| 77 | source "$currentDir/packages/pkg_aur.sh" |
| 78 | paru -S --needed "${pkg_aur[@]}" |
| 79 | fi |
| 80 | |
| 81 | |
| 82 | ## Setup dotfiles |
| 83 | log WARN "This will DELETE any conflicting files and replace them with symlinks from this repo." |
| 84 | log WARN "Make sure you have already backed up all your existing config files (~/.config)" |
| 85 | read -rp "Continue with stow (y/N): " confirm |
| 86 | if [[ "$confirm" =~ ^[Yy]$ ]]; then |
| 87 | log INFO "Detecting conflicts..." |
| 88 | conflicts=$(stow . --no-folding -nv 2>&1 | \ |
| 89 | sed -n 's/.*existing target \(.*\) since neither.*/\1/p') |
| 90 | |
| 91 | if [[ -z "$conflicts" ]]; then |
| 92 | log INFO "No conflicts. Running stow normally..." |
| 93 | stow . --no-folding \ |
| 94 | && log SUCCESS "Dotfiles stowed successfully" \ |
| 95 | || log ERROR "Stow failed" |
| 96 | else |
| 97 | log WARN "These paths conflict and will be removed:" |
| 98 | printf ' %s\n' $conflicts |
| 99 | read -rp "Proceed with deleting these files? (y/N): " ok |
| 100 | if [[ ! "$ok" =~ ^[Yy]$ ]]; then |
| 101 | echo "Aborted." |
| 102 | fi |
| 103 | |
| 104 | # Remove conflicts relative to $HOME |
| 105 | for path in $conflicts; do |
| 106 | rm -rf "$HOME/$path" && log INFO "Removed $HOME/$path" |
| 107 | done |
| 108 | |
| 109 | log INFO "Running stow..." |
| 110 | stow . --no-folding \ |
| 111 | && log INFO "✅ Dotfiles stowed with overwrite." \ |
| 112 | || log ERROR "Stow failed" |
| 113 | fi |
| 114 | else |
| 115 | log WARN "Aborted stow, the dotfiles are not synced" |
| 116 | fi |
| 117 | |
| 118 | |
| 119 | ## Setup neovim dotfiles |
| 120 | read -rp "Setup neovim configuration as well? (y/N): " confirm |
| 121 | if [[ "$confirm" =~ ^[Yy]$ ]]; then |
| 122 | log INFO "Taking backup of neovim config (if already exists)" |
| 123 | mv ~/.config/nvim{,.bak} |
| 124 | mv ~/.local/share/nvim{,.bak} |
| 125 | mv ~/.local/state/nvim{,.bak} |
| 126 | mv ~/.cache/nvim{,.bak} |
| 127 | git clone --depth=1 https://github.com/krolyxon/nvim.git ~/.config/nvim |
| 128 | fi |
| 129 | |
| 130 | ## Change default shell to zsh |
| 131 | log INFO "Changing the default shell to ZSH" |
| 132 | if [[ "$SHELL" != "$(which zsh)" ]]; then |
| 133 | read -rp "Change default shell to ZSH? (y/N): " confirm |
| 134 | if [[ "$confirm" =~ ^[Yy]$ ]]; then |
| 135 | chsh -s $(which zsh) \ |
| 136 | && log SUCCESS "Default shell successfully set to zsh" \ |
| 137 | || log ERROR "Default shell could not be set to zsh" |
| 138 | fi |
| 139 | else |
| 140 | log INFO "Skipping: zsh is already the default shell" |
| 141 | fi |
| 142 | |
| 143 | |
| 144 | ## Install and setup Keyd |
| 145 | read -rp "Configure and enable Keyd? (y/N): " confirm |
| 146 | if [[ "$confirm" =~ ^[Yy]$ ]]; then |
| 147 | log INFO "Copying keyd configuration to /etc/keyd/default.conf" |
| 148 | sudo cp "$currentDir/system/etc/keyd/default.conf" /etc/keyd/ |
| 149 | sudo systemctl enable --now keyd.service \ |
| 150 | && log SUCCESS "Successfully enabled keyd.service" \ |
| 151 | || log ERROR "Couldn't enable keyd.service" |
| 152 | fi |
| 153 | |
| 154 | |
| 155 | |
| 156 | printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' = |
| 157 | echo "" |
| 158 | log SUCCESS "Done!" |