54 lines
1.5 KiB
Bash
Executable File
54 lines
1.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# This script deploys the website to the VPS
|
|
|
|
# Load environment variables
|
|
if [ -f .env ]; then
|
|
source .env
|
|
else
|
|
echo "Error: .env file not found. Please create it based on .env.example."
|
|
exit 1
|
|
fi
|
|
|
|
# Check if sshpass is installed
|
|
if ! command -v sshpass &> /dev/null; then
|
|
echo "Error: sshpass is not installed. Please run ./install-sshpass.sh first."
|
|
exit 1
|
|
fi
|
|
|
|
# Set SSH and SCP commands with password
|
|
SSH_CMD="sshpass -p \"$SERVER_PASSWORD\" ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP"
|
|
SCP_CMD="sshpass -p \"$SERVER_PASSWORD\" scp -o StrictHostKeyChecking=no"
|
|
|
|
# Set variables
|
|
REMOTE_DIR="/var/www/boilerhaus.org"
|
|
LOCAL_DIR="."
|
|
|
|
# Create a temporary directory for the website files
|
|
echo "Creating temporary directory..."
|
|
mkdir -p ./deploy-temp
|
|
|
|
# Copy necessary files to the temporary directory
|
|
echo "Copying website files..."
|
|
cp -r index.html css dist ./deploy-temp/
|
|
|
|
# Create a tarball of the website files
|
|
echo "Creating tarball..."
|
|
tar -czf website.tar.gz -C ./deploy-temp .
|
|
|
|
# Upload the tarball to the server
|
|
echo "Uploading to server..."
|
|
eval "$SCP_CMD website.tar.gz $SERVER_USER@$SERVER_IP:/tmp/"
|
|
|
|
# Extract the tarball on the server
|
|
echo "Extracting files on server..."
|
|
eval "$SSH_CMD \"mkdir -p $REMOTE_DIR && \
|
|
tar -xzf /tmp/website.tar.gz -C $REMOTE_DIR && \
|
|
chown -R www-data:www-data $REMOTE_DIR && \
|
|
rm /tmp/website.tar.gz\""
|
|
|
|
# Clean up local files
|
|
echo "Cleaning up..."
|
|
rm -rf ./deploy-temp website.tar.gz
|
|
|
|
echo "Website deployed successfully!" |