61 lines
1.8 KiB
Bash
61 lines
1.8 KiB
Bash
#!/usr/bin/env bash
|
|
# Deploy the Inference Cooperative landing page to Cloudron Surfer via WebDAV.
|
|
#
|
|
# Usage:
|
|
# ./deploy.sh
|
|
#
|
|
# Credentials are read from .deploy.env (gitignored) or environment variables:
|
|
# SURFER_URL WebDAV base URL (e.g. https://inference.coop/_webdav/)
|
|
# SURFER_USER WebDAV username
|
|
# SURFER_TOKEN WebDAV password / app token
|
|
#
|
|
# The script uploads the contents of landing-page/ (index.html, favicon.svg,
|
|
# fonts/) to the Surfer instance, creating directories as needed and
|
|
# overwriting existing files.
|
|
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
SITE_DIR="$SCRIPT_DIR/landing-page"
|
|
|
|
# Load credentials from .deploy.env if present
|
|
if [[ -f "$SCRIPT_DIR/.deploy.env" ]]; then
|
|
set -a
|
|
# shellcheck disable=SC1091
|
|
source "$SCRIPT_DIR/.deploy.env"
|
|
set +a
|
|
fi
|
|
|
|
: "${SURFER_URL:?SURFER_URL is required (set in .deploy.env or env)}"
|
|
: "${SURFER_USER:?SURFER_USER is required}"
|
|
: "${SURFER_TOKEN:?SURFER_TOKEN is required}"
|
|
|
|
# Strip trailing slash for clean joining
|
|
SURFER_URL="${SURFER_URL%/}"
|
|
|
|
AUTH=(-u "$SURFER_USER:$SURFER_TOKEN")
|
|
|
|
echo "Deploying $SITE_DIR -> $SURFER_URL"
|
|
|
|
# 1. Create all directories (MKCOL). WebDAV requires parent collections to
|
|
# exist before files can be uploaded into them.
|
|
find "$SITE_DIR" -type d | while read -r dir; do
|
|
rel="${dir#"$SITE_DIR"}"
|
|
# Skip the root (rel is empty)
|
|
[[ -z "$rel" ]] && continue
|
|
dest="$SURFER_URL/$rel"
|
|
echo " mkdir $rel"
|
|
# MKCOL returns 405 if the collection already exists — that's fine.
|
|
curl -sS -X MKCOL "${AUTH[@]}" "$dest" >/dev/null 2>&1 || true
|
|
done
|
|
|
|
# 2. Upload every file, preserving relative paths.
|
|
find "$SITE_DIR" -type f | while read -r file; do
|
|
rel="${file#"$SITE_DIR"/}"
|
|
dest="$SURFER_URL/$rel"
|
|
echo " -> $rel"
|
|
curl -sS -f -T "$file" "${AUTH[@]}" "$dest"
|
|
done
|
|
|
|
echo "Deploy complete."
|