#!/bin/bash # deploy_ksaldis.sh — Deploy automático del libro de estudio # Llamado por el webhook de Gitea al hacer push set -e REPO_DIR="/var/www/ksaldis-dt/.repo" WEB_DIR="/var/www/ksaldis-dt" REPO_URL="http://10.0.10.205:3000/rmonla/rm-KSALDIS-DT.git" LOG="$WEB_DIR/deploy.log" # Configurar git safe.directory (necesario cuando el script corre como www-data) export GIT_CONFIG_GLOBAL=/dev/null git config --global --add safe.directory "$REPO_DIR" 2>/dev/null || true log() { echo "$(date '+%Y-%m-%d %H:%M:%S') | $1" >> "$LOG" } log "====== Deploy iniciado ======" # Clonar o actualizar repo if [ -d "$REPO_DIR/.git" ]; then cd "$REPO_DIR" git fetch origin 2>&1 git reset --hard origin/main 2>&1 log "git pull OK" else rm -rf "$REPO_DIR" git clone "$REPO_URL" "$REPO_DIR" 2>&1 log "git clone OK" fi # Copiar LIBRO_DE_ESTUDIO.html como index.html SRC="$REPO_DIR/descargar-curso/descargas/LIBRO_DE_ESTUDIO.html" if [ -f "$SRC" ]; then cp "$SRC" "$WEB_DIR/index.html" log "index.html actualizado ($(wc -c < "$WEB_DIR/index.html") bytes)" fi # Copiar secciones (sin videos_offline) SECCIONES_SRC="$REPO_DIR/descargar-curso/descargas/secciones" if [ -d "$SECCIONES_SRC" ]; then rsync -a --delete "$SECCIONES_SRC/" "$WEB_DIR/secciones/" log "secciones/ actualizadas" fi # Copiar otros assets for asset in campus imagenes screenshots subpaginas; do ASSET_SRC="$REPO_DIR/descargar-curso/descargas/$asset" if [ -d "$ASSET_SRC" ]; then rsync -a "$ASSET_SRC/" "$WEB_DIR/$asset/" log "$asset/ actualizado" fi done log "====== Deploy completado ======"