commit a09d07346d771e5dab1caadda77b781fa0007a39 Author: videah Date: Tue Aug 29 05:57:00 2023 +0100 initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..6b7872f --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# kobo-tailscale +Install scripts for getting [Tailscale](https://tailscale.com) running on Kobo e-readers and persisting through reboots. + +## Supported devices +- *Kobo Libra 2* + +Currently only the Libra 2 is supported as it is the only device I have access to. +If you have another device and would like to contribute, please open a PR! + +## Installation +> [!NOTE] +> The version of Tailscale to install can be chosen by editing the `TAILSCALE_VERSION` variable in `install-tailscale.sh`. + +1. Download this repo onto your Kobo e-reader's onboard storage and find your device. +2. Run `install-tailscale.sh` from the chosen device's directory. +3. Run `tailscale up` and follow the instructions to authenticate your e-reader! + +## Uninstallation +Simply run `uninstall-tailscale.sh` from the chosen device's directory in the repo. + +## Acknowledgements +[Dylan Staley for initial work and scripts on the Kobo Sage](https://dstaley.com/posts/tailscale-on-kobo-sage) + +[jmacindoe for documenting kernel module compilation on Kobo readers](https://github.com/jmacindoe/kobo-kernel-modules) \ No newline at end of file diff --git a/libra2/README.md b/libra2/README.md new file mode 100644 index 0000000..0626420 --- /dev/null +++ b/libra2/README.md @@ -0,0 +1,18 @@ +# Kobo Libra 2 + +## Modules +Tailscale requires the TUN/TAP device driver to be loaded to function. +This is not included in the stock Kobo Libra 2 kernel so this repo provides it as a +pre-built kernel module in the `modules` directory. + +This was built from the [Libra 2 kernel source code](https://github.com/kobolabs/Kobo-Reader/tree/master/hw/imx6sll-libra2) +provided by Rakuten following the instructions found on the [kobo-kernel-modules](https://github.com/jmacindoe/kobo-kernel-modules/tree/main/Kobo%20Mark%209%20-%20Libra%202) +repo. + +# iptables +Tailscale requires the `iptables` binary and shared libraries to be present on the device to function. +These are not included in the stock Kobo Libra 2 kernel so this repo provides it as +pre-built binaries/libraries in the `binaries` directory. + +This was pulled from the [July 5th 2017 build of Raspbian](http://downloads.raspberrypi.org/raspbian/images/raspbian-2017-07-05) +which also bundles the source code. This was done to match the glibc version used in the Libra 2 kernel. \ No newline at end of file diff --git a/libra2/binaries/iptables/lib/libip4tc.so.0.1.0 b/libra2/binaries/iptables/lib/libip4tc.so.0.1.0 new file mode 100755 index 0000000..726d0b6 Binary files /dev/null and b/libra2/binaries/iptables/lib/libip4tc.so.0.1.0 differ diff --git a/libra2/binaries/iptables/lib/libip6tc.so.0.1.0 b/libra2/binaries/iptables/lib/libip6tc.so.0.1.0 new file mode 100755 index 0000000..c8b84f9 Binary files /dev/null and b/libra2/binaries/iptables/lib/libip6tc.so.0.1.0 differ diff --git a/libra2/binaries/iptables/lib/libxtables.so.10.0.0 b/libra2/binaries/iptables/lib/libxtables.so.10.0.0 new file mode 100755 index 0000000..7072bf2 Binary files /dev/null and b/libra2/binaries/iptables/lib/libxtables.so.10.0.0 differ diff --git a/libra2/binaries/iptables/sbin/xtables-multi b/libra2/binaries/iptables/sbin/xtables-multi new file mode 100755 index 0000000..8e29b55 Binary files /dev/null and b/libra2/binaries/iptables/sbin/xtables-multi differ diff --git a/libra2/install-tailscale.sh b/libra2/install-tailscale.sh new file mode 100755 index 0000000..a181447 --- /dev/null +++ b/libra2/install-tailscale.sh @@ -0,0 +1,59 @@ +#!/bin/sh + +set -e + +# Set what version of tailscale you would like to install here. +# You can find the latest version at https://pkgs.tailscale.com/stable/#static +export TAILSCALE_VERSION=1.48.1 + +echo +echo "Installing tailscale ${TAILSCALE_VERSION} for Kobo Libra 2!" +uname -a +echo + +echo "Copying TUN kernel module into /lib/modules/tailscale ..." +mkdir -p /lib/modules/tailscale/kernel/drivers/net +cp modules/tun.ko /lib/modules/tailscale/kernel/drivers/net/tun.ko + +echo "Installing iptables into /sbin and /lib ..." +cp binaries/iptables/sbin/* /sbin +cp binaries/iptables/lib/* /lib + +ln -sf /sbin/xtables-multi /sbin/iptables +ln -sf /lib/libxtables.so.10.0.0 /lib/libxtables.so.10 +ln -sf /lib/libip4tc.so.0.1.0 /lib/libip4tc.so.0 +ln -sf /lib/libip6tc.so.0.1.0 /lib/libip6tc.so.0 + +echo "Downloading tailscale_${TAILSCALE_VERSION}_arm.tgz from pkgs.tailscale.com ..." +wget https://pkgs.tailscale.com/stable/tailscale_${TAILSCALE_VERSION}_arm.tgz +tar -xvf tailscale_${TAILSCALE_VERSION}_arm.tgz + +echo "Installing tailscale binaries into /mnt/onboard/tailscale and symlinking them into /usr/bin ..." +mkdir -p /mnt/onboard/tailscale +mv tailscale_${TAILSCALE_VERSION}_arm/tailscale /mnt/onboard/tailscale +mv tailscale_${TAILSCALE_VERSION}_arm/tailscaled /mnt/onboard/tailscale + +# Symlink tailscale binaries to /usr/bin +ln -sf /mnt/onboard/tailscale/tailscale /usr/bin/tailscale +ln -sf /mnt/onboard/tailscale/tailscaled /usr/bin/tailscaled + +echo "Cleaning up tarball ..." +rm -rf tailscale_${TAILSCALE_VERSION}_arm +rm -rf tailscale_${TAILSCALE_VERSION}_arm.tgz + +echo "Installing tailscale boot and load scripts into /usr/local/tailscale ..." +mkdir -p /usr/local/tailscale +cp scripts/* /usr/local/tailscale + +echo "Installing tailscale udev rule into /etc/udev/rules.d ..." +cp rules/* /etc/udev/rules.d + +echo +echo "Installation complete! Attempting to boot tailscale daemon ..." +/usr/local/tailscale/boot.sh +echo + +echo "If no errors were reported, tailscale should be installed!" +echo "You can now configure tailscale by running 'tailscale up' and following the instructions." +echo "The tailscale binaries are located in /mnt/onboard/tailscale." +echo \ No newline at end of file diff --git a/libra2/modules/tun.ko b/libra2/modules/tun.ko new file mode 100755 index 0000000..75ce9e3 Binary files /dev/null and b/libra2/modules/tun.ko differ diff --git a/libra2/rules/98-tailscale.rules b/libra2/rules/98-tailscale.rules new file mode 100644 index 0000000..7dfb916 --- /dev/null +++ b/libra2/rules/98-tailscale.rules @@ -0,0 +1,3 @@ +KERNEL=="loop0", RUN+="/bin/sh -c '/usr/local/tailscale/boot.sh'" +KERNEL=="wlan*", ACTION=="add", RUN+="/bin/sh -c '/usr/local/tailscale/on-wlan-up.sh'" +KERNEL=="wlan*", ACTION=="remove", RUN+="/bin/sh -c '/usr/local/tailscale/on-wlan-down.sh'" \ No newline at end of file diff --git a/libra2/scripts/boot.sh b/libra2/scripts/boot.sh new file mode 100755 index 0000000..12931d1 --- /dev/null +++ b/libra2/scripts/boot.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +# Start by renicing ourselves to a neutral value, to avoid any mishap... +renice 0 -p $$ + +# Launch in the background, with a clean env, after a setsid call to make very very sure udev won't kill us ;). +env -i -- setsid /usr/local/tailscale/on-boot.sh & + +# Done :) +exit 0 \ No newline at end of file diff --git a/libra2/scripts/on-boot.sh b/libra2/scripts/on-boot.sh new file mode 100755 index 0000000..c37b763 --- /dev/null +++ b/libra2/scripts/on-boot.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +# Make sure to load the TUN kernel module and create the /dev/net/tun device +if ! lsmod | grep -q "^tun"; then + insmod /lib/modules/tailscale/kernel/drivers/net/tun.ko + if [ ! -c /dev/net/tun ]; then + mkdir -p /dev/net + mknod /dev/net/tun c 10 200 + fi +fi + +# Make absolutely sure that iptables is in the PATH +export PATH=/usr/sbin:/usr/bin:$PATH + +# Make sure /mnt/onboard is mounted +timeout 5 sh -c "while ! grep -q /mnt/onboard /proc/mounts; do sleep 0.1; done" +if [[ $? -eq 143 ]]; then + exit 1 +fi + +case "$(pidof tailscaled | wc -w)" in +0) tailscaled --state=/tailscaled.state &> /tailscaled.log & + ;; +esac + +exit 0 \ No newline at end of file diff --git a/libra2/scripts/on-wlan-down.sh b/libra2/scripts/on-wlan-down.sh new file mode 100755 index 0000000..bffdade --- /dev/null +++ b/libra2/scripts/on-wlan-down.sh @@ -0,0 +1,2 @@ +#!/bin/sh +tailscale down \ No newline at end of file diff --git a/libra2/scripts/on-wlan-up.sh b/libra2/scripts/on-wlan-up.sh new file mode 100755 index 0000000..e27b4c8 --- /dev/null +++ b/libra2/scripts/on-wlan-up.sh @@ -0,0 +1,2 @@ +#!/bin/sh +tailscale up \ No newline at end of file diff --git a/libra2/uninstall-tailscale.sh b/libra2/uninstall-tailscale.sh new file mode 100644 index 0000000..c722f72 --- /dev/null +++ b/libra2/uninstall-tailscale.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +echo "Uninstalling tailscale..." + +pid=$(pgrep tailscaled) +if [ -n "$pid" ]; then + echo "Terminating tailscale daemon with PID $pid ..." + kill -15 "$pid" + + # Wait a little bit for the daemon to terminate cleanly. + sleep 3 + + echo "Tailscale daemon terminated successfully." +fi + +echo "Removing TUN kernel module from /lib/modules/tailscale ..." +rm /lib/modules/tailscale/kernel/drivers/net/tun.ko + +echo "Removing iptables binaries from /sbin and /lib ..." +rm -f /sbin/xtables-multi /sbin/iptables +rm -f /lib/libxtables.so.10 /lib/libip4tc.so.0 /lib/libip6tc.so.0 + +echo "Removing tailscale binaries from /mnt/onboard/tailscale and /usr/bin ..." +rm -rf /mnt/onboard/tailscale +rm -f /usr/bin/tailscale /usr/bin/tailscaled + +echo "Removing tailscale boot and load scripts from /usr/local/tailscale ..." +rm -rf /usr/local/tailscale + +echo "Removing tailscale udev rule from /etc/udev/rules.d ..." +rm -f /etc/udev/rules.d/99-tailscale.rules + +echo "Uninstallation complete!" \ No newline at end of file