#!/bin/sh
set -eu

AUTHKEY="${1:?usage: install.sh <authkey> <hostname>}"
HOSTNAME_TS="${2:?usage: install.sh <authkey> <hostname>}"

if [ "$(id -u)" -ne 0 ]; then
    echo "run as root" >&2
    exit 1
fi

apt-get update
apt-get install -y curl ca-certificates

curl -fsSL https://tailscale.com/install.sh | sh

systemctl enable --now tailscaled

tailscale up --auth-key="$AUTHKEY" --hostname="$HOSTNAME_TS" --ssh
