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