71 lines
1.9 KiB
Bash
Executable File
71 lines
1.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# deploy.sh - Robust Discourse Theme Deploy & Sync Manager
|
|
# Domain: 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"
|
|
|
|
THEME_ID="${1:-41}"
|
|
echo "🚀 Discourse Theme Deploy & Sync Manager"
|
|
echo " Target Theme ID: $THEME_ID"
|
|
echo "========================================================="
|
|
|
|
if [ "$THEME_ID" = "41" ]; then
|
|
SCSS_FILE="$THEMES_DIR/41_air_theme/common_scss.scss"
|
|
TARGET_ID=0
|
|
FIELD_NAME="scss"
|
|
elif [ "$THEME_ID" = "39" ]; then
|
|
SCSS_FILE="$THEMES_DIR/39_w-make_theme/common_scss.scss"
|
|
TARGET_ID=0
|
|
FIELD_NAME="scss"
|
|
else
|
|
echo "Usage: ./deploy.sh [41|39]"
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -f "$SCSS_FILE" ]; then
|
|
echo "❌ Theme file $SCSS_FILE not found."
|
|
exit 1
|
|
fi
|
|
|
|
echo "🔄 Updating Theme $THEME_ID ($FIELD_NAME, target: $TARGET_ID)..."
|
|
python3 - << PYEOF
|
|
import subprocess
|
|
|
|
with open('$SCSS_FILE', 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
|
|
hex_data = content.encode('utf-8').hex()
|
|
|
|
sql = f"""
|
|
UPDATE theme_fields
|
|
SET value = convert_from(decode('{hex_data}', 'hex'), 'UTF8')
|
|
WHERE theme_id = $THEME_ID AND name = '$FIELD_NAME' AND target_id = $TARGET_ID;
|
|
|
|
UPDATE themes SET updated_at = NOW() WHERE id = $THEME_ID;
|
|
"""
|
|
|
|
p = subprocess.run(
|
|
['ssh', '$TARGET_HOST', 'docker exec -i app su - discourse -c "psql -d discourse"'],
|
|
input=sql,
|
|
capture_output=True,
|
|
text=True
|
|
)
|
|
|
|
if p.returncode != 0:
|
|
print("Error:", p.stderr)
|
|
exit(1)
|
|
else:
|
|
print(p.stdout.strip())
|
|
PYEOF
|
|
|
|
echo "🔄 Reloading Unicorn workers to recompile theme assets immediately..."
|
|
ssh "$TARGET_HOST" 'docker exec app sv restart unicorn 2>/dev/null || docker exec app /usr/bin/supervisorctl restart unicorn 2>/dev/null || docker restart app'
|
|
|
|
echo "✅ Theme $THEME_ID deployed and recompiled!"
|
|
echo "✨ Deployment complete!"
|