Files
discourse-themes/deploy.sh
T

68 lines
2.2 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# deploy.sh - Deploy and Sync Discourse Themes
# Domains: info-board.win / w-make.org
# Target Host: free-warez.win -> Discourse Container (app)
set -euo pipefail
TARGET_HOST="free-warez.win"
LOCAL_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
THEMES_DIR="$LOCAL_DIR/themes"
echo "🚀 Discourse Theme Deploy & Sync Manager"
echo " Target Host: $TARGET_HOST (Discourse container 'app')"
echo "========================================================="
# 1. Check SSH connection
echo "📡 Checking SSH connection to $TARGET_HOST..."
if ! ssh -q -o BatchMode=yes -o ConnectTimeout=5 "$TARGET_HOST" exit; then
echo "❌ Cannot connect to $TARGET_HOST via SSH."
exit 1
fi
THEME_ID="${1:-39}"
if [ "$THEME_ID" = "39" ]; then
SCSS_FILE="$THEMES_DIR/39_w-make_theme/common_scss.scss"
if [ ! -f "$SCSS_FILE" ]; then
SCSS_FILE="$THEMES_DIR/w-make-theme.scss"
fi
echo "🔄 Deploying W-MAKE Theme (ID: 39) from $SCSS_FILE..."
scp "$SCSS_FILE" "$TARGET_HOST:/tmp/w-make-theme.scss"
ssh "$TARGET_HOST" 'docker exec -i app su - discourse -c "psql -d discourse" << "SQL"
UPDATE theme_fields
SET value = pg_read_file('\''/tmp/w-make-theme.scss'\'')
WHERE theme_id = 39 AND name = '\''scss'\'';
UPDATE themes
SET updated_at = NOW()
WHERE id = 39;
SQL
rm -f /tmp/w-make-theme.scss
'
elif [ "$THEME_ID" = "41" ]; then
echo "🔄 Deploying Air Theme (ID: 41) common SCSS..."
SCSS_FILE="$THEMES_DIR/41_air_theme/common_scss.scss"
scp "$SCSS_FILE" "$TARGET_HOST:/tmp/air-theme.scss"
ssh "$TARGET_HOST" 'docker exec -i app su - discourse -c "psql -d discourse" << "SQL"
UPDATE theme_fields
SET value = pg_read_file('\''/tmp/air-theme.scss'\'')
WHERE theme_id = 41 AND name = '\''scss'\'' AND target_id = 0;
UPDATE themes
SET updated_at = NOW()
WHERE id = 41;
SQL
rm -f /tmp/air-theme.scss
'
else
echo "ℹ️ Custom theme ID: $THEME_ID provided."
fi
# Invalidate cache & recompile
echo "🔄 Clearing Discourse theme cache..."
ssh "$TARGET_HOST" 'docker exec -i app su - discourse -c "bundle exec rails runner \"Theme.find_by(id: $THEME_ID)&.changed_fields&.clear; Discourse.cache.clear\" 2>/dev/null || true"'
echo "✅ Discourse theme(s) updated successfully!"
echo "✨ Deployment complete!"