-
Notifications
You must be signed in to change notification settings - Fork 0
/
caddy-install.sh
69 lines (61 loc) · 1.96 KB
/
caddy-install.sh
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
#!/usr/bin/env bash
# Assume dns and other variables are set
# dns="codeserver.ase.sh"
# auth=true
# temp_password="appsec"
# Check if Caddy is installed
echo "Checking if Caddy is installed"
command -v caddy >/dev/null 2>&1 || { echo >&2 "Caddy not installed."; exit 1; }
echo "Caddy installed successfully."
# Ensure Caddy is stopped and disabled
sudo systemctl stop caddy
sudo systemctl disable caddy
# Fetch variables from caddy_templater.py
echo "Fetching caddy_templater.py"
wget -O caddy_templater.py https://raw.githubusercontent.com/we45/caddy-installer-ase/main/caddy_templater_new.py
chmod +x ./caddy_templater.py
echo "Fetching variables from caddy_templater.py"
while test $# -gt 0; do
case "$1" in
-dns)
shift
dns=$1
shift
;;
-temp_password)
shift
temp_password=$1
shift
;;
-auth)
shift
auth=$1
shift
;;
*)
echo "$1 is not a recognized flag!"
exit 1
;;
esac
done
# Check if DNS is empty
if [ -z "$dns" ]; then
echo "DNS is empty. Exiting."
exit 1
fi
echo "Variables fetched:"
echo "DNS : $dns"
# Generate Caddy hash if auth is true
if [ "$auth" = true ]; then
echo "PASSWORD : $temp_password"
echo "AUTHENTICATION : $auth"
echo "AUTH is true. Generating Caddy hash"
caddy_hash=$(/usr/bin/caddy hash-password --plaintext "$temp_password")
echo "caddy_hash: $caddy_hash"
sudo ./caddy_templater.py --dns "$dns" --auth "$auth" --password "$caddy_hash"
else
echo "AUTH is false."
sudo ./caddy_templater.py --dns "$dns"
fi
# Remove caddy_templater.py after use
rm caddy_templater.py