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

TARGET_USER="${SUDO_USER:-$USER}"
WEB_ROOT="/var/www/html"

echo "==> Purging default Apache files from ${WEB_ROOT}..."
# Clear all existing files in the web root
rm -rf ${WEB_ROOT}/*
rm -rf ${WEB_ROOT}/.* 2>/dev/null || true

echo "==> Ensuring ownership for ${TARGET_USER}:www-data..."
chown -R "${TARGET_USER}:www-data" "${WEB_ROOT}"
chmod -R 775 "${WEB_ROOT}"

echo "==> Web root is clean and ready for Syncthing!"