Skip to content

Commit

Permalink
Merge pull request #35 from Babbexx-22/feat-certbot-config-scrpt
Browse files Browse the repository at this point in the history
Feat: certbot config script
  • Loading branch information
vicradon authored Jul 19, 2024
2 parents a85a396 + fd32635 commit 01c140e
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions scripts/certbot_config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

# Variables
DOMAINS=(
"api-golang.boilerplate.hng.tech" # prod
"deployment.api-golang.boilerplate.hng.tech" # dev
"staging.api-golang.boilerplate.hng.tech" # staging
)
EMAIL="[email protected]" # Used for certbot notifications and recovery

# Update package lists
sudo apt update

# Install Snapd if not already installed
sudo apt install -y snapd

# Install the core snap & Ensure Snapd is up to date
sudo snap install core
sudo snap refresh core

# Remove any existing Certbot installations
sudo apt-get remove certbot

# Install Certbot using Snap
sudo snap install --classic certbot

# Create a symbolic link to make Certbot command globally available
sudo ln -s /snap/bin/certbot /usr/bin/certbot

# Obtain SSL certificates for each domain
for DOMAIN in "${DOMAINS[@]}"; do
echo "Configuring SSL for domain: $DOMAIN"
sudo certbot --nginx -d "$DOMAIN" --non-interactive --agree-tos --email "$EMAIL"
done

# Set up automatic renewal of the certificates
sudo crontab -l | { cat; echo "0 0,12 * * * root certbot renew --quiet"; } | sudo crontab -

# Display the configured domains
for DOMAIN in "${DOMAINS[@]}"; do
echo "SSL certificate configured for: https://$DOMAIN"
done

0 comments on commit 01c140e

Please sign in to comment.