#!/bin/bash set -euo pipefail # ------------------------------- # Helpers # ------------------------------- info() { printf '\n==> %s\n' "$1" } append_if_missing() { local line="$1" local file="$2" touch "$file" grep -qxF "$line" "$file" || echo "$line" >>"$file" } # ------------------------------- # Paths and config # ------------------------------- HOME_DIR="$HOME" BASHRC="$HOME_DIR/.bashrc" SSH_KEY_PATH="$HOME_DIR/.ssh/id_ed25519" SSH_KEY_EMAIL="hector@h3cx.dev" DOTFILES_REPO="gitea@git.h3cx.dev:h3cx/HectorsDotFiles.git" WALLPAPERS_REPO="gitea@git.h3cx.dev:h3cx/HectorsWallpapers.git" CONFIG_BACKUP="$HOME_DIR/.config.backup.$(date +%Y%m%d-%H%M%S)" WALLPAPER_TARGET="$HOME_DIR/.local/share/wallpapers" TMP_DIR="$(mktemp -d)" cleanup() { rm -rf "$TMP_DIR" } trap cleanup EXIT cd "$HOME_DIR" # ------------------------------- # System update and packages # ------------------------------- info "Updating system" sudo pacman -Syu --noconfirm info "Installing base packages" sudo pacman -S --needed --noconfirm \ git \ which \ base-devel \ ttf-jetbrains-mono-nerd \ cliphist \ wl-clipboard \ neovim \ starship \ lazygit \ openssh # ------------------------------- # yay # ------------------------------- if ! command -v yay >/dev/null 2>&1; then info "Installing yay" git clone https://aur.archlinux.org/yay.git "$TMP_DIR/yay" ( cd "$TMP_DIR/yay" makepkg -si --noconfirm ) else info "yay already installed" fi # ------------------------------- # AUR packages # ------------------------------- info "Installing AUR packages" yay -S --needed --noconfirm zen-browser-bin # ------------------------------- # ble.sh # ------------------------------- if [ ! -f "$HOME_DIR/.local/share/blesh/ble.sh" ]; then info "Installing ble.sh" git clone --recursive --depth 1 --shallow-submodules https://github.com/akinomyoga/ble.sh.git "$TMP_DIR/ble.sh" make -C "$TMP_DIR/ble.sh" install PREFIX="$HOME_DIR/.local" else info "ble.sh already installed" fi append_if_missing 'source -- ~/.local/share/blesh/ble.sh' "$BASHRC" # ------------------------------- # Shell setup # ------------------------------- info "Configuring shell" append_if_missing 'eval "$(starship init bash)"' "$BASHRC" stty sane || true # ------------------------------- # Git setup # ------------------------------- info "Configuring git" git config --global user.email "$SSH_KEY_EMAIL" git config --global user.name "Hector van der Aa" # ------------------------------- # SSH key setup for Gitea # ------------------------------- info "Preparing SSH key for git access" mkdir -p "$HOME_DIR/.ssh" chmod 700 "$HOME_DIR/.ssh" if [ ! -f "$SSH_KEY_PATH" ]; then ssh-keygen -t ed25519 -C "$SSH_KEY_EMAIL" -f "$SSH_KEY_PATH" -N "" else info "SSH key already exists at $SSH_KEY_PATH, reusing it" fi chmod 600 "$SSH_KEY_PATH" chmod 644 "$SSH_KEY_PATH.pub" if command -v ssh-keyscan >/dev/null 2>&1; then touch "$HOME_DIR/.ssh/known_hosts" ssh-keyscan -H git.h3cx.dev >>"$HOME_DIR/.ssh/known_hosts" 2>/dev/null || true fi if command -v wl-copy >/dev/null 2>&1; then wl-copy <"$SSH_KEY_PATH.pub" info "Your public SSH key has been copied to the clipboard" else info "wl-copy not found, public key is below" cat "$SSH_KEY_PATH.pub" fi echo echo "Add this SSH public key as an authorized key in your Gitea account:" echo " $SSH_KEY_PATH.pub" echo read -rp "Press Enter once the key has been added to git.h3cx.dev... " # ------------------------------- # Clone private repositories # ------------------------------- info "Replacing ~/.config with HectorsDotFiles" if [ -d "$HOME_DIR/.config" ]; then mv "$HOME_DIR/.config" "$CONFIG_BACKUP" info "Existing ~/.config moved to $CONFIG_BACKUP" fi git clone "$DOTFILES_REPO" "$HOME_DIR/.config" info "Installing wallpapers repository" mkdir -p "$HOME_DIR/.local/share" rm -rf "$WALLPAPER_TARGET" git clone "$WALLPAPERS_REPO" "$WALLPAPER_TARGET" info "Post-install section completed" echo "You may want to restart your shell or run: source ~/.bashrc"