- Add scripts/deploy.sh for safe deployment with uploads preservation - Add scripts/cleanup_orphan_uploads.php to remove orphaned files - Add .gitkeep to uploads folder - Update .gitignore to exclude uploaded files but keep folder structure The deploy script now: - Backs up and restores .env file - Backs up and restores uploads folder contents - Runs database migrations automatically Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
64 lines
1.9 KiB
Bash
Executable File
64 lines
1.9 KiB
Bash
Executable File
#!/bin/bash
|
|
# TinkerTickets Deployment Script
|
|
# This script safely deploys updates while preserving user data
|
|
set -e
|
|
|
|
WEBROOT="/var/www/html/tinkertickets"
|
|
UPLOADS_BACKUP="/tmp/tinker_uploads_backup"
|
|
|
|
echo "[TinkerTickets] Starting deployment..."
|
|
|
|
# Backup .env if it exists
|
|
if [ -f "$WEBROOT/.env" ]; then
|
|
echo "[TinkerTickets] Backing up .env..."
|
|
cp "$WEBROOT/.env" /tmp/.env.backup
|
|
fi
|
|
|
|
# Backup uploads folder if it exists and has files
|
|
if [ -d "$WEBROOT/uploads" ] && [ "$(ls -A $WEBROOT/uploads 2>/dev/null)" ]; then
|
|
echo "[TinkerTickets] Backing up uploads folder..."
|
|
rm -rf "$UPLOADS_BACKUP"
|
|
cp -r "$WEBROOT/uploads" "$UPLOADS_BACKUP"
|
|
fi
|
|
|
|
if [ ! -d "$WEBROOT/.git" ]; then
|
|
echo "[TinkerTickets] Directory not a git repo — performing initial clone..."
|
|
rm -rf "$WEBROOT"
|
|
git clone https://code.lotusguild.org/LotusGuild/tinker_tickets.git "$WEBROOT"
|
|
else
|
|
echo "[TinkerTickets] Updating existing repo..."
|
|
cd "$WEBROOT"
|
|
git fetch --all
|
|
git reset --hard origin/main
|
|
fi
|
|
|
|
# Restore .env if it was backed up
|
|
if [ -f /tmp/.env.backup ]; then
|
|
echo "[TinkerTickets] Restoring .env..."
|
|
mv /tmp/.env.backup "$WEBROOT/.env"
|
|
fi
|
|
|
|
# Restore uploads folder if it was backed up
|
|
if [ -d "$UPLOADS_BACKUP" ]; then
|
|
echo "[TinkerTickets] Restoring uploads folder..."
|
|
# Don't overwrite .htaccess from repo
|
|
rsync -av --exclude='.htaccess' --exclude='.gitkeep' "$UPLOADS_BACKUP/" "$WEBROOT/uploads/"
|
|
rm -rf "$UPLOADS_BACKUP"
|
|
fi
|
|
|
|
# Ensure uploads directory exists with proper permissions
|
|
mkdir -p "$WEBROOT/uploads"
|
|
chmod 755 "$WEBROOT/uploads"
|
|
|
|
echo "[TinkerTickets] Setting permissions..."
|
|
chown -R www-data:www-data "$WEBROOT"
|
|
|
|
# Run migrations if .env exists
|
|
if [ -f "$WEBROOT/.env" ]; then
|
|
echo "[TinkerTickets] Running database migrations..."
|
|
cd "$WEBROOT/migrations"
|
|
php run_migrations.php || echo "[TinkerTickets] Warning: Migration errors occurred"
|
|
fi
|
|
|
|
echo "[TinkerTickets] Deployment complete!"
|