-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
71 lines (65 loc) · 2.15 KB
/
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
70
71
#!/bin/bash
apt update
apt install -y nginx certbot python3-certbot-nginx
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
apt-get install autoconf automake g++ libtool -y
apt-get install --install-recommends build-essential libtool-bin autoconf -y
curl -fsSL https://code-server.dev/install.sh | sh
## These values must be changed!
domainName=##
duckToken=##
letsEncryptEmail=##
## Install duckdns (Thanks for whoever wrote this script!)
userHome=$(eval echo ~${USER})
duckPath="$userHome/duckdns"
duckLog="$duckPath/duck.log"
duckScript="$duckPath/duck.sh"
# Main Install ***
mySubDomain="${domainName%%.*}"
duckDomain="${domainName#*.}"
if [ "$duckDomain" != "duckdns.org" ] && [ "$duckDomain" != "$mySubDomain" ] || [ "$mySubDomain" = "" ]
then
echo "[Error] Invalid domain name. Program will now quit."
exit 0
fi
# Create duck dir
if [ ! -d "$duckPath" ]
then
mkdir "$duckPath"
fi
# Create duck script file
echo "echo url=\"https://www.duckdns.org/update?domains=$mySubDomain&token=$duckToken&ip=\" | curl -k -o $duckLog -K -" > $duckScript
chmod 700 $duckScript
echo "Duck Script file created"
# Create Conjob
# Check if job already exists
checkCron=$( crontab -l | grep -c $duckScript )
if [ "$checkCron" -eq 0 ]
then
# Add cronjob
echo "Adding Cron job for Duck DNS"
crontab -l | { cat; echo "*/5 * * * * $duckScript"; } | crontab -
fi
# Test Setup
confirmCont=Y
if [ "$confirmCont" != "Y" ] && [ "$confirmCont" != "Yes" ] && [ "$confirmCont" != "" ] && [ "$confirmCont" != "y" ]
then
echo "Setup cancelled. Program will now quit."
exit 0
fi
# Run now
$duckScript
# Response
duckResponse=$( cat $duckLog )
echo "Duck DNS server response : $duckResponse"
if [ "$duckResponse" != "OK" ]
then
echo "[Error] Duck DNS did not update correctly. Please check your settings or run the setup again."
else
echo "Duck DNS setup complete."
fi
cp code-server /etc/nginx/sites-available/code-server
sudo ln -s ../sites-available/code-server /etc/nginx/sites-enabled/code-server
sudo certbot --non-interactive --redirect --agree-tos --nginx -d $domainName -m $letsEncryptEmail
systemctl restart nginx
sudo systemctl enable --now code-server@root