Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-27 07:41:44

0001 #!/bin/bash
0002 # Set up Apache vhost and Let's Encrypt for epic-devcloud.org.
0003 # Run once after DNS A record points to this server.
0004 
0005 set -euo pipefail
0006 
0007 SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
0008 REPO_DIR="$(dirname "$SCRIPT_DIR")"
0009 DEPLOY_DIR="/var/www/swf-remote"
0010 SWF_MONITOR_DEV="/home/admin/github/swf-monitor"
0011 SWF_MONITOR_PROD="/var/www/swf-monitor"
0012 DOMAIN="epic-devcloud.org"
0013 
0014 echo "=== Apache setup for $DOMAIN ==="
0015 
0016 # ── Deploy directories ─────────────────────────────────────────────────────
0017 
0018 for dir in "$DEPLOY_DIR" "$SWF_MONITOR_PROD"; do
0019     if [ ! -d "$dir" ]; then
0020         sudo mkdir -p "$dir"
0021         sudo chown admin:admin "$dir"
0022         echo "Created $dir"
0023     fi
0024 done
0025 
0026 # ── Rsync swf-monitor to production ────────────────────────────────────────
0027 
0028 rsync -a --delete \
0029     --exclude '.git' \
0030     --exclude '.venv' \
0031     --exclude '__pycache__' \
0032     --exclude '.env' \
0033     "$SWF_MONITOR_DEV/" "$SWF_MONITOR_PROD/"
0034 echo "swf-monitor synced to $SWF_MONITOR_PROD"
0035 
0036 # ── Rsync swf-remote to production ─────────────────────────────────────────
0037 
0038 rsync -a --delete \
0039     --exclude '.git' \
0040     --exclude '.venv' \
0041     --exclude '__pycache__' \
0042     --exclude 'src/.env' \
0043     --exclude 'staticfiles' \
0044     --exclude 'src/monitor_templates' \
0045     "$REPO_DIR/" "$DEPLOY_DIR/"
0046 echo "swf-remote synced to $DEPLOY_DIR"
0047 
0048 # ── Venv and deps ───────────────────────────────────────────────────────────
0049 
0050 if [ ! -d "$DEPLOY_DIR/.venv" ]; then
0051     python3 -m venv "$DEPLOY_DIR/.venv"
0052 fi
0053 "$DEPLOY_DIR/.venv/bin/pip" install -q -r "$DEPLOY_DIR/requirements/prod.txt"
0054 echo "Dependencies installed"
0055 
0056 # ── Setup symlinks (templates, static from swf-monitor) ─────────────────────
0057 
0058 export SWF_MONITOR="$SWF_MONITOR_PROD"
0059 bash "$DEPLOY_DIR/setup-dev.sh"
0060 
0061 # ── .env ────────────────────────────────────────────────────────────────────
0062 
0063 if [ ! -f "$DEPLOY_DIR/src/.env" ]; then
0064     SECRET_KEY=$(python3 -c "import secrets; print(secrets.token_urlsafe(50))")
0065     cat > "$DEPLOY_DIR/src/.env" <<EOF
0066 SWF_REMOTE_SECRET_KEY=$SECRET_KEY
0067 SWF_REMOTE_DEBUG=False
0068 SWF_REMOTE_ALLOWED_HOSTS=$DOMAIN,www.$DOMAIN,localhost
0069 
0070 SWF_REMOTE_DB_NAME=swf_remote
0071 SWF_REMOTE_DB_USER=swf_remote
0072 SWF_REMOTE_DB_PASSWORD=swf_remote
0073 SWF_REMOTE_DB_HOST=localhost
0074 SWF_REMOTE_DB_PORT=5432
0075 
0076 SWF_REMOTE_STATIC_URL=/static/
0077 SWF_REMOTE_MONITOR_URL=https://localhost:18443/swf-monitor
0078 EOF
0079     echo ".env created"
0080 else
0081     echo ".env exists"
0082 fi
0083 
0084 # ── Database ────────────────────────────────────────────────────────────────
0085 
0086 bash "$DEPLOY_DIR/setup-server.sh"
0087 
0088 # ── Collect static files ────────────────────────────────────────────────────
0089 
0090 cd "$DEPLOY_DIR/src"
0091 "$DEPLOY_DIR/.venv/bin/python" manage.py collectstatic --noinput
0092 echo "Static files collected"
0093 
0094 # ── Apache config ───────────────────────────────────────────────────────────
0095 
0096 sudo cp "$DEPLOY_DIR/deploy/epic-devcloud.conf" /etc/apache2/sites-available/
0097 sudo a2ensite epic-devcloud.conf
0098 sudo systemctl reload apache2
0099 echo "Apache configured and reloaded"
0100 
0101 # ── SSL certificate ─────────────────────────────────────────────────────────
0102 
0103 echo ""
0104 echo "To add HTTPS (after DNS is pointing here):"
0105 echo "  sudo certbot --apache -d $DOMAIN"
0106 echo ""
0107 echo "=== Setup complete ==="
0108 echo "Site: http://$DOMAIN/"