..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70 | #!/bin/bash
# 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
|
|