aboutsummaryrefslogtreecommitdiff
path: root/runserver.sh
diff options
context:
space:
mode:
authorBobby <[email protected]>2023-07-20 02:47:57 -0400
committerBobby <[email protected]>2023-07-20 02:47:57 -0400
commit34499804094dea5ab9be609b4134254038ec4b7f (patch)
tree75ff099fed0083f4b9530ef2d60f3a37b44eeb53 /runserver.sh
parent052fdcb685ac1f5a15d01048c07c201b8e762d2f (diff)
downloadthatcomputerscientist-34499804094dea5ab9be609b4134254038ec4b7f.tar.xz
thatcomputerscientist-34499804094dea5ab9be609b4134254038ec4b7f.zip
local dev on `peek` subdomain
Diffstat (limited to 'runserver.sh')
-rwxr-xr-xrunserver.sh69
1 files changed, 68 insertions, 1 deletions
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