2021-10-20 20:09:57 +10:00
|
|
|
#!/bin/bash
|
2024-02-05 09:46:59 +10:00
|
|
|
# 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.
|
2021-10-20 20:09:57 +10:00
|
|
|
|
2022-10-25 18:52:32 +10:00
|
|
|
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
|
|
|
|
|
2023-05-01 15:10:42 +10:00
|
|
|
# Prepare run dirs
|
2021-10-20 20:09:57 +10:00
|
|
|
if [ ! -d "/var/run/sshd" ]; then
|
|
|
|
mkdir -p /var/run/sshd
|
|
|
|
fi
|
|
|
|
|
2022-10-25 18:52:32 +10:00
|
|
|
# Set root password
|
|
|
|
echo "root:${PASSWORD}" | chpasswd
|
2021-10-20 20:09:57 +10:00
|
|
|
|
|
|
|
# Install routes
|
|
|
|
IFS=',' read -ra SUBNETS <<< "${ADVERTISE_ROUTES}"
|
|
|
|
for s in "${SUBNETS[@]}"; do
|
|
|
|
ip route add "$s" via "${CONTAINER_GATEWAY}"
|
|
|
|
done
|
|
|
|
|
2024-01-06 10:39:50 +10:00
|
|
|
# Perform an update if set
|
|
|
|
if [[ ! -z "${UPDATE_TAILSCALE+x}" ]]; then
|
|
|
|
/usr/local/bin/tailscale update --yes
|
|
|
|
fi
|
|
|
|
|
2023-06-18 13:58:03 +10:00
|
|
|
# Set login server for tailscale
|
|
|
|
if [[ -z "$LOGIN_SERVER" ]]; then
|
|
|
|
LOGIN_SERVER=https://controlplane.tailscale.com
|
2022-10-25 18:52:32 +10:00
|
|
|
fi
|
|
|
|
|
2024-12-23 10:22:57 +01:00
|
|
|
if [[ -n "$STARTUP_SCRIPT" ]]; then
|
|
|
|
bash "$STARTUP_SCRIPT" || exit $?
|
|
|
|
fi
|
|
|
|
|
2023-05-01 15:10:42 +10:00
|
|
|
# Start tailscaled and bring tailscale up
|
2023-08-29 16:31:18 +10:00
|
|
|
/usr/local/bin/tailscaled ${TAILSCALED_ARGS} &
|
2021-10-20 20:09:57 +10:00
|
|
|
until /usr/local/bin/tailscale up \
|
2024-01-14 20:42:03 +10:00
|
|
|
--reset --authkey="${AUTH_KEY}" \
|
|
|
|
--login-server "${LOGIN_SERVER}" \
|
2022-10-25 18:52:32 +10:00
|
|
|
--advertise-routes="${ADVERTISE_ROUTES}" \
|
|
|
|
${TAILSCALE_ARGS}
|
2021-10-20 20:09:57 +10:00
|
|
|
do
|
|
|
|
sleep 0.1
|
|
|
|
done
|
|
|
|
echo Tailscale started
|
|
|
|
|
|
|
|
# Start SSH
|
|
|
|
/usr/sbin/sshd -D
|
|
|
|
|
|
|
|
fg %1
|