64 lines
1.8 KiB
Bash
Executable File
64 lines
1.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Upload www/ directory to server using rsync
|
|
# Usage: ./upload_www.sh
|
|
|
|
SERVER="ubuntu@laantungir.net"
|
|
FINAL_PATH="/var/www/html/client"
|
|
SOURCE_DIR="www"
|
|
TEMP_PATH="~/www-temp"
|
|
|
|
echo "📦 Syncing www/ directory to server with rsync..."
|
|
echo ""
|
|
|
|
# Check if www directory exists
|
|
if [ ! -d "$SOURCE_DIR" ]; then
|
|
echo "❌ Error: $SOURCE_DIR directory not found."
|
|
exit 1
|
|
fi
|
|
|
|
# Count files to sync
|
|
file_count=$(find "$SOURCE_DIR" -type f | wc -l)
|
|
echo "📁 Found $file_count files to sync"
|
|
echo ""
|
|
|
|
# Use rsync to upload files to temp directory
|
|
# -a: archive mode (preserves permissions, timestamps, etc.)
|
|
# -v: verbose
|
|
# -z: compress during transfer
|
|
# --progress: show progress
|
|
# --delete: delete files on destination that don't exist in source
|
|
echo "📤 Syncing $SOURCE_DIR to server..."
|
|
rsync -avz --progress --delete "$SOURCE_DIR/" "$SERVER:$TEMP_PATH/"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo "✅ Files synced to temp directory"
|
|
else
|
|
echo "❌ Failed to sync files"
|
|
exit 1
|
|
fi
|
|
|
|
# Move files to final location with sudo and set www-data ownership
|
|
echo ""
|
|
echo "📁 Moving files to $FINAL_PATH and setting permissions..."
|
|
ssh $SERVER "sudo mkdir -p $FINAL_PATH && sudo rsync -a --delete $TEMP_PATH/ $FINAL_PATH/ && sudo chown -R www-data:www-data $FINAL_PATH && sudo chmod -R 644 $FINAL_PATH/* && sudo find $FINAL_PATH -type d -exec chmod 755 {} \;"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo "✅ Files moved to final location with www-data ownership"
|
|
else
|
|
echo "❌ Failed to move files to final location"
|
|
exit 1
|
|
fi
|
|
|
|
# Clean up temp directory
|
|
ssh $SERVER "rm -rf $TEMP_PATH"
|
|
|
|
echo ""
|
|
echo "✅ All files synced successfully!"
|
|
echo ""
|
|
echo "🌐 Application available at:"
|
|
echo " https://laantungir.net/client/"
|
|
echo ""
|
|
echo "📋 Files synced:"
|
|
find "$SOURCE_DIR" -type f | sed "s|^$SOURCE_DIR/| - |"
|