BankliPlus/temparea/solarbank/manual-deploy.sh
2025-08-13 18:05:26 +02:00

160 lines
5.1 KiB
Bash
Executable File

#!/bin/bash
# SolarBank Manual Deployment Script
# This script will guide you through the deployment process
echo "======================================"
echo "SolarBank IoT Dashboard Deployment"
echo "======================================"
echo ""
echo "Server Details:"
echo "IP: 172.104.237.108"
echo "User: root"
echo "Password: 6eqWiHHX4bNTPg"
echo ""
echo "This script will guide you through the deployment process."
echo "You'll need to run some commands manually and enter the password when prompted."
echo ""
read -p "Press Enter to continue..."
echo ""
echo "Step 1: Uploading deployment package to server"
echo "Please run the following command and enter the password when prompted:"
echo ""
echo "scp solarbank-deployment.tar.gz root@172.104.237.108:/tmp/"
echo ""
read -p "Press Enter after you've uploaded the file..."
echo ""
echo "Step 2: Now we'll create a server setup script"
echo "Creating server-setup.sh..."
cat > server-setup.sh << 'EOF'
#!/bin/bash
echo "Starting SolarBank server setup..."
# Update system and install dependencies
echo "Updating system packages..."
apt update && apt upgrade -y
# Install Docker if not already installed
if ! command -v docker &> /dev/null; then
echo "Installing Docker..."
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
rm get-docker.sh
else
echo "Docker already installed"
fi
# Install Docker Compose if not already installed
if ! command -v docker-compose &> /dev/null; then
echo "Installing Docker Compose..."
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
else
echo "Docker Compose already installed"
fi
# Install other required packages
echo "Installing additional packages..."
apt install -y git curl wget htop ufw fail2ban python3 python3-pip
# Configure firewall
echo "Configuring firewall..."
ufw --force reset
ufw default deny incoming
ufw default allow outgoing
ufw allow ssh
ufw allow 80/tcp
ufw allow 443/tcp
ufw --force enable
# Create application directory
echo "Setting up application directory..."
mkdir -p /opt/solarbank
cd /opt/solarbank
# Extract application files
echo "Extracting application files..."
tar -xzf /tmp/solarbank-deployment.tar.gz
rm /tmp/solarbank-deployment.tar.gz
# Make scripts executable
chmod +x scripts/*.sh
# Create production environment file
echo "Creating production environment configuration..."
cp environment.prod.example .env.prod
# Generate secure keys
echo "Generating secure keys..."
SECRET_KEY=$(python3 -c "import secrets; print(secrets.token_urlsafe(32))")
JWT_SECRET_KEY=$(python3 -c "import secrets; print(secrets.token_urlsafe(32))")
DB_PASSWORD=$(python3 -c "import secrets; print(secrets.token_urlsafe(16))")
DB_ROOT_PASSWORD=$(python3 -c "import secrets; print(secrets.token_urlsafe(16))")
# Update .env.prod with generated values
sed -i "s/SECRET_KEY=.*/SECRET_KEY=$SECRET_KEY/" .env.prod
sed -i "s/JWT_SECRET_KEY=.*/JWT_SECRET_KEY=$JWT_SECRET_KEY/" .env.prod
sed -i "s/POSTGRES_PASSWORD=.*/POSTGRES_PASSWORD=$DB_PASSWORD/" .env.prod
sed -i "s/POSTGRES_INITDB_ROOT_PASSWORD=.*/POSTGRES_INITDB_ROOT_PASSWORD=$DB_ROOT_PASSWORD/" .env.prod
echo ""
echo "========================================"
echo "Server setup completed!"
echo "========================================"
echo ""
echo "Next steps:"
echo "1. Configure your domain in /opt/solarbank/.env.prod"
echo "2. Update the following values:"
echo " - DOMAIN_NAME=yourdomain.com (replace with your actual domain)"
echo " - EMAIL=your-email@domain.com (replace with your email)"
echo " - BACKEND_CORS_ORIGINS=[\"https://yourdomain.com\", \"https://www.yourdomain.com\"]"
echo " - REACT_APP_API_URL=https://yourdomain.com/api"
echo ""
echo "3. If you don't have a domain yet, you can use the server IP for testing:"
echo " - DOMAIN_NAME=172.104.237.108"
echo " - BACKEND_CORS_ORIGINS=[\"http://172.104.237.108\", \"https://172.104.237.108\"]"
echo " - REACT_APP_API_URL=http://172.104.237.108/api"
echo ""
echo "To edit the configuration:"
echo "nano /opt/solarbank/.env.prod"
echo ""
echo "After configuration, run:"
echo "cd /opt/solarbank && ./scripts/deploy.sh"
EOF
chmod +x server-setup.sh
echo ""
echo "Step 3: Upload the setup script to server"
echo "Run this command:"
echo ""
echo "scp server-setup.sh root@172.104.237.108:/tmp/"
echo ""
read -p "Press Enter after uploading..."
echo ""
echo "Step 4: Connect to server and run setup"
echo "Run these commands:"
echo ""
echo "ssh root@172.104.237.108"
echo "chmod +x /tmp/server-setup.sh"
echo "/tmp/server-setup.sh"
echo ""
echo "After the setup completes, you'll need to configure your domain."
echo "If you don't have a domain, you can use the IP address for testing."
echo ""
echo "To deploy without a domain (using IP only), after connecting to the server:"
echo "cd /opt/solarbank"
echo "nano .env.prod"
echo ""
echo "Change these lines:"
echo "DOMAIN_NAME=172.104.237.108"
echo "BACKEND_CORS_ORIGINS=[\"http://172.104.237.108\", \"https://172.104.237.108\"]"
echo "REACT_APP_API_URL=http://172.104.237.108/api"
echo ""
echo "Skip the SSL setup by running:"
echo "./scripts/deploy.sh --no-ssl"