#!/usr/bin/env bash
# Option A: EP symlink + .htaccess for https://friendlytv.site/vpn-*.php
set -euo pipefail
EP="/var/www/html/wordpress6/wordpress/EP"
ROOT="/var/www/html/wordpress2/wordpress"
HTSRC="$EP/friendlytv-site.htaccess.example"
HTDST="$ROOT/.htaccess"

if [[ "$(id -u)" -ne 0 ]]; then
  echo "Run with: sudo bash $0" >&2
  exit 1
fi

ln -sfn "$EP" "$ROOT/EP"
chown -h www-data:www-data "$ROOT/EP"

if [[ -f "$HTDST" ]]; then
  echo "Backing up existing $HTDST" >&2
  cp -a "$HTDST" "${HTDST}.bak.$(date +%Y%m%d%H%M%S)"
fi

cp -a "$HTSRC" "$HTDST"
chown www-data:www-data "$HTDST"

echo "Done. Test: https://friendlytv.site/vpn-login.php"
ls -la "$ROOT"
