#!/bin/bash # LuckyChit Flutter Web - Automated Full Deployment # This script builds AND deploys to production server # ============================================ # CONFIGURATION - UPDATE THESE VALUES # ============================================ # Server Configuration SERVER_USER="luckychit" # Your server username SERVER_HOST="your-server-ip" # Your server IP or domain WEB_DIR="/var/www/luckychit" # Web directory on server USE_PM2=false # Set to true if using PM2 instead of nginx PM2_APP_NAME="luckychit-web" # PM2 app name (if using PM2) # ============================================ # DEPLOYMENT SCRIPT - DO NOT EDIT BELOW # ============================================ echo "๐Ÿš€ LuckyChit Flutter Web - Auto Deployment" echo "===========================================" echo "" echo "๐Ÿ“‹ Configuration:" echo " Server: $SERVER_USER@$SERVER_HOST" echo " Target: $WEB_DIR" echo " Method: $([ "$USE_PM2" = true ] && echo 'PM2' || echo 'nginx')" echo "" # Check if we're in the right directory if [ ! -f "pubspec.yaml" ]; then echo "โŒ Error: pubspec.yaml not found!" echo "Please run this script from the luckychit directory" exit 1 fi # Clean and build echo "๐Ÿงน Step 1/4: Cleaning..." flutter clean echo "๐Ÿ“ฆ Step 2/4: Getting dependencies..." flutter pub get echo "๐Ÿ”จ Step 3/4: Building for web..." flutter build web --release if [ $? -ne 0 ]; then echo "โŒ Build failed!" exit 1 fi echo "โœ… Build successful!" echo "" # Deploy to server echo "๐Ÿ“ค Step 4/4: Deploying to production server..." echo "" if command -v rsync &> /dev/null; then # Use rsync (faster, incremental) echo "Using rsync for deployment..." rsync -avz --delete build/web/ $SERVER_USER@$SERVER_HOST:$WEB_DIR/ else # Fallback to scp echo "Using scp for deployment..." scp -r build/web/* $SERVER_USER@$SERVER_HOST:$WEB_DIR/ fi if [ $? -ne 0 ]; then echo "โŒ Deployment failed!" echo "Please check:" echo " - Server credentials are correct" echo " - You have SSH access to the server" echo " - Target directory exists and has write permissions" exit 1 fi echo "" echo "โœ… Files uploaded successfully!" # Restart service if using PM2 if [ "$USE_PM2" = true ]; then echo "" echo "๐Ÿ”„ Restarting PM2 service..." ssh $SERVER_USER@$SERVER_HOST "pm2 restart $PM2_APP_NAME" if [ $? -eq 0 ]; then echo "โœ… PM2 restarted successfully!" else echo "โš ๏ธ PM2 restart failed - you may need to restart manually" fi fi echo "" echo "==========================================" echo "๐ŸŽ‰ Deployment Complete!" echo "" echo "๐ŸŒ Your app should now be live with the latest changes" echo "" echo "๐Ÿ“ Important:" echo " - Users may need to clear browser cache (Ctrl+Shift+R)" echo " - Test the app in an incognito window first" echo "" echo "๐Ÿ” Monitor logs:" if [ "$USE_PM2" = true ]; then echo " ssh $SERVER_USER@$SERVER_HOST 'pm2 logs $PM2_APP_NAME'" else echo " ssh $SERVER_USER@$SERVER_HOST 'sudo tail -f /var/log/nginx/error.log'" fi echo ""