@@ -9,19 +9,45 @@ echo " https://github.com/alec-hs/coder-cloudflare-setup"
99echo
1010echo " ------------------------------------------------------------"
1111echo
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
1843echo
1944echo
2045echo " ------------------------------------------------------------"
2146echo
2247echo " Setting up Caddy and Coder services..."
2348echo
2449echo " ------------------------------------------------------------"
50+ sleep 3
2551
2652# Hash the password
2753hash=$( printf $password | sha256sum | cut -d' ' -f1)
@@ -47,6 +73,9 @@ curl -fsSL https://code-server.dev/install.sh | sh
4773# Download service file from repo
4874curl https://raw.githubusercontent.com/alec-hs/coder-cloudflare-setup/main/code-server.service --output /etc/systemd/system/code-server.service
4975
76+ # Update coder file with proxy domain
77+ sed -i.bak " s/mydomain.com/$proxyDomain /" /etc/systemd/system/code-server.service
78+
5079# Run Coder & run on boot
5180systemctl enable --now code-server
5281
@@ -78,8 +107,20 @@ mv caddy /usr/bin
78107curl https://raw.githubusercontent.com/alec-hs/coder-cloudflare-setup/main/Caddyfile --output /etc/caddy/Caddyfile
79108
80109# Update Caddyfile
81- sed -i.bak " s/sub.mydomain.com/$domain /" /etc/caddy/Caddyfile
82110sed -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+
83124
84125# Update Coder config in /home/coder/.config/code-server/config.yaml
85126sed -i.bak " s/password: .*/hashed-password: $hash /" /home/coder/.config/code-server/config.yaml
0 commit comments