#!/usr/bin/env bash # Full Sway bootstrap installer with gtkgreet # To run: curl -sfL https://sway.spurve.net/install.sh | sudo bash set -euo pipefail # ------------------------------- # CONFIG # ------------------------------- REPO_URL="https://github.com/skadakar/swayconf.git" APPLICATIONS_FILE="applications.txt" CONFIG_DIR=".config" ETC_DIR="etc" # ------------------------------- # Determine non-root user # ------------------------------- USER_TO_RUN="${SUDO_USER:-$USER}" HOME_TO_USE=$(eval echo "~$USER_TO_RUN") # ------------------------------- # Helper function: install yay # ------------------------------- install_yay() { if ! command -v yay &>/dev/null; then echo "yay not found. Installing yay..." sudo pacman -S --needed --noconfirm git base-devel TMP_DIR=$(mktemp -d -p "$HOME_TO_USE") sudo chown -R "$USER_TO_RUN":"$USER_TO_RUN" "$TMP_DIR" sudo -u "$USER_TO_RUN" git clone https://aur.archlinux.org/yay.git "$TMP_DIR/yay" cd "$TMP_DIR/yay" sudo -u "$USER_TO_RUN" makepkg -si --noconfirm cd - rm -rf "$TMP_DIR" else echo "yay is already installed." fi } # ------------------------------- # Clone repo (latest commit only) # ------------------------------- TMP_REPO=$(mktemp -d) trap 'rm -rf "$TMP_REPO"' EXIT echo "Cloning swayconf (latest commit only)..." git clone --depth 1 --branch main "$REPO_URL" "$TMP_REPO" # Make repo owned by non-root user sudo chown -R "$USER_TO_RUN":"$USER_TO_RUN" "$TMP_REPO" cd "$TMP_REPO" # ------------------------------- # Install packages # ------------------------------- if [[ -f "$APPLICATIONS_FILE" ]]; then pacman_pkgs=() yay_pkgs=() while IFS= read -r line; do [[ -z "$line" || "$line" =~ ^# ]] && continue manager="${line%%:*}" package="${line#*:}" case "$manager" in pacman) pacman_pkgs+=("$package") ;; yay) yay_pkgs+=("$package") ;; *) echo "Unknown package manager: $manager" ;; esac done < "$APPLICATIONS_FILE" if [[ ${#pacman_pkgs[@]} -gt 0 ]]; then echo "Installing pacman packages..." sudo pacman -S --needed --noconfirm "${pacman_pkgs[@]}" fi if [[ ${#yay_pkgs[@]} -gt 0 ]]; then install_yay echo "Installing yay/AUR packages..." sudo -u "$USER_TO_RUN" yay -S --needed --noconfirm "${yay_pkgs[@]}" fi fi # ------------------------------- # Sync .config to user's home # ------------------------------- echo "Copying .config to $HOME_TO_USE..." mkdir -p "$HOME_TO_USE/.config" if [[ -d "$CONFIG_DIR" ]]; then rsync -a --delete "$CONFIG_DIR/" "$HOME_TO_USE/.config/" fi # ------------------------------- # Copy /etc files from repo to /etc as root # ------------------------------- if [[ -d "$ETC_DIR" ]]; then echo "Copying repo /etc files to /etc..." find "$ETC_DIR" -type f | while read -r f; do dest="/etc/${f#$ETC_DIR/}" sudo mkdir -p "$(dirname "$dest")" sudo cp -f "$f" "$dest" # Force overwrite sudo chown root:root "$dest" # Set ownership sudo chmod 644 "$dest" # Set permissions echo "Copied $f -> $dest" done # Ensure directories have correct permissions find /etc/ -type d -exec sudo chmod 755 {} \; fi # ------------------------------- # Create greeter user if needed # ------------------------------- if ! id greeter &>/dev/null; then echo "Creating greeter user..." sudo useradd -M -G video greeter fi # ------------------------------- # Enable greetd service # ------------------------------- echo "Enabling greetd.service..." sudo systemctl enable --now greetd.service # ------------------------------- # Reload Sway # ------------------------------- echo "Dotfiles bootstrap complete!" echo "Reloading sway..." sudo -u "$USER_TO_RUN" swaymsg reload