forked from geph-official/geph5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-exit.sh
85 lines (68 loc) · 2.48 KB
/
deploy-exit.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
if [ -z "$AUTH_TOKEN" ]; then
read -p "Enter the auth_token: " auth_token
else
auth_token="$AUTH_TOKEN"
fi
echo -e "\033[1mUpdating package lists and installing dependencies\033[0m"
apt-get update
apt-get install -y curl jq
echo -e "\033[1mDownloading geph5-exit\033[0m"
curl -s https://artifacts.geph.io/musl-latest/geph5-exit -o /usr/local/bin/geph5-exit
chmod +x /usr/local/bin/geph5-exit
echo -e "\033[1mCreating configuration directory\033[0m"
mkdir -p /etc/geph5-exit
echo -e "\033[1mGenerating random port numbers\033[0m"
c2e_port=$((10000 + RANDOM % 55535))
b2e_port=$((10000 + RANDOM % 55535))
echo -e "\033[1mGetting country and city using ip-api.com\033[0m"
location_data=$(curl -s 'http://ip-api.com/json/')
country=$(echo "$location_data" | jq -r '.countryCode')
city=$(echo "$location_data" | jq -r '.city')
echo -e "\033[1mGenerating signing secret\033[0m"
dd if=/dev/random of=/etc/geph5-exit/signing.secret bs=1 count=32 2>/dev/null
chmod 600 /etc/geph5-exit/signing.secret
echo -e "\033[1mCreating configuration file\033[0m"
cat > /etc/geph5-exit/config.yaml <<EOL
broker:
url: https://broker.geph.io/
auth_token: $auth_token
c2e_listen: 0.0.0.0:$c2e_port
b2e_listen: 0.0.0.0:$b2e_port
country: $country
city: $city
signing_secret: /etc/geph5-exit/signing.secret
EOL
echo -e "\033[1mCreating systemd service file\033[0m"
cat > /etc/systemd/system/geph5-exit.service <<EOL
[Unit]
Description=Geph5 Exit
After=network.target
[Service]
ExecStart=/usr/local/bin/geph5-exit --config /etc/geph5-exit/config.yaml
Restart=always
[Install]
WantedBy=multi-user.target
EOL
echo -e "\033[1mCreating systemd timer file for upgrades\033[0m"
cat > /etc/systemd/system/geph5-exit-upgrade.timer <<EOL
[Unit]
Description=Geph5 Exit Upgrade Timer
[Timer]
OnCalendar=hourly
Persistent=true
[Install]
WantedBy=timers.target
EOL
echo -e "\033[1mCreating systemd service file for upgrades\033[0m"
cat > /etc/systemd/system/geph5-exit-upgrade.service <<EOL
[Unit]
Description=Geph5 Exit Upgrade Service
[Service]
Type=oneshot
ExecStart=/bin/bash -c 'curl -s https://artifacts.geph.io/musl-latest/geph5-exit -o /tmp/geph5-exit && if ! cmp -s /tmp/geph5-exit /usr/local/bin/geph5-exit; then mv /tmp/geph5-exit /usr/local/bin/geph5-exit && chmod +x /usr/local/bin/geph5-exit && systemctl restart geph5-exit; else rm /tmp/geph5-exit; fi'
EOL
echo -e "\033[1mReloading systemd and starting services\033[0m"
systemctl daemon-reload
systemctl enable --now geph5-exit
systemctl enable --now geph5-exit-upgrade.timer