#!/bin/bash set -euo pipefail SITE=myvps-site DOMAIN=www.194.164.167.80.nip.io BASE=/opt/myvps-site REPO_DIR=$BASE/repo CONTENT_DIR=/opt/myvps-site-content/repo export HOME=/root CRED=$(grep -oE 'http://[^@]+@git\.194\.164\.167\.80\.nip\.io' /root/.git-credentials 2>/dev/null | head -1 || true) GITROOT=${CRED:-https://git.194.164.167.80.nip.io} export GIT_TERMINAL_PROMPT=0 mkdir -p "$BASE" /opt/myvps-site-content if [ -d "$REPO_DIR/.git" ]; then git -C "$REPO_DIR" pull -q --ff-only origin main else git clone -q "$GITROOT/forgejo-admin/myvps-site.git" "$REPO_DIR" fi if [ -d "$CONTENT_DIR/.git" ]; then git -C "$CONTENT_DIR" pull -q --ff-only origin main else git clone -q "$GITROOT/forgejo-admin/myvps-site-content.git" "$CONTENT_DIR" fi mkdir -p "$REPO_DIR/src/content/pages" cp "$CONTENT_DIR"/pages/*.md "$REPO_DIR/src/content/pages/" podman build -t "$SITE:latest" "$REPO_DIR" >/dev/null systemctl stop "container-$SITE.service" >/dev/null 2>&1 || true podman rm -f "$SITE" >/dev/null 2>&1 || true podman run -d --name "$SITE" --network web \ -l "traefik.enable=true" \ -l "traefik.docker.network=web" \ -l "traefik.http.routers.mysite.rule=Host(\`$DOMAIN\`)" \ -l "traefik.http.routers.mysite.entrypoints=web" \ -l "traefik.http.routers.mysite.middlewares=mysite-https-redirect@docker" \ -l "traefik.http.routers.mysite-tls.rule=Host(\`$DOMAIN\`)" \ -l "traefik.http.routers.mysite-tls.entrypoints=websecure" \ -l "traefik.http.routers.mysite-tls.tls=true" \ -l "traefik.http.routers.mysite-tls.tls.certresolver=le" \ -l "traefik.http.routers.mysite-tls.service=mysite" \ -l "traefik.http.routers.mysite-riservata.rule=Host(\`$DOMAIN\`) && PathPrefix(\`/riservata\`)" \ -l "traefik.http.routers.mysite-riservata.entrypoints=websecure" \ -l "traefik.http.routers.mysite-riservata.priority=100" \ -l "traefik.http.routers.mysite-riservata.tls=true" \ -l "traefik.http.routers.mysite-riservata.tls.certresolver=le" \ -l "traefik.http.routers.mysite-riservata.middlewares=authelia@docker" \ -l "traefik.http.routers.mysite-riservata.service=mysite" \ -l "traefik.http.middlewares.mysite-https-redirect.redirectscheme.scheme=https" \ -l "traefik.http.middlewares.mysite-https-redirect.redirectscheme.permanent=true" \ -l "traefik.http.services.mysite.loadbalancer.server.port=80" \ "$SITE:latest" >/dev/null UNIT=/etc/systemd/system/container-$SITE.service podman generate systemd --new --name "$SITE" > "$UNIT" systemctl daemon-reload systemctl enable "container-$SITE.service" >/dev/null 2>&1 || true WANT=/etc/systemd/system/multi-user.target.wants/container-$SITE.service mkdir -p "$(dirname "$WANT")" ln -sf "/etc/systemd/system/container-$SITE.service" "$WANT" 2>/dev/null || true systemctl restart "container-$SITE.service" >/dev/null 2>&1 || podman restart "$SITE" >/dev/null sleep 3 code=$(curl -s -o /dev/null -m 8 -w '%{http_code}' "https://$DOMAIN/" || true) echo "deploy $SITE completato $(date '+%Y-%m-%d %H:%M:%S') - home HTTP $code" [ "$code" = "200" ]