updated deploy logc

This commit is contained in:
2025-06-24 21:02:20 +01:00
parent 38f373afb8
commit 8e450a9f25

View File

@@ -1,7 +1,7 @@
#!/bin/bash
# ==============================================================================
# NGINX CONFIG & SSL DEPLOYMENT SCRIPT (v4)
# NGINX CONFIG & SSL DEPLOYMENT SCRIPT (v5)
#
# This script securely copies NGINX configuration files, tests the config,
# reloads Nginx, and then automates running Certbot to issue SSL certificates
@@ -10,13 +10,15 @@
# INSTRUCTIONS:
# 1. Ensure Certbot is installed on the remote server.
# (e.g., `sudo apt install certbot python3-certbot-nginx`)
# 2. Make the script executable: chmod +x <script_name>.sh
# 3. Run the script: ./<script_name>.sh
# 2. Update the CERTBOT_EMAIL variable below.
# 3. Make the script executable: chmod +x <script_name>.sh
# 4. Run the script: ./<script_name>.sh
# ==============================================================================
# --- Configuration ---
REMOTE_USER="ubuntu" # The user you SSH in with (e.g., ubuntu, ec2-user)
REMOTE_HOST="3.9.182.122" # The IP address or domain of your server
CERTBOT_EMAIL="your-email@example.com" # Email for Let's Encrypt account
# --- File & Path Definitions ---
KEY_FILE="~/repos/azeem-macbookair.pem"
@@ -52,11 +54,11 @@ if [ ! -d "$SOURCE_SITES_DIR" ]; then
exit 1
fi
# --- Local Operations: Find all domains ---
echo "-> Scanning local 'sites-available' for domain names..."
# This command finds all 'server_name' lines, removes the directive and semicolon,
# and consolidates all domains onto a single line.
ALL_DOMAINS=$(grep -r "server_name" "$SOURCE_SITES_DIR" | sed 's/.*server_name\s*//' | sed 's/;//' | tr '\n' ' ' | sed 's/ *$//')
# --- Local Operations: Find all unique domains ---
echo "-> Scanning local 'sites-available' for unique domain names..."
# This robust command finds all 'server_name' entries, handles multiple domains
# per line, removes duplicates, and creates a clean, space-separated list.
ALL_DOMAINS=$(grep -r "server_name" "$SOURCE_SITES_DIR" | sed 's/.*server_name\s*//' | sed 's/;//' | xargs -n1 | sort -u | tr '\n' ' ' | sed 's/ *$//')
if [ -z "$ALL_DOMAINS" ]; then
echo "⚠️ WARNING: No domains found in 'sites-available' config files. Skipping Certbot step later."
@@ -109,7 +111,6 @@ if [ $? -ne 0 ]; then
echo "You may need to log in manually to fix it: ssh -i $EVAL_KEY_FILE ${REMOTE_USER}@${REMOTE_HOST}"
exit 1
fi
echo " ✅ Files moved and configuration test passed."
echo
@@ -131,10 +132,9 @@ if [ -n "$ALL_DOMAINS" ]; then
# Format domains for the certbot command (-d domain1 -d domain2 etc.)
CERTBOT_DOMAINS=$(echo "$ALL_DOMAINS" | sed 's/ / -d /g' | sed 's/^/-d /')
echo "- Running Certbot on the server. This may require interaction..."
# Note: You may need to provide an email and agree to terms on the first run.
echo "- Running Certbot on the server. This may require interaction on the first run..."
ssh -t -i "$EVAL_KEY_FILE" "${REMOTE_USER}@${REMOTE_HOST}" \
"sudo certbot --nginx --non-interactive --agree-tos --email your-email@example.com --redirect $CERTBOT_DOMAINS"
"sudo certbot --nginx --non-interactive --agree-tos --email $CERTBOT_EMAIL --redirect $CERTBOT_DOMAINS"
if [ $? -eq 0 ]; then
echo " ✅ Certbot process completed."