#!/usr/bin/env bash set -euo pipefail ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" REPO_URL="${GIT_REPO_URL:-https://git.organic-server.org/organic-CPU/website-but-better.git}" BRANCH="${GIT_BRANCH:-main}" DEPLOY_DIR="${DEPLOY_DIR:-/var/www/html}" cd "$ROOT_DIR" if [ ! -d .git ]; then if [ "$(find . -maxdepth 1 -mindepth 1 | wc -l)" -eq 0 ]; then echo "Cloning website repository from $REPO_URL into $ROOT_DIR" git clone "$REPO_URL" . else echo "Error: $ROOT_DIR is not a git repository and is not empty." >&2 echo "Please clone the repository into this directory or initialize git manually." >&2 exit 1 fi fi echo "Syncing website from $REPO_URL ($BRANCH)" git remote set-url origin "$REPO_URL" git fetch origin --prune git checkout "$BRANCH" git pull --ff-only origin "$BRANCH" echo "Regenerating manifests" if command -v python3 >/dev/null 2>&1; then python3 scripts/generate_blog_manifest.py python3 scripts/generate_manifest.py else echo "Warning: python3 not found; manifest regeneration skipped." >&2 fi if [ "$DEPLOY_DIR" != "$ROOT_DIR" ]; then echo "Deploying website files to $DEPLOY_DIR" mkdir -p "$DEPLOY_DIR" rsync -a --delete \ --exclude '.git' \ --exclude 'scripts/' \ --exclude 'nginx/' \ --exclude '.gitignore' \ --exclude '*.sh' \ "$ROOT_DIR/" "$DEPLOY_DIR/" fi echo "Website sync complete."