Skip to content

Commit

Permalink
Update generate_cert.sh to accept env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
pnedkov committed Dec 24, 2023
1 parent fafbdba commit 3efa74b
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions resources/generate_cert.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
#!/bin/bash

# Directory where the certificate and key will be stored
CERT_DIR="$HOME/.nginx"

# Certificate and key configuration
ALG_NAME="rsa"
ALG_SIZE="4096"
DAYS="3650"
CN="ip.aumaton.com"
# Key and certificate configuration
ALG_NAME=${ALG_NAME:-rsa}
ALG_SIZE=${ALG_SIZE:-4096}
DAYS=${DAYS:-3650}
CN=${CN:-ip.aumaton.com}

# Directory where the key and certificate will be stored
CERT_DIR="$HOME/.nginx"

# Check if the directory exists, create if not
# Make sure CERT_DIR exists
if [ ! -d "$CERT_DIR" ]; then
mkdir -p "$CERT_DIR"
fi

# Set the filenames
CERT_FILE="$CERT_DIR/cert.pem"
KEY_FILE="$CERT_DIR/key.pem"
CERT_FILE="$CERT_DIR/cert.pem"

# Generate the key and certificate
openssl req -x509 -newkey $ALG_NAME:$ALG_SIZE -keyout "$KEY_FILE" -out "$CERT_FILE" -days $DAYS -nodes -subj "/CN=$CN"

echo "Certificate and key have been generated in $CERT_DIR"
echo "Key and certificate have been generated in $CERT_DIR"

0 comments on commit 3efa74b

Please sign in to comment.