#!/usr/bin/env bash
# deploy-frigate.sh - Deploy Frigate NVR on chelsty-infra (print or SSH)

MODE="print"
[[ "$1" == "--ssh" ]] && MODE="ssh"

TARGET="100.122.201.22"
NODE="chelsty-infra"
REPO_PATH="/home/oskar/homelab-codex-ws"
SERVICE_PATH="$REPO_PATH/hosts/chelsty-infra/runtime/frigate"

echo "HOST: $NODE"
echo "MODE: $MODE"
echo "TARGET: $TARGET"

# Secrets must exist at /opt/homelab/config/frigate/frigate.env on the node
# before first deploy. See config.yml for required variables.
DEPLOY_CMD="cd $REPO_PATH && git fetch origin && git checkout master && git pull origin master && cd $SERVICE_PATH && docker-compose pull && docker-compose up -d"

if [[ "$MODE" == "ssh" ]]; then
    echo "--- Deploying Frigate to $NODE ($TARGET) via SSH ---"
    ssh oskar@$TARGET "$DEPLOY_CMD"
else
    echo "# --- Deployment commands for $NODE ---"
    echo "ssh oskar@$TARGET '$DEPLOY_CMD'"
fi
