#!/bin/bash set -e DOTFILES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$DOTFILES_DIR" || exit 1 PKG="stow" # Check if stow is installed if ! command -v stow &> /dev/null; then echo "'$PKG' is not installed." # Detect distribution if [[ -f /etc/os-release ]]; then . /etc/os-release DISTRO_ID=$ID else echo "Could not detect distribution. Please install '$PKG' manually." exit 1 fi # Choose installation command case "$DISTRO_ID" in debian|ubuntu) INSTALL_CMD="sudo apt update && sudo apt install -y $PKG" ;; opensuse*|suse|sles) INSTALL_CMD="sudo zypper install -y $PKG" ;; rocky|rhel|centos) INSTALL_CMD="sudo dnf install -y $PKG" ;; arch) INSTALL_CMD="sudo pacman -S --noconfirm $PKG" ;; *) echo "Unsupported distribution '$DISTRO_ID'. Please install '$PKG' manually." exit 1 ;; esac # Ask user read -rp "Do you want to install '$PKG' now? [y/N]: " reply if [[ "$reply" =~ ^[Yy]$ ]]; then echo "Running: $INSTALL_CMD" eval "$INSTALL_CMD" else echo "Aborted. '$PKG' is required to continue." exit 1 fi fi # Stow all visible subdirectories for pkg in */; do if [[ -d "$pkg" && ! "$pkg" =~ ^\..* ]]; then echo "${pkg%/}" stow -D "${pkg%/}" stow "${pkg%/}" fi done