-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-cloudflared.sh
executable file
·53 lines (43 loc) · 1.57 KB
/
setup-cloudflared.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
#!/bin/sh
# Define error_exit function
error_exit() {
echo "$1" 1>&2
exit 1
}
# Check if cloudflared is installed
if ! which cloudflared > /dev/null 2>&1; then
# Update package list and install dependencies
apt-get update || error_exit "Failed to update package list"
apt-get install -y curl || error_exit "Failed to install curl"
# Download and install the Cloudflare Tunnel package
curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-arm -o /usr/local/bin/cloudflared || error_exit "Failed to download cloudflared"
chmod +x /usr/local/bin/cloudflared || error_exit "Failed to make cloudflared executable"
# Verify the installation
cloudflared --version || error_exit "Failed to verify cloudflared installation"
else
echo "cloudflared is already installed";
fi
# Create a configuration directory for cloudflared
mkdir -p /etc/cloudflared || error_exit "Failed to create cloudflared configuration directory"
# Verify VAR1 is set
if [ -z "${VAR1}" ]; then
error_exit "VAR1 is not set. Please set the tunnel ID variable.";
fi
# Clear out the service and redo it
rm /etc/systemd/system/cloudflared.service;
cat <<EOF > /etc/systemd/system/cloudflared.service
[Unit]
Description=Cloudflare Tunnel
After=network.target
[Service]
Type=simple
User=nobody
ExecStart=/usr/local/bin/cloudflared tunnel run
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload;
cloudflared service uninstall;
cloudflared service install $VAR1;
echo "Cloudflare Tunnel installation completed successfully"