72 lines
2.3 KiB
Bash
Executable File
72 lines
2.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
LOG_FILE="/var/log/hugo_sync.log"
|
|
SYNC_TO_PRO_LOG="/var/log/sync-to-pro.log"
|
|
|
|
# Run sync-to-pro first every time with logging
|
|
echo "🔄 Running sync-to-pro to update log... (logged to $SYNC_TO_PRO_LOG)"
|
|
/home/arul/auto-scripts/professional-site-scripts/sync-content-pro-site/sync-to-pro >> "$SYNC_TO_PRO_LOG" 2>&1
|
|
|
|
# Function for deployment chain
|
|
run_deployment_chain() {
|
|
echo "Changing directory to working path..."
|
|
cd /home/arul/auto-scripts/professional-site-scripts || {
|
|
echo "❌ Failed to cd to working directory."
|
|
exit 1
|
|
}
|
|
|
|
echo "1. 🚀 Generating summaries..."
|
|
python3 generate-summaries/summarize.py
|
|
|
|
echo "2. 📤 Syncing contents from personal site to professional site..."
|
|
sync-content-pro-site/sync-to-pro
|
|
|
|
echo "3. 🧐 Checking sync logs..."
|
|
sync-content-pro-site/check-sync-logs
|
|
|
|
echo "4. 🗺️ Generating redirect map..."
|
|
python3 redirect-site-upload-map/generate-nginx-map.py
|
|
|
|
echo "5. ☁️ Uploading map via SFTP..."
|
|
bash redirect-site-upload-map/upload-map.sftp.sh
|
|
|
|
echo "6. 🔄 Restarting Hugo Professional site to update latest contents on Local Home Server 🏠📰"
|
|
cd /var/www/html/professional-site/ && sudo hugo
|
|
|
|
echo "7. 🔃 Restarting reverse proxy tunnel in remote tunnel"
|
|
cd /home/arul/auto-scripts/professional-site-scripts && bash sync-content-pro-site/tunnel-reverseproxy-restart
|
|
|
|
echo "🎉 Deployment chain completed"
|
|
}
|
|
|
|
# Check log for latest sync status
|
|
if [ ! -f "$LOG_FILE" ]; then
|
|
echo "❌ Log file not found: $LOG_FILE"
|
|
exit 1
|
|
fi
|
|
|
|
LATEST_TIMESTAMP=$(tac "$LOG_FILE" | grep -m 1 -oP '^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}' | head -1)
|
|
|
|
if [ -z "$LATEST_TIMESTAMP" ]; then
|
|
echo "❌ Could not find any timestamp in the log."
|
|
exit 1
|
|
fi
|
|
|
|
LOG_BLOCK=$(awk -v ts="$LATEST_TIMESTAMP" '{
|
|
if ($0 ~ ts) start=1
|
|
if (start) print
|
|
}' "$LOG_FILE")
|
|
|
|
if echo "$LOG_BLOCK" | grep -q "✅ Synced files:"; then
|
|
echo "🔁 Changes detected in latest log block. Proceeding with deployment."
|
|
run_deployment_chain
|
|
exit 0
|
|
elif echo "$LOG_BLOCK" | grep -q "☑️ Already in sync. No changes needed."; then
|
|
echo "✅ No changes detected in latest log block. Skipping deployment."
|
|
exit 1
|
|
else
|
|
echo "⚠️ Could not determine sync status from latest log block."
|
|
exit 1
|
|
fi
|
|
|