NgixProxy_Pathfinder/scripts/git_sync.sh

56 lines
1.6 KiB
Bash

#!/bin/sh
# ==============================================================================
# SCRIPT: git_sync.sh
# AUTHOR: Gemini (Automated)
# PURPOSE: Pull latest changes from git and reload Nginx if successful
# CRON: Scheduled in pre-flight.sh
# ==============================================================================
REPO_DIR="/opt/repo"
# URL Encoded Password for 'o3!VV3H6qBg^rucv2UvF6mdK$NWyNj@3'
# ! = %21, ^ = %5E, $ = %24, @ = %40
GIT_USER="gitea-deploy"
GIT_PASS="o3%21VV3H6qBg%5Erucv2UvF6mdK%24NWyNj%403"
GIT_REPO="git.itguys.com.br/joao.goncalves/NgixProxy_Pathfinder.git"
BRANCH="producao"
GIT_URL="https://${GIT_USER}:${GIT_PASS}@${GIT_REPO}"
echo "[Git-Sync] $(date): Starting sync process..."
if [ ! -d "$REPO_DIR" ]; then
echo "[Git-Sync] ERROR: Repository directory $REPO_DIR does not exist."
exit 1
fi
# Trust the directory (fix for 'dubious ownership' in container)
git config --global --add safe.directory "$REPO_DIR"
cd "$REPO_DIR"
# Fetch and Pull
OUTPUT=$(git pull "$GIT_URL" "$BRANCH" 2>&1)
EXIT_CODE=$?
echo "[Git-Sync] Output: $OUTPUT"
if [ $EXIT_CODE -ne 0 ]; then
echo "[Git-Sync] ERROR: Git pull failed."
exit $EXIT_CODE
fi
if echo "$OUTPUT" | grep -q "Already up to date"; then
echo "[Git-Sync] No changes detected."
exit 0
else
echo "[Git-Sync] Changes detected. Validating Nginx config..."
if nginx -t; then
echo "[Git-Sync] Configuration valid. Reloading Nginx..."
nginx -s reload
echo "[Git-Sync] Reload successful."
else
echo "[Git-Sync] CRITICAL: Nginx configuration test failed! Not reloading."
exit 1
fi
fi