initial commit

This commit is contained in:
videah
2023-08-29 05:57:00 +01:00
commit a09d07346d
14 changed files with 177 additions and 0 deletions

24
README.md Normal file
View File

@@ -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)

18
libra2/README.md Normal file
View File

@@ -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.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

59
libra2/install-tailscale.sh Executable file
View File

@@ -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

BIN
libra2/modules/tun.ko Executable file

Binary file not shown.

View File

@@ -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'"

10
libra2/scripts/boot.sh Executable file
View File

@@ -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

26
libra2/scripts/on-boot.sh Executable file
View File

@@ -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

2
libra2/scripts/on-wlan-down.sh Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/sh
tailscale down

2
libra2/scripts/on-wlan-up.sh Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/sh
tailscale up

View File

@@ -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!"