forked from tailscale-dev/deck-tailscale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtailscale.sh
97 lines (71 loc) · 3.18 KB
/
tailscale.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
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env bash
# make system configuration vars available
source /etc/os-release
# set invocation settings for this script:
# -e: Exit immediately if a command exits with a non-zero status.
# -u: Treat unset variables as an error when substituting.
# -o pipefail: the return value of a pipeline is the status of the last command to exit with a non-zero status, or zero if no command exited with a non-zero status
set -eu -o pipefail
# save the current directory silently
pushd . > /dev/null
# make a temporary directory, save the name, and move into it
dir="$(mktemp -d)"
cd "${dir}"
echo -n "Getting version..."
# get info for the latest version of Tailscale
tarball="$(curl -s 'https://pkgs.tailscale.com/stable/?mode=json' | jq -r .Tarballs.amd64)"
version="$(echo ${tarball} | cut -d_ -f2)"
echo "got ${version}."
echo -n "Downloading..."
# download the Tailscale package itself
curl -s "https://pkgs.tailscale.com/stable/${tarball}" -o tailscale.tgz
echo "done."
echo -n "Installing..."
# extract the tailscale binaries
tar xzf tailscale.tgz
tar_dir="$(echo ${tarball} | cut -d. -f1-3)"
test -d $tar_dir
# create our target directory structure
mkdir -p tailscale/usr/{bin,sbin,lib/{systemd/system,extension-release.d}}
# pull things into the right place in the target dir structure
cp -rf $tar_dir/tailscale tailscale/usr/bin/tailscale
cp -rf $tar_dir/tailscaled tailscale/usr/sbin/tailscaled
# write a systemd extension-release file
echo -e "ID=steamos\nVERSION_ID=${VERSION_ID}" >> tailscale/usr/lib/extension-release.d/extension-release.tailscale
# create the system extension folder if it doesn't already exist, remove the old version of our tailscale extension, and install our new one
mkdir -p /var/lib/extensions
rm -rf /var/lib/extensions/tailscale
cp -rf tailscale /var/lib/extensions/
# copy the systemd files into place
cp -rf $tar_dir/systemd/tailscaled.service /etc/systemd/system
# copy in the defaults file if it doesn't already exist
if ! test -f /etc/default/tailscaled; then
cp -rf $tar_dir/systemd/tailscaled.defaults /etc/default/tailscaled
fi
# return to our original directory (silently) and clean up
popd > /dev/null
rm -rf "${dir}"
# copy in our overrides file if it doesn't already exist
if ! test -f /etc/systemd/system/tailscaled.service.d/override.conf; then
mkdir -p /etc/systemd/system/tailscaled.service.d
cp -rf override.conf /etc/systemd/system/tailscaled.service.d/override.conf
fi
echo "done."
echo "Starting required services..."
# systemd-sysext - manages system extensions
if systemctl is-enabled --quiet systemd-sysext && systemctl is-active --quiet systemd-sysext; then
echo "systemd-sysext is already enabled and active"
else
systemctl enable systemd-sysext --now # this should be all we need in every case, but something breaks if it's already enabled/running.
fi
systemd-sysext refresh > /dev/null 2>&1
echo "Done."
# tailscaled - the tailscale daemon
systemctl enable tailscaled
if systemctl is-active --quiet tailscaled; then
echo "Upgrade complete. Restarting tailscaled..."
else
echo "Install complete. Starting tailscaled..."
fi
systemctl restart tailscaled # This needs to be the last thing we do in case the user's running this over Tailscale SSH.
echo "Done."