#!/usr/bin/env bash set -euo pipefail DOMAIN="${DOMAIN:-politictalk.parallelglobe.io}" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" JITSI_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" BACKUP_ROOT="${BACKUP_ROOT:-/root/jitsi-backups}" STAMP="$(date +%Y%m%d-%H%M%S)" BACKUP_DIR="$BACKUP_ROOT/$STAMP" CONFIG_SRC="$JITSI_DIR/config/$DOMAIN-config.js" ASSETS_SRC="$JITSI_DIR/assets/public/politictalk" NGINX_SRC="$JITSI_DIR/nginx/$DOMAIN.conf" CONFIG_DEST="/etc/jitsi/meet/$DOMAIN-config.js" ASSETS_DEST="/etc/jitsi/meet/public/politictalk" NGINX_DEST="/etc/nginx/sites-available/$DOMAIN.conf" if [[ "$(id -u)" -ne 0 ]]; then echo "Run this script with sudo on the VPS." exit 1 fi if [[ ! -f "$CONFIG_SRC" ]]; then echo "Missing config source: $CONFIG_SRC" exit 1 fi if [[ ! -d "$ASSETS_SRC" ]]; then echo "Missing assets source: $ASSETS_SRC" exit 1 fi install -d -m 0755 "$BACKUP_DIR" if [[ -f "$CONFIG_DEST" ]]; then cp -a "$CONFIG_DEST" "$BACKUP_DIR/" fi if [[ -d "$ASSETS_DEST" ]]; then install -d -m 0755 "$BACKUP_DIR/public" cp -a "$ASSETS_DEST" "$BACKUP_DIR/public/" fi if [[ "${DEPLOY_NGINX:-0}" == "1" && -f "$NGINX_DEST" ]]; then cp -a "$NGINX_DEST" "$BACKUP_DIR/" fi install -d -m 0755 "$ASSETS_DEST" install -m 0644 "$CONFIG_SRC" "$CONFIG_DEST" find "$ASSETS_SRC" -maxdepth 1 -type f -print0 | while IFS= read -r -d '' file; do install -m 0644 "$file" "$ASSETS_DEST/" done if [[ "${DEPLOY_NGINX:-0}" == "1" ]]; then if [[ ! -f "$NGINX_SRC" ]]; then echo "Missing nginx source: $NGINX_SRC" exit 1 fi install -m 0644 "$NGINX_SRC" "$NGINX_DEST" nginx -t fi systemctl reload nginx echo "Deployed PoliticTalk Jitsi files." echo "Backup: $BACKUP_DIR"