@@ -9,19 +9,45 @@ echo " https://github.com/alec-hs/coder-cloudflare-setup"
9
9
echo
10
10
echo " ------------------------------------------------------------"
11
11
echo
12
- read -s -p " Please enter a password for Coder web GUI: " password
13
- echo
14
- echo
15
- read -p " Please enter your domain: " domain
16
- echo
17
- read -s -p " Please enter your Cloudflare API Token: " token
12
+ read -s -p " Enter a password for Coder web GUI: " password
13
+ echo
14
+ echo
15
+ echo " Enter root domain to access Code Server (not a subdomain): "
16
+ unset domain
17
+ until [[ $domain =~ ^[A-Za-z0-9-]+.([A-Za-z]{3,}| [A-Za-z]{2}.[A-Za-z]{2}| [A-Za-z]{2})$ ]] ; do
18
+ read -r domain
19
+ done
20
+ echo
21
+ echo " To allow port proxying, subdomain setup will be used. Please"
22
+ echo " enter a number from the below options. For more info:"
23
+ echo " https://github.com/alec-hs/coder-cloudflare-setup/#port-proxy"
24
+ echo
25
+ echo " 0 - wildcard record"
26
+ echo " 1 - specific ports"
27
+ echo
28
+ unset subOption
29
+ until [[ $subOption == @ (0| 1) ]] ; do
30
+ read -r -p " Your selection: " subOption
31
+ done
32
+ echo
33
+ echo " Enter your proxy domain, eg: mydomain.com"
34
+ read -p " Your domain: " proxyDomain
35
+ if [ $subOption == 1 ]
36
+ then
37
+ echo " Enter a space separated list of all the ports you need."
38
+ echo " eg: 80 8080 3000 8443"
39
+ read -p " Your ports: " ports
40
+ fi
41
+ echo
42
+ read -s -p " Enter your Cloudflare API Token: " token
18
43
echo
19
44
echo
20
45
echo " ------------------------------------------------------------"
21
46
echo
22
47
echo " Setting up Caddy and Coder services..."
23
48
echo
24
49
echo " ------------------------------------------------------------"
50
+ sleep 3
25
51
26
52
# Hash the password
27
53
hash=$( printf $password | sha256sum | cut -d' ' -f1)
@@ -47,6 +73,9 @@ curl -fsSL https://code-server.dev/install.sh | sh
47
73
# Download service file from repo
48
74
curl https://raw.githubusercontent.com/alec-hs/coder-cloudflare-setup/main/code-server.service --output /etc/systemd/system/code-server.service
49
75
76
+ # Update coder file with proxy domain
77
+ sed -i.bak " s/mydomain.com/$proxyDomain /" /etc/systemd/system/code-server.service
78
+
50
79
# Run Coder & run on boot
51
80
systemctl enable --now code-server
52
81
@@ -78,8 +107,20 @@ mv caddy /usr/bin
78
107
curl https://raw.githubusercontent.com/alec-hs/coder-cloudflare-setup/main/Caddyfile --output /etc/caddy/Caddyfile
79
108
80
109
# Update Caddyfile
81
- sed -i.bak " s/sub.mydomain.com/$domain /" /etc/caddy/Caddyfile
82
110
sed -i.bak " s/API_TOKEN/$token /" /etc/caddy/Caddyfile
111
+ if [ $subOption == 0 ]
112
+ then
113
+ caddyDomains=" $domain , *.$proxyDomain "
114
+ fi
115
+ if [ $subOption == 1 ]
116
+ then
117
+ proxyPorts=" ${ports// / .$proxyDomain , } "
118
+ proxyPorts=" $proxyPorts .$proxyDomain "
119
+ caddyDomains=" $domain , $proxyPorts "
120
+ fi
121
+ sed -i.bak " s/sub.mydomain.com/$caddyDomains /" /etc/caddy/Caddyfile
122
+
123
+
83
124
84
125
# Update Coder config in /home/coder/.config/code-server/config.yaml
85
126
sed -i.bak " s/password: .*/hashed-password: $hash /" /home/coder/.config/code-server/config.yaml
0 commit comments