#!/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=${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 main LOCAL=$(git rev-parse HEAD) REMOTE=$(git rev-parse origin/main) 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/main echo "Applying OpenTofu changes in $OPENTOFU_DIR..." cd "$OPENTOFU_DIR" || exit tofu init -upgrade tofu apply -auto-approve echo "Hypervisor GitOps sync completed successfully."