diff --git a/modules/programs/home/zsh/scripts/rebuild.sh b/modules/programs/home/zsh/scripts/rebuild.sh index 035de95..a738ae7 100755 --- a/modules/programs/home/zsh/scripts/rebuild.sh +++ b/modules/programs/home/zsh/scripts/rebuild.sh @@ -2,22 +2,30 @@ current_dir=$(pwd) -cd ~/nix +cd ~/nix || exit -git add . +git fetch -alejandra . +if git diff --quiet HEAD..origin/main; then + echo "No changes detected in the remote. Proceeding with rebuild..." -hostname=$(hostname) + git add . -if echo "$hostname" | grep -q 'desktop'; then - doas nixos-rebuild switch --flake ~/nix/#desktop -elif echo "$hostname" | grep -q 'laptop'; then - doas nixos-rebuild switch --flake ~/nix/#laptop -elif echo "$hostname" | grep -q 'server'; then - doas nixos-rebuild switch --flake ~/nix/#server -elif echo "$hostname" | grep -q 'localhost'; then - nix-on-droid switch --flake ~/nix + hostname=$(hostname) + + if echo "$hostname" | grep -q 'desktop'; then + doas nixos-rebuild switch --flake ~/nix/#desktop + elif echo "$hostname" | grep -q 'laptop'; then + doas nixos-rebuild switch --flake ~/nix/#laptop + elif echo "$hostname" | grep -q 'server'; then + doas nixos-rebuild switch --flake ~/nix/#server + elif echo "$hostname" | grep -q 'localhost'; then + nix-on-droid switch --flake ~/nix + fi +else + echo "Changes detected in the remote. Stopping execution." + git diff HEAD..origin/main + exit 1 fi -cd "$current_dir" +cd "$current_dir" || exit