From 34499804094dea5ab9be609b4134254038ec4b7f Mon Sep 17 00:00:00 2001 From: Bobby Date: Thu, 20 Jul 2023 02:47:57 -0400 Subject: local dev on `peek` subdomain --- runserver.sh | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) (limited to 'runserver.sh') diff --git a/runserver.sh b/runserver.sh index 48583d3b..5a84a06c 100755 --- a/runserver.sh +++ b/runserver.sh @@ -1,3 +1,70 @@ #!/bin/bash -lt -p 8000 -s thatcomputerscientist & python3 manage.py runserver && fg \ No newline at end of file +# Function to check if mkcert is installed +check_mkcert_installed() { + if ! command -v mkcert &> /dev/null; then + echo "mkcert is not installed. Installing mkcert..." + brew install mkcert # Assuming you're using Homebrew to install mkcert + fi +} + +# Function to check if the mkcert local CA is installed and install it if not present +check_and_install_local_ca() { + if ! mkcert -CAROOT &> /dev/null; then + echo "Installing mkcert local CA..." + mkcert -install + fi +} + +# Function to set the DOMAIN value in the .env file +set_domain_in_env() { + domain=$1 + sed -i "" "s/^DOMAIN=.*/DOMAIN='.${domain}'/" .env +} + +# Function to run the development server +run_dev_server() { + domain=$1 + cert_file="SSL/${domain}+1.pem" + key_file="SSL/${domain}+1-key.pem" + + if [[ -f "$cert_file" && -f "$key_file" ]]; then + set_domain_in_env "$domain" + sudo python3 manage.py runsslserver 127.0.0.1:443 --certificate "$cert_file" --key "$key_file" + else + echo "Certificate files not found. Generating self-signed certificate..." + mkdir -p SSL && cd SSL + mkcert "${domain}" "*.${domain}" + cd .. + set_domain_in_env "$domain" + sudo python3 manage.py runsslserver 127.0.0.1:443 --certificate "$cert_file" --key "$key_file" + fi +} + +# Main script + +# Check if mkcert is installed and install if not present +check_mkcert_installed + +# Present options to the user +echo "Choose an option:" +echo "[1]: (*).[peek].shi.foo" +echo "[2]: (*).[peek].thatcomputerscientist.com" +read -p "Enter your choice (1 or 2): " choice + +case $choice in + 1) + domain="peek.shi.foo" + check_and_install_local_ca + run_dev_server "$domain" + ;; + 2) + domain="peek.thatcomputerscientist.com" + check_and_install_local_ca + run_dev_server "$domain" + ;; + *) + echo "Invalid choice. Exiting..." + exit 1 + ;; +esac -- cgit v1.2.3