#!/usr/bin/env bash
set -e

# Get absolute path of this script's directory
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
ROOT_DIR="$SCRIPT_DIR/.."

# Load config
source "$ROOT_DIR/scripts/config.sh"

# Make sure we're up-to-date
if [ -n "$(git status --porcelain)" ]; then
  echo "=> You have unsaved (git) changes"
  exit 1
fi

git push origin main

# SSH to target and update
ssh "$HOST" "cd $DEST && git pull origin main && bun run build && sudo systemctl restart toes.service"

echo "=> Deployed to $HOST"
echo "=> Visit $URL"
