#!/usr/bin/env bash
# Rihvara coming-soon page for rihvara.com, served by Caddy (installed on the server, not in Docker).
# Usage on the server: bash rihvara-coming-soon.sh
set -euo pipefail
SITE_DIR=/var/www/rihvara/coming-soon
CADDYFILE=/etc/caddy/Caddyfile
echo "==> Creating $SITE_DIR"
sudo mkdir -p "$SITE_DIR"
echo "==> Writing index.html"
sudo tee "$SITE_DIR/index.html" >/dev/null <<'EOF'
EOF
sudo chmod 755 /var/www /var/www/rihvara "$SITE_DIR"
sudo chmod 644 "$SITE_DIR/index.html"
echo "==> Configuring Caddy"
if [ ! -f "$CADDYFILE" ]; then
echo "ERROR: $CADDYFILE not found. Is Caddy installed on the server (not in Docker)?"
exit 1
fi
if grep -qE '^[[:space:]]*(https?://)?(www\.)?rihvara\.com' "$CADDYFILE"; then
echo "NOTE: $CADDYFILE already has a rihvara.com block. Not changing it."
echo " Make sure that block contains: root * $SITE_DIR and file_server"
else
sudo cp "$CADDYFILE" "$CADDYFILE.bak.$(date +%Y%m%d-%H%M%S)"
sudo tee -a "$CADDYFILE" >/dev/null <<'EOF'
rihvara.com, www.rihvara.com {
root * /var/www/rihvara/coming-soon
file_server
encode zstd gzip
header {
Strict-Transport-Security "max-age=31536000"
X-Content-Type-Options "nosniff"
X-Frame-Options "DENY"
Referrer-Policy "strict-origin-when-cross-origin"
Content-Security-Policy "default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'; img-src 'self' data:; base-uri 'none'; frame-ancestors 'none'"
-Server
}
}
EOF
fi
echo "==> Validating and reloading Caddy"
sudo caddy validate --config "$CADDYFILE" --adapter caddyfile
sudo systemctl reload caddy
echo
echo "Done. Open https://rihvara.com"
echo "(HTTPS starts working once the DNS records for rihvara.com and www.rihvara.com point to this server.)"