#!/usr/bin/env bash
# curl -fsSL https://maint.spaceplane.dev/install.sh | sudo bash
set -euo pipefail

if [ "$(id -u)" -ne 0 ]; then
    echo "Run as root (sudo)." >&2
    exit 1
fi

BASE="https://maint.spaceplane.dev/dist"

install -d /etc/nginx/snippets /etc/nginx/maintenance /var/www/maintenance /etc/maint

curl -fsSL "$BASE/maint" -o /usr/local/sbin/maint
chmod 755 /usr/local/sbin/maint

curl -fsSL "$BASE/maintenance.conf" -o /etc/nginx/snippets/maintenance.conf
curl -fsSL "$BASE/maintenance-page.conf" -o /etc/nginx/snippets/maintenance-page.conf
curl -fsSL "$BASE/maintenance.html" -o /var/www/maintenance/maintenance.html

echo "maint installed."
echo
echo "Next: wire a site into its nginx config (see the README), then reload nginx"
echo "once. After that, toggle with: maint <site> on|off|status"
