#!/usr/bin/env bash
set -euo pipefail

TARGET_HOST="${TARGET_HOST:-player@193.8.215.70}"
TARGET_DOMAIN="${TARGET_DOMAIN:-test2.shineup.me}"
REMOTE_UI_DIR="${REMOTE_UI_DIR:-/home/player/SHiNE/shine-ui}"

TARGET_HOST="$TARGET_HOST" TARGET_DOMAIN="$TARGET_DOMAIN" REMOTE_UI_DIR="$REMOTE_UI_DIR" \
  bash "$(dirname "$0")/scripts/install_test2_caddyfile.sh"

REMOTE_HOST="$TARGET_HOST" \
REMOTE_UI_DIR="$REMOTE_UI_DIR" \
EXPECTED_CADDY_UI_ROOT="$REMOTE_UI_DIR" \
EXPECTED_CADDY_SITE="$TARGET_DOMAIN" \
TARGET_URL="https://$TARGET_DOMAIN" \
bash "$(dirname "$0")/deploy_shine-PWA.sh"

ssh "$TARGET_HOST" "sudo chmod o+x /home/player /home/player/SHiNE '$REMOTE_UI_DIR'; \
  sudo find '$REMOTE_UI_DIR' -type d -exec chmod o+rx {} +; \
  sudo find '$REMOTE_UI_DIR' -type f -exec chmod o+r {} +"

