Created
April 8, 2022 08:32
-
-
Save Maigre/3f51f3a22def14e88a8f3e585e2a9d65 to your computer and use it in GitHub Desktop.
Install Tailscale on GL.iNET router, using microSD/USB storage.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Tailscale install script on GL.iNet devices | |
# Tested on BERYL (MT1300), should work on MANGO (GL-MT300N) | |
# and probably other mipsel devices, as long as external storage (microSD/USB) | |
# is available. | |
# | |
# Written by Thomas BOHL for Hemisphere-Project - 2022 | |
# Free to use - No warranty provided | |
# | |
# Inspired by: | |
# https://bitsnbobs.kertho.me/en/posts/running-tailscale-on-a-mango-router/ | |
# https://blog.patshead.com/2020/10/tailscale-on-my-gl-dot-inet-mango-openwrt-router.html | |
# | |
# exit when any command fails | |
set -e | |
trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG | |
trap 'echo "\"${last_command}\" command filed with exit code $?."' EXIT | |
# Hello | |
# | |
echo ".:: Tailscale on GL.iNet Beryl/Mango ::.\n" | |
echo "Install Tailscale on Beryl using microSD/USB storage.\n" | |
echo "NOTE: you must insert a microSD/USB before starting." | |
echo "WARNING: the microSD/USB will be completly ERASED ! (Ctrl-C to abort)" | |
read -n 1 -p "= Press a key to continue or Ctrl-C to abort" D | |
echo "\n" | |
# Hostname | |
# | |
echo "Change device name" | |
read -p "= Hostname: " HOST_NAME | |
echo "\n" | |
if [[ ! -z "$HOST_NAME" ]] | |
then | |
uci set system.@system[0].hostname="$HOST_NAME" | |
uci commit system | |
/etc/init.d/system reload | |
fi | |
# Version | |
# | |
echo "Enter current tailscale version, something like 1.22 (see https://pkgs.tailscale.com/stable/#static)" | |
read -p "= Version: " TS_VERSION | |
echo "\n" | |
# Install tools | |
# | |
opkg update | |
opkg install curl ca-bundle kmod-tun | |
opkg install kmod-usb-storage kmod-usb-storage-uas usbutils block-mount | |
opkg install gdisk e2fsprogs kmod-fs-ext4 | |
# find microSD | |
# | |
echo -n "Finding microSD... " | |
DEVPATH="" | |
if [ -b "/dev/sda" ]; then | |
DEVPATH="/dev/sda" | |
PARTPATH="/dev/sda1" | |
elif [ -b "/dev/mmcblk0" ]; then | |
DEVPATH="/dev/mmcblk0" | |
PARTPATH="/dev/mmcblk0p1" | |
else | |
echo "" | |
echo "ERROR: can't find microSD /dev path" | |
#exit 1 | |
fi | |
echo "$DEVPATH" | |
# format microSD | |
# | |
( | |
echo o # Remove all partitions | |
echo Y # confirm | |
echo n # Add a new partition | |
echo # First partition (Accept default: 1) | |
echo # First sector (Accept default: 1) | |
echo # Last sector (Accept default: varies) | |
echo # HEX (Accept default: 8300) | |
echo w # Write changes | |
echo Y # confirm | |
) | gdisk $DEVPATH | |
( | |
echo y | |
) | mkfs.ext4 $PARTPATH | |
# Automount | |
# | |
block umount | |
block detect | uci import fstab | |
uci set fstab.@mount[-1].enabled='1' | |
uci commit fstab | |
block mount | |
# Link opt | |
mkdir -p /mnt/mmcblk0p1/opt/tailscale/state | |
mkdir -p /mnt/mmcblk0p1/opt/tailscale/logs | |
ln -s /mnt/mmcblk0p1/opt /opt | |
# Download / Extract Tailscale | |
TAILSCA=tailscale_"$TS_VERSION"_mipsle | |
mkdir -p /opt/tailscale/archive | |
cd /opt/tailscale/archive | |
curl -O https://pkgs.tailscale.com/stable/"$TAILSCA".tgz | |
tar x -zvf "$TAILSCA".tgz | |
mv "$TAILSCA"/* /opt/tailscale/ | |
ln -s /opt/tailscale/tailscale /usr/sbin/tailscale | |
ln -s /opt/tailscale/tailscaled /usr/sbin/tailscaled | |
# Startup script | |
echo "#!/bin/sh /etc/rc.common | |
USE_PROCD=1 | |
START=80 | |
STOP=01 | |
start_service() { | |
echo \"==== Starting tailscaled ====\" | |
/usr/sbin/tailscaled --cleanup | |
procd_open_instance | |
procd_set_param command /usr/sbin/tailscaled | |
procd_append_param command --port 41641 | |
procd_append_param command --state /opt/tailscale/state/tailscaled.state | |
procd_set_param respawn | |
procd_set_param stdout 1 | |
procd_set_param stderr 1 | |
procd_close_instance | |
} | |
stop_service() { | |
echo \"==== Stop tailscaled ====\" | |
/usr/sbin/tailscaled --cleanup | |
} | |
" > /etc/init.d/tailscale | |
chmod +x /etc/init.d/tailscale | |
/etc/init.d/tailscale enable | |
/etc/init.d/tailscale start | |
# Start tailscale | |
# tailscale up --advertise-routes=10.0.0.0/24 | |
tailscale up |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I used it on a Beryl.
To get enough storage space, install it from/on the microSD storage as mentioned in the script comments.
Also make sure to read both link tutorials from the script comments.
Note that i recently bought a Beryl AX (wifi 6), and tailscale is now natively embedded in the Gl.inet OS !