39 lines
931 B
Bash
39 lines
931 B
Bash
#!/usr/bin/env bash
|
|
|
|
# This script pulls the latest changes from the Git repository
|
|
# and runs OpenTofu to provision the hypervisor state.
|
|
# Usage: ./hypervisor-sync.sh <REPO_URL> <OPENTOFU_DIR>
|
|
|
|
REPO_URL=${1:-"https://git.depeuter.dev/Bos55/nix-config.git"}
|
|
OPENTOFU_DIR=${2:-"opentofu/nodes/mikoshi"}
|
|
|
|
echo "Starting Hypervisor GitOps sync..."
|
|
|
|
if [ ! -d "nix-config" ]; then
|
|
echo "Cloning repository from $REPO_URL..."
|
|
git clone "$REPO_URL" nix-config
|
|
fi
|
|
|
|
cd nix-config || exit
|
|
|
|
git fetch origin v2
|
|
|
|
LOCAL=$(git rev-parse HEAD)
|
|
REMOTE=$(git rev-parse origin/v2)
|
|
|
|
if [ "$LOCAL" = "$REMOTE" ]; then
|
|
echo "Already up to date. Nothing to do."
|
|
exit 0
|
|
fi
|
|
|
|
echo "Changes detected. Updating from $LOCAL to $REMOTE..."
|
|
git reset --hard origin/v2
|
|
|
|
echo "Applying OpenTofu changes in $OPENTOFU_DIR..."
|
|
cd "$OPENTOFU_DIR" || exit
|
|
|
|
tofu init -upgrade
|
|
|
|
tofu apply -auto-approve
|
|
|
|
echo "Hypervisor GitOps sync completed successfully."
|