add script for fetching updates

This commit is contained in:
2025-11-29 13:15:35 +03:00
parent 36765feed3
commit 8736b50e04
3 changed files with 39 additions and 1 deletions
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
set -euo pipefail
REPO_DIR="$HOME/Documents/Github/nixos-config"
cd "$REPO_DIR" || { echo "Error: cannot change directory to $REPO_DIR" >&2; exit 1; }
echo "Fetching latest changes from git..."
if ! git fetch --all; then
echo "Error: git fetch failed" >&2
exit 2
fi
LOCAL_HASH=$(git rev-parse @)
REMOTE_HASH=$(git rev-parse @{u})
if [ "$LOCAL_HASH" = "$REMOTE_HASH" ]; then
echo "The repository is already up to date."
exit 0
else
echo "Updates are available. Pulling latest changes..."
if ! git pull; then
echo "Error: git pull failed" >&2; exit 3
fi
echo "Repository updated successfully."
fi
chmod -R u+rwX "$REPO_DIR"
sudo ./update-nixos.sh
./update-home-manager.sh
echo "System update from git completed successfully."