#!/bin/bash
set -e

cd "$(dirname "$0")"

BUN=$(which bun)

echo "Pulling latest changes..."
PULL_OUTPUT=$(git pull)
echo "$PULL_OUTPUT"
if [ "$PULL_OUTPUT" = "Already up to date." ]; then
  echo "Nothing to deploy."
  exit 0
fi

echo "Installing dependencies..."
$BUN i

echo "Building..."
$BUN --bun run build

SERVICE_NAME="$(basename "$(pwd)").service"
echo "Restarting service ($SERVICE_NAME)..."
sudo systemctl restart "$SERVICE_NAME"

echo "Done!"
