Skip to content

Instantly share code, notes, and snippets.

@haron
Last active February 6, 2025 19:54
Show Gist options
  • Save haron/8b2a6244e124766ee0d6396389ac7f34 to your computer and use it in GitHub Desktop.
Save haron/8b2a6244e124766ee0d6396389ac7f34 to your computer and use it in GitHub Desktop.
Bash script to install Tailscale in unsupported countries (in case if you get HTTP 451 while trying to download package)

This is a bash script to install and upgrade Tailscale in unsupported countries — in case if you get HTTP 451 while trying to download package. Works at least on Ubuntu 22.04 (but probably with Debian and other Ubuntu versions as well).

Usage:

git clone https://gist.github.com/8b2a6244e124766ee0d6396389ac7f34.git tailscale-install-451 && cd tailscale-install-451
./tailscale-install-451.sh host1 host2 ...
#!/usr/bin/env bash
# bash unofficial strict mode:
set -euo pipefail
IFS=$'\n\t'
ARCH="${ARCH:-amd64}"
RELEASE="${RELEASE:-""}"
DISTRO="https://pkgs.tailscale.com/stable/tailscale_${RELEASE}_${ARCH}.tgz"
install() {
local HOST="$1"
ssh -T "$HOST" <<EOT
cp -f -a $REMOTE_DIR/tailscaled /usr/sbin/
cp -a $REMOTE_DIR/tailscale /usr/bin/
cp -a $REMOTE_DIR/systemd/tailscaled.defaults /etc/default/tailscaled
cp -a $REMOTE_DIR/systemd/tailscaled.service /etc/systemd/system/
if systemctl status tailscaled.service >/dev/null 2>&1; then
systemctl daemon-reload
systemctl restart tailscaled.service
else
echo 'net.ipv4.ip_forward = 1' | sudo tee /etc/sysctl.d/99-tailscale.conf
echo 'net.ipv6.conf.all.forwarding = 1' | sudo tee -a /etc/sysctl.d/99-tailscale.conf
sudo sysctl -p /etc/sysctl.d/99-tailscale.conf
systemctl daemon-reload
systemctl enable tailscaled.service
systemctl start tailscaled.service
sudo tailscale up --advertise-exit-node
fi
rm -rf tailscale_* tailscale.tgz
{
echo -n "tailscale version: "
tailscale --version | head -n1
echo -n "tailscaled version: "
tailscaled --version | head -n1
systemctl status tailscaled | grep Active:
} 2>&1 | sed "s/^/$HOST: /"
EOT
}
if [[ -z "$RELEASE" ]]; then
# looking for the latest available release, because there could be 1.64.2 as a latest
# release, but 1.64.0 only available for our platform
for VER in $(curl -sSf https://api.github.com/repos/tailscale/tailscale/releases | jq -r '.[].name | sub("^v"; "")'); do
DISTRO="https://pkgs.tailscale.com/stable/tailscale_${VER}_${ARCH}.tgz"
echo "-- checking if $DISTRO is available"
# range because pkgs.tailscale.com doesn't support HEAD requests :(
if curl -H "Range: bytes=0-0" -sSf "$DISTRO" 2>/dev/null; then
RELEASE="$VER"
break
fi
done
fi
REMOTE_DIR="tailscale_${RELEASE}_${ARCH}"
echo "-- downloading $DISTRO"
for HOST; do
curl -sSf "$DISTRO" | ssh "$HOST" 'cat > tailscale.tgz && tar zxf tailscale.tgz' &
done
wait
echo "-- installing tailscale"
for HOST; do
install "$HOST" &
done
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment