-
Notifications
You must be signed in to change notification settings - Fork 4
/
unix.sh
69 lines (60 loc) · 1.93 KB
/
unix.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
#!/bin/bash
set -eu -o pipefail -E
#================================================================
AUTHKEY=__AUTHKEY__
#================================================================
function cleanup() {
set +e
trap - SIGINT SIGTERM ERR
echo "Cleaning up..."
sudo "$INSTALL_DIR/tailscale" logout >/dev/null 2>&1
sudo pkill Tailscale
sudo pkill tailscale
sudo pkill tailscaled
rm -r "$INSTALL_DIR" >/dev/null 2>&1
rm -r /var/lib/tailscale/ >/dev/null 2>&1
rm -d /run/tailscale/ >/dev/null 2>&1
echo "Done!"
}
function error() {
error_code=$?
echo "There was an error!"
cleanup
exit $error_code
}
trap error SIGINT SIGTERM ERR
echo "Stopping any existing instances of TailScale..."
sudo pkill Tailscale || true
sudo pkill tailscale || true
sudo pkill tailscaled || true
rm -r /var/lib/tailscale/ >/dev/null 2>&1 || true
rm -d /run/tailscale/ >/dev/null 2>&1 || true
echo "Loading TailScale..."
PAYLOAD_LINE=$(awk '/^__PAYLOAD_BEGINS__/ { print NR + 1; exit 0; }' "$0")
INSTALL_DIR="/tmp/tsbolt-kg93j1"
mkdir -p "$INSTALL_DIR"
tail -n +"$PAYLOAD_LINE" "$0" | base64 -d | tar -xzp -C "$INSTALL_DIR"
sudo "$INSTALL_DIR/tailscaled" >/dev/null 2>&1 &
echo "Starting VPN..."
echo "If nothing happens, close this script and restart it."
echo "If the issue persists, your auth key is likely invalid."
sudo "$INSTALL_DIR/tailscale" up --authkey "$AUTHKEY" --reset >/dev/null 2>&1
echo "VPN successfully initialized."
echo
echo "Your IP:"
echo
sudo "$INSTALL_DIR/tailscale" ip
echo
echo "Status:"
echo
sudo "$INSTALL_DIR/tailscale" status
echo
echo "If you need to access the CLI, it can be found here:"
echo "$INSTALL_DIR/tailscale"
echo
echo "When you are done, continue to remove TailScale."
read -n 1 -s -r -p $'Press any key to continue...\n'
cleanup
exit 0
#========================================================================================================================================
__PAYLOAD_BEGINS__