-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathtailscale.sh
executable file
·56 lines (45 loc) · 1.29 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
#!/bin/bash
# Copyright (c) 2024 Fluent Networks Pty Ltd & AUTHORS All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
set -m
# Enable IP forwarding
echo 'net.ipv4.ip_forward = 1' | tee -a /etc/sysctl.conf
echo 'net.ipv6.conf.all.forwarding = 1' | tee -a /etc/sysctl.conf
sysctl -p /etc/sysctl.conf
# Prepare run dirs
if [ ! -d "/var/run/sshd" ]; then
mkdir -p /var/run/sshd
fi
# Set root password
echo "root:${PASSWORD}" | chpasswd
# Install routes
IFS=',' read -ra SUBNETS <<< "${ADVERTISE_ROUTES}"
for s in "${SUBNETS[@]}"; do
ip route add "$s" via "${CONTAINER_GATEWAY}"
done
# Perform an update if set
if [[ ! -z "${UPDATE_TAILSCALE+x}" ]]; then
/usr/local/bin/tailscale update --yes
fi
# Set login server for tailscale
if [[ -z "$LOGIN_SERVER" ]]; then
LOGIN_SERVER=https://controlplane.tailscale.com
fi
if [[ -n "$STARTUP_SCRIPT" ]]; then
bash "$STARTUP_SCRIPT" || exit $?
fi
# Start tailscaled and bring tailscale up
/usr/local/bin/tailscaled ${TAILSCALED_ARGS} &
until /usr/local/bin/tailscale up \
--reset --authkey="${AUTH_KEY}" \
--login-server "${LOGIN_SERVER}" \
--advertise-routes="${ADVERTISE_ROUTES}" \
${TAILSCALE_ARGS}
do
sleep 0.1
done
echo Tailscale started
# Start SSH
/usr/sbin/sshd -D
fg %1