Skip to content

Instantly share code, notes, and snippets.

@jaredallard
Forked from cceckman/rm2-tailscale.sh
Last active March 20, 2025 20:21
Show Gist options
  • Select an option

  • Save jaredallard/96da354c37afb2a000f61cc0c10c4e61 to your computer and use it in GitHub Desktop.

Select an option

Save jaredallard/96da354c37afb2a000f61cc0c10c4e61 to your computer and use it in GitHub Desktop.
Tailscale setup for remarkable
#!/usr/bin/env bash
#
# Original: https://github.com/cceckman/homelab/blob/main/helpers/rm2-tailscale.sh
# I am the original author of this document and release it into the public domain.
# Go wild.
#
# 2025 Modified by @jaredallard to build release versions of Tailscale.
#
# This script enables [Tailscale] on a [reMarkable 2] tablet.
#
# Tailscale is run in [userspace networking] mode, so any outbound applications
# will need to be configured to proxy via tailscaled.
#
# The script assumes you've set up SSH to the tablet, as described in
# https://remarkablewiki.com/tech/ssh, and that it's locally connected
# (not just via Tailscale) during setup.
#
# [Tailscale]: https://tailscale.com
# [reMarkable 2]: https://remarkable.com/
# [userspace networking]: https://tailscale.com/kb/1112/userspace-networking/
#
set -eu
if ! test "$#" = "1"; then
echo >&2 "Requires a single argument: reMarkable address"
echo >&2 "(Typically 10.11.99.1)"
exit 1
fi
TARGET="$1"
TSINSTALLPATH="~/tailscale"
# TAILSCALE_VERSION is the version of tailscale to build.
TAILSCALE_VERSION="1.80.3"
CONTENT="$(mktemp -d)/"
build_tailscale() {
# Build Tailscale:
TSPATH="$(mktemp -d)"
rmdir "$TSPATH"
echo >&2 "Downloading tailscale source..."
mkdir -p "$(dirname "$TSPATH")"
git clone -c advice.detachedHead=false --single-branch --branch "v$TAILSCALE_VERSION" \
https://github.com/tailscale/tailscale.git "$TSPATH"
pushd "$TSPATH" >/dev/null
# Read build information
set -a
eval "$(./build_dist.sh shellvars)"
set +a
# We're building for a small device. We aren't trying to squeeze onto the root
# partition, but we still want to leave more space for docs if we can.
#
# Use https://tailscale.com/kb/1207/small-tailscale,
# and tags+flags pulled from build_dist.
echo >&2 "Building tailscale..."
GOOS=linux GOARCH=arm GOARM=7 \
go build \
-C "$TSPATH" \
-o "$CONTENT"/tailscale.combined \
-tags ts_include_cli,ts_omit_aws,ts_omit_bird,ts_omit_tap,ts_omit_kube,ts_omit_completion \
-ldflags "-w -s -X tailscale.com/version.longStamp=${VERSION_LONG} -X tailscale.com/version.shortStamp=${VERSION_SHORT}" \
./cmd/tailscaled
echo >&2 "Tailscale binary up-to-date in $CONTENT"
# Capture the service file too.
cp "$TSPATH"/cmd/tailscaled/tailscaled.service "$CONTENT"
popd >/dev/null
}
# Build in a subshell, so cd doesn't move us.
(build_tailscale)
cat <<EOF >"$CONTENT"/setup.sh
#!/usr/bin/env bash
set -eu
# Sometimes Remarkable's OS doesn't update resolv.conf ?
# https://www.reddit.com/r/RemarkableTablet/comments/miogzb/solution_cloud_service_connection_issue_when
# Turn ~ into the actual home path.
export TSINSTALLPATH=$(sed 's|~|'"\$HOME"'|' <<<"$TSINSTALLPATH")
# Install files to their proper locations:
ls -lah \$TSINSTALLPATH
chown -R root:root \$TSINSTALLPATH
echo >&2 "Installing binaries and service definitions..."
set -x
# Link from the /usr paths to our install location
ln -sf "\$TSINSTALLPATH/tailscale.combined" /usr/bin/tailscale
ln -sf "\$TSINSTALLPATH/tailscale.combined" /usr/sbin/tailscaled
sed 's|/usr/sbin/tailscaled|'"\$TSINSTALLPATH/tailscale.combined"'|' "\$TSINSTALLPATH/tailscaled.service" > /etc/systemd/system/tailscaled.service
set +x
# Tailscale expects some configuration in a drop-in unit or config files;
# the tailscale.service definition includes PORT and FLAGS variables.
# We oblige!
# The reMarkable kernel doesn't appear to have CONFIG_TUN (no /dev/net/tun),
# so we have to try userspace-networking:
# https://tailscale.com/kb/1112/userspace-networking/
cat <<EOS >/etc/default/tailscaled
PORT=41641
FLAGS="--tun userspace-networking --socks5-server=localhost:1055 --outbound-http-proxy-listen=localhost:1055"
EOS
echo >&2 "Reloading systemd..."
systemctl daemon-reload
echo >&2 "Starting tailscale..."
systemctl enable --now tailscaled
tailscale up
EOF
chmod +x "$CONTENT/setup.sh"
echo >&2 "Connecting and uploading..."
ssh -o ConnectTimeout=5 "$TARGET" \
"echo >&2 'Connected to reMarkable!'; rm -rf $TSINSTALLPATH; mkdir -p $TSINSTALLPATH" >&2
rsync -avz "$CONTENT" "$TARGET:$TSINSTALLPATH"
echo >&2 "Running setup..."
ssh "$TARGET" "$TSINSTALLPATH/setup.sh"
@akralovic
Copy link
Copy Markdown

akralovic commented Feb 20, 2025

Does this work with Remarkable2 version 3.17.0.72?

@jaredallard
Copy link
Copy Markdown
Author

jaredallard commented Feb 22, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment