From ad02f786d79003d5b78b6c2104b78f25168b9d00 Mon Sep 17 00:00:00 2001 From: krolxon Date: Tue, 9 Dec 2025 15:30:45 +0530 Subject: [PATCH] install.sh: stow, delete conflicting files if they exist --- install.sh | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index 2160940..4fe87f4 100755 --- a/install.sh +++ b/install.sh @@ -122,10 +122,7 @@ pkg_aur=( # Install necessary desktop packages -sudo pacman -S --needed "${pkg_desktop[@]}" - -# install packages -sudo pacman -S --needed "${pkg_utils[@]}" +sudo pacman -S --needed "${pkg_desktop[@]}" "${pkg_utils[@]}" # Install dev tools read -rp "Do you wish to development tools? [y/n]" install_dev_tools @@ -163,3 +160,39 @@ if [[ $install_aur_pkg == y ]]; then # Install aur packages paru -S --needed "${pkg_aur[@]}" fi + + +# Setup dotfiles +echo "⚠️ WARNING: This will DELETE any conflicting files and replace them with symlinks from this repo." +echo " Make sure your dotfiles repo is the source of truth / already backed up." +read -rp "Continue with stow (y/N): " confirm +if [[ "$confirm" =~ ^[Yy]$ ]]; then + echo "Detecting conflicts..." + conflicts=$(stow . --no-folding -nv 2>&1 | \ + sed -n 's/.*existing target \(.*\) since neither.*/\1/p') + + if [[ -z "$conflicts" ]]; then + echo "No conflicts. Running stow normally..." + stow . --no-folding + echo "✅ Done." + else + echo "These paths conflict and will be removed:" + printf ' %s\n' $conflicts + read -rp "Proceed with deleting these files? (y/N): " ok + if [[ ! "$ok" =~ ^[Yy]$ ]]; then + echo "Aborted." + fi + + # Remove conflicts relative to $HOME + for path in $conflicts; do + echo "Removing $HOME/$path" + rm -rf "$HOME/$path" + done + + echo "Running stow..." + stow . --no-folding + echo "✅ Dotfiles stowed with overwrite." + fi +else + echo "Aborted" +fi