Skip to content

Instantly share code, notes, and snippets.

@onequbit
Created September 2, 2025 13:38
Show Gist options
  • Save onequbit/f81e42285fc880c79aaa0216af7fc76b to your computer and use it in GitHub Desktop.
Save onequbit/f81e42285fc880c79aaa0216af7fc76b to your computer and use it in GitHub Desktop.

Revisions

  1. onequbit created this gist Sep 2, 2025.
    32 changes: 32 additions & 0 deletions new_certs.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    #!/bin/bash

    # This script generates a self-signed SSL certificate if one doesn't already exist.

    CERT_DIR="./certs"
    CERT_KEY_FILE="$CERT_DIR/localhost.key"
    CERT_PUBLIC_FILE="$CERT_DIR/localhost.crt"
    CERT_DOMAIN="localhost"
    CERT_STATE="Spira"
    CERT_LOCALITY="Besaid"
    CERT_ORGANIZATION="Aurochs"

    # Create the certificate directory if it doesn't exist
    if [ ! -d "$CERT_DIR" ]; then
    echo "Creating certificate directory: $CERT_DIR"
    mkdir -p "$CERT_DIR"
    fi

    # Check if the certificate and key files already exist
    if [ -f "$CERT_KEY_FILE" ] && [ -f "$CERT_PUBLIC_FILE" ]; then
    echo "SSL certificate and key already exist. Skipping generation."
    else
    echo "Generating self-signed SSL certificate for $CERT_DOMAIN..."
    openssl req -x509 -nodes -newkey rsa:2048 -keyout "$CERT_KEY_FILE" -out "$CERT_PUBLIC_FILE" -days 365 \
    -subj "/C=US/ST=$CERT_STATE/L=$CERT_LOCALITY/O=$CERT_ORGANIZATION/CN=$CERT_DOMAIN"
    echo "Certificate and key generated successfully."
    fi

    # Set appropriate permissions for the key file
    chmod 600 "$CERT_KEY_FILE"

    echo "Script finished."