From cda40f1a822b3aa137e26d8104cbd4db800949d8 Mon Sep 17 00:00:00 2001 From: Zac Holland Date: Thu, 14 Dec 2023 15:36:46 -0800 Subject: [PATCH 01/28] change id to _any --- tailscale.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tailscale.sh b/tailscale.sh index df9ebe1..df9dff9 100644 --- a/tailscale.sh +++ b/tailscale.sh @@ -46,7 +46,7 @@ cp -rf $tar_dir/tailscale tailscale/usr/bin/tailscale cp -rf $tar_dir/tailscaled tailscale/usr/sbin/tailscaled # write a systemd extension-release file -echo -e "ID=steamos\nVERSION_ID=${VERSION_ID}" >> tailscale/usr/lib/extension-release.d/extension-release.tailscale +echo -e "ID=_any" >> tailscale/usr/lib/extension-release.d/extension-release.tailscale # create the system extension folder if it doesn't already exist, remove the old version of our tailscale extension, and install our new one mkdir -p /var/lib/extensions From c16ab36d52fc3dca2f0bbbe405a30a9f77adfb4a Mon Sep 17 00:00:00 2001 From: Zac Holland Date: Fri, 15 Dec 2023 09:24:54 -0800 Subject: [PATCH 02/28] remove readme note about update issues --- readme.md | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/readme.md b/readme.md index 57b1484..eb59e61 100644 --- a/readme.md +++ b/readme.md @@ -57,21 +57,6 @@ $ steamos-readonly enable $ systemd-sysext merge ``` -## On system update - -Unfortunately, because SteamOS doesn't include a `SYSEXT_LEVEL`, this -installation method breaks when the system version changes. Repair is simple: -Re-run the second step of the installation, and everything should come back up -as you had it. - -### Why this happens - -Extension images have to declare their compatibility using the OS ID and either -the SYSEXT_LEVEL or VERSION_ID, which have to match what the system declares. - -SteamOS doesn't declare a SYSEXT_LEVEL, and the VERSION_ID increments with every -system update, so there's no stable values to declare compatibility against. - ## Common issues ### Broken config file From d496b2a7d76f70ab788c786c7a2325115f482671 Mon Sep 17 00:00:00 2001 From: Zac Holland Date: Fri, 15 Dec 2023 15:59:25 -0800 Subject: [PATCH 03/28] install in home dir --- tailscale.sh | 49 +++++++++++++------------------------------------ 1 file changed, 13 insertions(+), 36 deletions(-) diff --git a/tailscale.sh b/tailscale.sh index df9dff9..7bbafa5 100644 --- a/tailscale.sh +++ b/tailscale.sh @@ -38,53 +38,30 @@ tar xzf tailscale.tgz tar_dir="$(echo ${tarball} | cut -d. -f1-3)" test -d $tar_dir -# create our target directory structure -mkdir -p tailscale/usr/{bin,sbin,lib/{systemd/system,extension-release.d}} +# Create binaries directory in home +mkdir -p /home/deck/.local/bin -# pull things into the right place in the target dir structure -cp -rf $tar_dir/tailscale tailscale/usr/bin/tailscale -cp -rf $tar_dir/tailscaled tailscale/usr/sbin/tailscaled - -# write a systemd extension-release file -echo -e "ID=_any" >> tailscale/usr/lib/extension-release.d/extension-release.tailscale - -# create the system extension folder if it doesn't already exist, remove the old version of our tailscale extension, and install our new one -mkdir -p /var/lib/extensions -rm -rf /var/lib/extensions/tailscale -cp -rf tailscale /var/lib/extensions/ - -# copy the systemd files into place -cp -rf $tar_dir/systemd/tailscaled.service /etc/systemd/system +# pull binaries +cp -rf $tar_dir/tailscale /home/deck/.local/bin/tailscale +cp -rf $tar_dir/tailscaled /home/deck/.local/bin/tailscaled # copy in the defaults file if it doesn't already exist -if ! test -f /etc/default/tailscaled; then - cp -rf $tar_dir/systemd/tailscaled.defaults /etc/default/tailscaled +if ! test -f /home/deck/.config/tailscaled.defaults; then + cp -rf $tar_dir/systemd/tailscaled.defaults /home/deck/.config/tailscaled.defaults fi +# copy the systemd file into place +cp -rf $tar_dir/systemd/tailscaled.service /etc/systemd/system + +sed -i 's@/etc/default/tailscaled@/home/deck/.config/tailscaled.defaults@g' /etc/systemd/system/tailscaled.service +sed -i 's@/usr/sbin/tailscaled@/home/deck/.bin/tailscaled@g' /etc/systemd/system/tailscaled.service + # return to our original directory (silently) and clean up popd > /dev/null rm -rf "${dir}" -# copy in our overrides file if it doesn't already exist -if ! test -f /etc/systemd/system/tailscaled.service.d/override.conf; then - mkdir -p /etc/systemd/system/tailscaled.service.d - cp -rf override.conf /etc/systemd/system/tailscaled.service.d/override.conf -fi - -echo "done." - echo "Starting required services..." -# systemd-sysext - manages system extensions -if systemctl is-enabled --quiet systemd-sysext && systemctl is-active --quiet systemd-sysext; then - echo "systemd-sysext is already enabled and active" -else - systemctl enable systemd-sysext --now # this should be all we need in every case, but something breaks if it's already enabled/running. -fi -systemd-sysext refresh > /dev/null 2>&1 - -echo "Done." - # tailscaled - the tailscale daemon systemctl enable tailscaled if systemctl is-active --quiet tailscaled; then From 88563800974427c97ca7da87308b52d5ec50a29e Mon Sep 17 00:00:00 2001 From: Zac Holland Date: Fri, 15 Dec 2023 16:03:53 -0800 Subject: [PATCH 04/28] fix paths for binary --- tailscale.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tailscale.sh b/tailscale.sh index 7bbafa5..87bf2d7 100644 --- a/tailscale.sh +++ b/tailscale.sh @@ -39,11 +39,11 @@ tar_dir="$(echo ${tarball} | cut -d. -f1-3)" test -d $tar_dir # Create binaries directory in home -mkdir -p /home/deck/.local/bin +mkdir -p /home/deck/.bin # pull binaries -cp -rf $tar_dir/tailscale /home/deck/.local/bin/tailscale -cp -rf $tar_dir/tailscaled /home/deck/.local/bin/tailscaled +cp -rf $tar_dir/tailscale /home/deck/.bin/tailscale +cp -rf $tar_dir/tailscaled /home/deck/.bin/tailscaled # copy in the defaults file if it doesn't already exist if ! test -f /home/deck/.config/tailscaled.defaults; then From 6778aaead6f1c864dcfeaa93aa43317fe9dc7807 Mon Sep 17 00:00:00 2001 From: Zac Holland Date: Fri, 15 Dec 2023 16:10:51 -0800 Subject: [PATCH 05/28] add user binaries to path --- tailscale.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tailscale.sh b/tailscale.sh index 87bf2d7..b8568f9 100644 --- a/tailscale.sh +++ b/tailscale.sh @@ -45,6 +45,11 @@ mkdir -p /home/deck/.bin cp -rf $tar_dir/tailscale /home/deck/.bin/tailscale cp -rf $tar_dir/tailscaled /home/deck/.bin/tailscaled +# add binaries to path via bashrc if not already there +if [ $(cat /home/deck/.bashrc | grep -c "/home/deck/.bin") -eq 0 ]; then + echo "/home/deck/.bin" >> /home/deck/.bashrc +fi + # copy in the defaults file if it doesn't already exist if ! test -f /home/deck/.config/tailscaled.defaults; then cp -rf $tar_dir/systemd/tailscaled.defaults /home/deck/.config/tailscaled.defaults From 2ee6edbc821d891a656e7676f76eba7bb2f35147 Mon Sep 17 00:00:00 2001 From: Zac Holland Date: Fri, 15 Dec 2023 16:16:40 -0800 Subject: [PATCH 06/28] fix bashrc lines --- tailscale.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tailscale.sh b/tailscale.sh index b8568f9..22e345f 100644 --- a/tailscale.sh +++ b/tailscale.sh @@ -46,8 +46,8 @@ cp -rf $tar_dir/tailscale /home/deck/.bin/tailscale cp -rf $tar_dir/tailscaled /home/deck/.bin/tailscaled # add binaries to path via bashrc if not already there -if [ $(cat /home/deck/.bashrc | grep -c "/home/deck/.bin") -eq 0 ]; then - echo "/home/deck/.bin" >> /home/deck/.bashrc +if [ $(cat /home/deck/.bashrc | grep -c 'export PATH="/home/deck/.bin:$PATH"') -eq 0 ]; then + echo 'export PATH="/home/deck/.bin:$PATH"' >> /home/deck/.bashrc fi # copy in the defaults file if it doesn't already exist From cb88cbc1a9bf52b09694a05199e6007583ab6449 Mon Sep 17 00:00:00 2001 From: Zac Holland Date: Fri, 15 Dec 2023 16:24:03 -0800 Subject: [PATCH 07/28] put Readme update back to remove diff clutter --- readme.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/readme.md b/readme.md index eb59e61..57b1484 100644 --- a/readme.md +++ b/readme.md @@ -57,6 +57,21 @@ $ steamos-readonly enable $ systemd-sysext merge ``` +## On system update + +Unfortunately, because SteamOS doesn't include a `SYSEXT_LEVEL`, this +installation method breaks when the system version changes. Repair is simple: +Re-run the second step of the installation, and everything should come back up +as you had it. + +### Why this happens + +Extension images have to declare their compatibility using the OS ID and either +the SYSEXT_LEVEL or VERSION_ID, which have to match what the system declares. + +SteamOS doesn't declare a SYSEXT_LEVEL, and the VERSION_ID increments with every +system update, so there's no stable values to declare compatibility against. + ## Common issues ### Broken config file From 05156fbb6790207df4a6376a696a0264df921d2f Mon Sep 17 00:00:00 2001 From: Zac Holland Date: Fri, 15 Dec 2023 16:34:12 -0800 Subject: [PATCH 08/28] add comment for sed commands --- tailscale.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tailscale.sh b/tailscale.sh index 22e345f..78164dc 100644 --- a/tailscale.sh +++ b/tailscale.sh @@ -58,6 +58,7 @@ fi # copy the systemd file into place cp -rf $tar_dir/systemd/tailscaled.service /etc/systemd/system +# update paths in the unit file sed -i 's@/etc/default/tailscaled@/home/deck/.config/tailscaled.defaults@g' /etc/systemd/system/tailscaled.service sed -i 's@/usr/sbin/tailscaled@/home/deck/.bin/tailscaled@g' /etc/systemd/system/tailscaled.service From dd30633d723bb17edf9c1c78c5f8307cce9445ea Mon Sep 17 00:00:00 2001 From: Zac Holland Date: Mon, 18 Dec 2023 12:12:03 -0800 Subject: [PATCH 09/28] add section for removing legacy installations --- tailscale.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tailscale.sh b/tailscale.sh index 78164dc..7c8a357 100644 --- a/tailscale.sh +++ b/tailscale.sh @@ -31,6 +31,28 @@ curl -s "https://pkgs.tailscale.com/stable/${tarball}" -o tailscale.tgz echo "done." +echo -n "Uninstalling Legacy Installation..." + +# Stop and disable the systemd service +if systemctl is-active --quiet tailscaled; then + systemctl stop tailscaled +fi +if systemctl is-enabled --quiet tailscaled; then + systemctl disable tailscaled +fi + +# Remove the systemd system extension +if [ $(systemd-sysext list | grep -c "/var/lib/extensions/tailscale") -ne 0 ]; then + systemd-sysext unmerge > /dev/null + rm -rf /var/lib/extensions/tailscale + systemd-sysext merge > /dev/null +fi + +# Remove the overrides conf +if test -f /etc/systemd/system/tailscaled.service.d/override.conf; then + cp -rf $tar_dir/systemd/tailscaled.defaults /home/deck/.config/tailscaled.defaults +fi + echo -n "Installing..." # extract the tailscale binaries From dee3fecb400d68cc4e5968d9ea0d9bf8f66923ec Mon Sep 17 00:00:00 2001 From: Zac Holland Date: Mon, 18 Dec 2023 12:20:17 -0800 Subject: [PATCH 10/28] move defaults to /etc move installation to /opt --- tailscale.sh | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/tailscale.sh b/tailscale.sh index 7c8a357..9549b7c 100644 --- a/tailscale.sh +++ b/tailscale.sh @@ -31,7 +31,7 @@ curl -s "https://pkgs.tailscale.com/stable/${tarball}" -o tailscale.tgz echo "done." -echo -n "Uninstalling Legacy Installation..." +echo -n "Removing Legacy Installations..." # Stop and disable the systemd service if systemctl is-active --quiet tailscaled; then @@ -50,7 +50,7 @@ fi # Remove the overrides conf if test -f /etc/systemd/system/tailscaled.service.d/override.conf; then - cp -rf $tar_dir/systemd/tailscaled.defaults /home/deck/.config/tailscaled.defaults + rm -rf /etc/systemd/system/tailscaled.service.d/override.conf fi echo -n "Installing..." @@ -61,28 +61,28 @@ tar_dir="$(echo ${tarball} | cut -d. -f1-3)" test -d $tar_dir # Create binaries directory in home -mkdir -p /home/deck/.bin +mkdir -p /opt/tailscale # pull binaries -cp -rf $tar_dir/tailscale /home/deck/.bin/tailscale -cp -rf $tar_dir/tailscaled /home/deck/.bin/tailscaled +cp -rf $tar_dir/tailscale /opt/tailscale/tailscale +cp -rf $tar_dir/tailscaled /opt/tailscale/tailscaled -# add binaries to path via bashrc if not already there -if [ $(cat /home/deck/.bashrc | grep -c 'export PATH="/home/deck/.bin:$PATH"') -eq 0 ]; then - echo 'export PATH="/home/deck/.bin:$PATH"' >> /home/deck/.bashrc -fi - -# copy in the defaults file if it doesn't already exist -if ! test -f /home/deck/.config/tailscaled.defaults; then - cp -rf $tar_dir/systemd/tailscaled.defaults /home/deck/.config/tailscaled.defaults +# add binaries to path via profile.d +if ! test -f /etc/profile.d/tailscale.sh; then + mkdir -p /etc/profile.d/tailscale.sh + echo 'PATH="$PATH:/home/deck/.bin"' >> /etc/profile.d/tailscale.sh fi # copy the systemd file into place -cp -rf $tar_dir/systemd/tailscaled.service /etc/systemd/system +cp -rf $tar_dir/systemd/tailscaled.service /etc/systemd/system/tailscaled.service + +# copy in the defaults file if it doesn't already exist +if ! test -f /etc/default/tailscaled; then + cp -rf $tar_dir/systemd/tailscaled.defaults /etc/default/tailscaled +fi # update paths in the unit file -sed -i 's@/etc/default/tailscaled@/home/deck/.config/tailscaled.defaults@g' /etc/systemd/system/tailscaled.service -sed -i 's@/usr/sbin/tailscaled@/home/deck/.bin/tailscaled@g' /etc/systemd/system/tailscaled.service +sed -i 's@/usr/sbin/tailscaled@/opt/tailscale/tailscaled@g' /etc/systemd/system/tailscaled.service # return to our original directory (silently) and clean up popd > /dev/null @@ -91,6 +91,8 @@ rm -rf "${dir}" echo "Starting required services..." # tailscaled - the tailscale daemon +# Note: enable and start/restart must be run because the legacy installation stops and disables +# any existing installations. systemctl enable tailscaled if systemctl is-active --quiet tailscaled; then echo "Upgrade complete. Restarting tailscaled..." From 9f7ea642d4fb626c7b77ad36f1be776036af02e2 Mon Sep 17 00:00:00 2001 From: Zac Holland Date: Mon, 18 Dec 2023 12:37:28 -0800 Subject: [PATCH 11/28] add &>/dev/null and error messages because commands are sending output to stderr even on success --- tailscale.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tailscale.sh b/tailscale.sh index 9549b7c..38468ca 100644 --- a/tailscale.sh +++ b/tailscale.sh @@ -35,17 +35,17 @@ echo -n "Removing Legacy Installations..." # Stop and disable the systemd service if systemctl is-active --quiet tailscaled; then - systemctl stop tailscaled + systemctl stop tailscaled &>/dev/null || echo "ERROR: could not stop tailscaled" fi if systemctl is-enabled --quiet tailscaled; then - systemctl disable tailscaled + systemctl disable tailscaled &>/dev/null || echo "ERROR: could not disable tailscaled" fi # Remove the systemd system extension if [ $(systemd-sysext list | grep -c "/var/lib/extensions/tailscale") -ne 0 ]; then - systemd-sysext unmerge > /dev/null + systemd-sysext unmerge &>/dev/null || echo "ERROR: could not unmerge system extensions" rm -rf /var/lib/extensions/tailscale - systemd-sysext merge > /dev/null + systemd-sysext merge &>/dev/null || echo "ERROR: could not merge system extensions" fi # Remove the overrides conf @@ -69,7 +69,6 @@ cp -rf $tar_dir/tailscaled /opt/tailscale/tailscaled # add binaries to path via profile.d if ! test -f /etc/profile.d/tailscale.sh; then - mkdir -p /etc/profile.d/tailscale.sh echo 'PATH="$PATH:/home/deck/.bin"' >> /etc/profile.d/tailscale.sh fi From c250264b6b8b8d55cb9e54bbb5697a0f39c72151 Mon Sep 17 00:00:00 2001 From: Zac Holland Date: Mon, 18 Dec 2023 12:40:25 -0800 Subject: [PATCH 12/28] Consistent logging --- tailscale.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tailscale.sh b/tailscale.sh index 38468ca..ab670ad 100644 --- a/tailscale.sh +++ b/tailscale.sh @@ -53,6 +53,8 @@ if test -f /etc/systemd/system/tailscaled.service.d/override.conf; then rm -rf /etc/systemd/system/tailscaled.service.d/override.conf fi +echo "done." + echo -n "Installing..." # extract the tailscale binaries @@ -87,6 +89,8 @@ sed -i 's@/usr/sbin/tailscaled@/opt/tailscale/tailscaled@g' /etc/systemd/system/ popd > /dev/null rm -rf "${dir}" +echo "done." + echo "Starting required services..." # tailscaled - the tailscale daemon From 52c0e7670454f59a203811e2b29217b11b141e1a Mon Sep 17 00:00:00 2001 From: Zac Holland Date: Mon, 18 Dec 2023 12:45:47 -0800 Subject: [PATCH 13/28] fix profile.d path bug --- tailscale.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tailscale.sh b/tailscale.sh index ab670ad..a3bb407 100644 --- a/tailscale.sh +++ b/tailscale.sh @@ -71,7 +71,7 @@ cp -rf $tar_dir/tailscaled /opt/tailscale/tailscaled # add binaries to path via profile.d if ! test -f /etc/profile.d/tailscale.sh; then - echo 'PATH="$PATH:/home/deck/.bin"' >> /etc/profile.d/tailscale.sh + echo 'PATH="$PATH:/opt/tailscale"' >> /etc/profile.d/tailscale.sh fi # copy the systemd file into place From c1b0ffe10d659256a9b818b3822b15fd37465f3a Mon Sep 17 00:00:00 2001 From: Zac Holland Date: Mon, 18 Dec 2023 12:55:12 -0800 Subject: [PATCH 14/28] more logging consistency changes because stuff is being printed to stderr --- tailscale.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tailscale.sh b/tailscale.sh index a3bb407..6347d8b 100644 --- a/tailscale.sh +++ b/tailscale.sh @@ -42,7 +42,7 @@ if systemctl is-enabled --quiet tailscaled; then fi # Remove the systemd system extension -if [ $(systemd-sysext list | grep -c "/var/lib/extensions/tailscale") -ne 0 ]; then +if [ $(systemd-sysext list 2>/dev/null | grep -c "/var/lib/extensions/tailscale") -ne 0 ]; then systemd-sysext unmerge &>/dev/null || echo "ERROR: could not unmerge system extensions" rm -rf /var/lib/extensions/tailscale systemd-sysext merge &>/dev/null || echo "ERROR: could not merge system extensions" @@ -96,12 +96,16 @@ echo "Starting required services..." # tailscaled - the tailscale daemon # Note: enable and start/restart must be run because the legacy installation stops and disables # any existing installations. -systemctl enable tailscaled +systemctl enable tailscaled &>/dev/null || echo "ERROR: Could not enable tailscaled service" if systemctl is-active --quiet tailscaled; then - echo "Upgrade complete. Restarting tailscaled..." + echo "Upgrade complete." + echo -n "Restarting tailscaled..." else - echo "Install complete. Starting tailscaled..." + echo "Install complete." + echo -n "Starting tailscaled..." fi -systemctl restart tailscaled # This needs to be the last thing we do in case the user's running this over Tailscale SSH. -echo "Done." +# This needs to be the last thing we do in case the user's running this over Tailscale SSH. +systemctl restart tailscaled &>/dev/null || echo "ERROR: Could not start tailscaled service" + +echo "done." From 3b2ff6b9cf56a724289c4da76504501a059d3245 Mon Sep 17 00:00:00 2001 From: Zac Holland Date: Mon, 18 Dec 2023 12:56:42 -0800 Subject: [PATCH 15/28] one more echo change --- tailscale.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tailscale.sh b/tailscale.sh index 6347d8b..aa9baba 100644 --- a/tailscale.sh +++ b/tailscale.sh @@ -91,7 +91,7 @@ rm -rf "${dir}" echo "done." -echo "Starting required services..." +echo -n "Starting required services..." # tailscaled - the tailscale daemon # Note: enable and start/restart must be run because the legacy installation stops and disables From f582ec51e73adfc41074d0e8a70296c7e35a2031 Mon Sep 17 00:00:00 2001 From: Zac Holland Date: Mon, 18 Dec 2023 13:00:46 -0800 Subject: [PATCH 16/28] add uninstall script --- uninstall.sh | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 uninstall.sh diff --git a/uninstall.sh b/uninstall.sh new file mode 100644 index 0000000..bcb7670 --- /dev/null +++ b/uninstall.sh @@ -0,0 +1,6 @@ +systemctl stop tailscaled +systemctl disable tailscaled +rm /etc/systemd/system/tailscaled.service +rm /etc/default/tailscaled +rm /etc/profile.d/tailscale.sh +rm -rf /opt/tailscale/tailscale From 8b128cf1e9d0e8a66f87e376e0633a31e4c9341c Mon Sep 17 00:00:00 2001 From: Zac Holland Date: Mon, 18 Dec 2023 13:11:22 -0800 Subject: [PATCH 17/28] add small helper if it is the users first time running the script --- tailscale.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tailscale.sh b/tailscale.sh index aa9baba..92163e2 100644 --- a/tailscale.sh +++ b/tailscale.sh @@ -72,6 +72,7 @@ cp -rf $tar_dir/tailscaled /opt/tailscale/tailscaled # add binaries to path via profile.d if ! test -f /etc/profile.d/tailscale.sh; then echo 'PATH="$PATH:/opt/tailscale"' >> /etc/profile.d/tailscale.sh + source /etc/profile.d/tailscale.sh fi # copy the systemd file into place @@ -109,3 +110,11 @@ fi systemctl restart tailscaled &>/dev/null || echo "ERROR: Could not start tailscaled service" echo "done." + +if ! command -v tailscale &> /dev/null; then + echo "Tailscale is installed and running but the binaries are not in your path yet." + echo "Restart your session or run the following command to add them:" + echo "" && echo "source /etc/tailscale" && echo "" +fi + +echo "Installation Complete." \ No newline at end of file From 002419edcca54a3358ef38346ecabdc5f5f85f32 Mon Sep 17 00:00:00 2001 From: Zac Holland Date: Mon, 18 Dec 2023 13:14:04 -0800 Subject: [PATCH 18/28] formatting --- tailscale.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tailscale.sh b/tailscale.sh index 92163e2..e2f945d 100644 --- a/tailscale.sh +++ b/tailscale.sh @@ -112,9 +112,12 @@ systemctl restart tailscaled &>/dev/null || echo "ERROR: Could not start tailsca echo "done." if ! command -v tailscale &> /dev/null; then + echo echo "Tailscale is installed and running but the binaries are not in your path yet." echo "Restart your session or run the following command to add them:" - echo "" && echo "source /etc/tailscale" && echo "" + echo + echo "source /etc/tailscale" + echo fi echo "Installation Complete." \ No newline at end of file From 61b47d9522511b83eb612cb537c20e5ec96ae4d4 Mon Sep 17 00:00:00 2001 From: Zac Holland Date: Mon, 18 Dec 2023 13:56:22 -0800 Subject: [PATCH 19/28] fix source command --- tailscale.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tailscale.sh b/tailscale.sh index e2f945d..4c70dff 100644 --- a/tailscale.sh +++ b/tailscale.sh @@ -116,7 +116,7 @@ if ! command -v tailscale &> /dev/null; then echo "Tailscale is installed and running but the binaries are not in your path yet." echo "Restart your session or run the following command to add them:" echo - echo "source /etc/tailscale" + echo "source /etc/profile.d/tailscale.sh" echo fi From 2e65e8d5bd0047c50d2723117b7b915e02c232cb Mon Sep 17 00:00:00 2001 From: Zac Holland Date: Mon, 18 Dec 2023 14:09:17 -0800 Subject: [PATCH 20/28] do not blindly delete tailscale override conf --- tailscale.sh | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tailscale.sh b/tailscale.sh index 4c70dff..2110bd8 100644 --- a/tailscale.sh +++ b/tailscale.sh @@ -48,11 +48,6 @@ if [ $(systemd-sysext list 2>/dev/null | grep -c "/var/lib/extensions/tailscale" systemd-sysext merge &>/dev/null || echo "ERROR: could not merge system extensions" fi -# Remove the overrides conf -if test -f /etc/systemd/system/tailscaled.service.d/override.conf; then - rm -rf /etc/systemd/system/tailscaled.service.d/override.conf -fi - echo "done." echo -n "Installing..." From be6349059dd56e49319a070466d49b43b0fc496c Mon Sep 17 00:00:00 2001 From: Zac Holland Date: Mon, 18 Dec 2023 15:35:47 -0800 Subject: [PATCH 21/28] replace overrides file in favor of sed --- override.conf | 7 ++++++- tailscale.sh | 8 +++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/override.conf b/override.conf index 6d52022..bf4279a 100644 --- a/override.conf +++ b/override.conf @@ -1,2 +1,7 @@ [Service] -ExtensionDirectories=/var/lib/extensions/tailscale +ExecStartPre= +ExecStartPre=/opt/tailscale/tailscaled --cleanup +ExecStart= +ExecStart=/opt/tailscale/tailscaled --state=/var/lib/tailscale/tailscaled.state --socket=/run/tailscale/tailscaled.sock --port=${PORT} $FLAGS +ExecStopPost= +ExecStopPost=/opt/tailscale/tailscaled --cleanup diff --git a/tailscale.sh b/tailscale.sh index 2110bd8..f66d621 100644 --- a/tailscale.sh +++ b/tailscale.sh @@ -78,13 +78,15 @@ if ! test -f /etc/default/tailscaled; then cp -rf $tar_dir/systemd/tailscaled.defaults /etc/default/tailscaled fi -# update paths in the unit file -sed -i 's@/usr/sbin/tailscaled@/opt/tailscale/tailscaled@g' /etc/systemd/system/tailscaled.service - # return to our original directory (silently) and clean up popd > /dev/null rm -rf "${dir}" +# copy in our overrides file if it doesn't already exist +if ! test -f /etc/systemd/system/tailscaled.service.d/override.conf; then + mkdir -p /etc/systemd/system/tailscaled.service.d + cp -rf override.conf /etc/systemd/system/tailscaled.service.d/override.conf + echo "done." echo -n "Starting required services..." From 698fcefab027bde1b0692764c7fb8766115743a5 Mon Sep 17 00:00:00 2001 From: Zac Holland Date: Mon, 18 Dec 2023 18:13:18 -0800 Subject: [PATCH 22/28] replace fi --- tailscale.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tailscale.sh b/tailscale.sh index f66d621..79847a7 100644 --- a/tailscale.sh +++ b/tailscale.sh @@ -86,6 +86,7 @@ rm -rf "${dir}" if ! test -f /etc/systemd/system/tailscaled.service.d/override.conf; then mkdir -p /etc/systemd/system/tailscaled.service.d cp -rf override.conf /etc/systemd/system/tailscaled.service.d/override.conf +fi echo "done." From 29f6fd70f9052d737c13e0618bd2c53c6b5585a6 Mon Sep 17 00:00:00 2001 From: Zac Holland Date: Tue, 19 Dec 2023 10:18:32 -0800 Subject: [PATCH 23/28] override file is backed up if already existing, then replaced --- tailscale.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tailscale.sh b/tailscale.sh index 79847a7..28d640a 100644 --- a/tailscale.sh +++ b/tailscale.sh @@ -82,12 +82,20 @@ fi popd > /dev/null rm -rf "${dir}" -# copy in our overrides file if it doesn't already exist -if ! test -f /etc/systemd/system/tailscaled.service.d/override.conf; then - mkdir -p /etc/systemd/system/tailscaled.service.d - cp -rf override.conf /etc/systemd/system/tailscaled.service.d/override.conf +# if an override file already exists, back up and remove +if test -f /etc/systemd/system/tailscaled.service.d/override.conf; then + echo + echo "Warning: An existing Tailscaled systemd override file was detected. It must be replaced." + echo "A backup of the existing file is being placed at /etc/systemd/system/tailscaled.service.d/override.conf.bak" + echo + cp -rf /etc/systemd/system/tailscaled.service.d/override.conf /etc/systemd/system/tailscaled.service.d/override.conf.bak + rm /etc/systemd/system/tailscaled.service.d/override.conf fi +# copy our override file in +mkdir -p /etc/systemd/system/tailscaled.service.d +cp -rf override.conf /etc/systemd/system/tailscaled.service.d/override.conf + echo "done." echo -n "Starting required services..." From a4348ef742fa22c014d4f275825148139aacded2 Mon Sep 17 00:00:00 2001 From: Zac Holland Date: Tue, 19 Dec 2023 10:21:19 -0800 Subject: [PATCH 24/28] one more echo for formatting --- tailscale.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tailscale.sh b/tailscale.sh index 28d640a..b8c73e9 100644 --- a/tailscale.sh +++ b/tailscale.sh @@ -84,6 +84,7 @@ rm -rf "${dir}" # if an override file already exists, back up and remove if test -f /etc/systemd/system/tailscaled.service.d/override.conf; then + echo echo echo "Warning: An existing Tailscaled systemd override file was detected. It must be replaced." echo "A backup of the existing file is being placed at /etc/systemd/system/tailscaled.service.d/override.conf.bak" From 89365b7f4de923c1b9c15fbc37c7012a9dfc76cc Mon Sep 17 00:00:00 2001 From: Zac Holland Date: Tue, 19 Dec 2023 10:25:26 -0800 Subject: [PATCH 25/28] remove recursive copy on single file --- tailscale.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tailscale.sh b/tailscale.sh index b8c73e9..046c57e 100644 --- a/tailscale.sh +++ b/tailscale.sh @@ -89,13 +89,13 @@ if test -f /etc/systemd/system/tailscaled.service.d/override.conf; then echo "Warning: An existing Tailscaled systemd override file was detected. It must be replaced." echo "A backup of the existing file is being placed at /etc/systemd/system/tailscaled.service.d/override.conf.bak" echo - cp -rf /etc/systemd/system/tailscaled.service.d/override.conf /etc/systemd/system/tailscaled.service.d/override.conf.bak + cp -f /etc/systemd/system/tailscaled.service.d/override.conf /etc/systemd/system/tailscaled.service.d/override.conf.bak rm /etc/systemd/system/tailscaled.service.d/override.conf fi # copy our override file in mkdir -p /etc/systemd/system/tailscaled.service.d -cp -rf override.conf /etc/systemd/system/tailscaled.service.d/override.conf +cp -f override.conf /etc/systemd/system/tailscaled.service.d/override.conf echo "done." From ba0a52692f69185eec22a0dc43d2d0a41b9b9ecd Mon Sep 17 00:00:00 2001 From: Zac Holland Date: Tue, 19 Dec 2023 11:03:39 -0800 Subject: [PATCH 26/28] readme changes --- readme.md | 56 +++++++------------------------------------------------ 1 file changed, 7 insertions(+), 49 deletions(-) diff --git a/readme.md b/readme.md index 57b1484..1e01419 100644 --- a/readme.md +++ b/readme.md @@ -9,7 +9,8 @@ automatically on boot (no need to enter desktop mode). 1. Clone this repo to your Deck. 2. Run `sudo bash tailscale.sh` to install Tailscale (or update the existing installation). -3. Run `sudo tailscale up --qr --operator=deck --ssh` to have Tailscale generate +3. Run `source /etc/profile.d/tailscale.sh` to put the binaries in your path +4. Run `sudo tailscale up --qr --operator=deck --ssh` to have Tailscale generate a login QR code. Scan the code with your phone and authenticate with Tailscale to bring your Deck onto your network. @@ -29,48 +30,9 @@ If it doesn't, keep reading. 2. Run `sudo bash tailscale.sh` again. This process overwrites the existing binaries and service file, so it's not -recommended to tweak those files directly. The configuration files at -`/etc/default/tailscaled` and -`/etc/systemd/system/tailscaled.service.d/override.conf` are left alone, so feel -free to edit those. If something goes wrong, copy those files somewhere else and -re-run the install script to get back to a working state. - -## Changing the root filesystem after installing Tailscale - -This method for installing Tailscale uses -[`systemd` system extensions](https://man.archlinux.org/man/systemd-sysext.8.en) -to install files in the otherwise read-only Steam Deck filesystem. A side-effect -is that the `/usr` and `/opt` directories (and directories like `/bin`, `/lib`, -`/lib64`, `/mnt`, and `/sbin`, that typically link to `/usr` due to -[`/usr` merge](https://www.freedesktop.org/wiki/Software/systemd/TheCaseForTheUsrMerge/) -which SteamOS implements) are read-only while system extensions are active, -_even after running `steamos-readonly disable`_. - -If you need to modify files in these directories after installing Tailscale, run -the following commands: - -```bash -$ systemd-sysext unmerge -$ steamos-readonly disable -[ make your changes to the rootfs now ] -$ steamos-readonly enable -$ systemd-sysext merge -``` - -## On system update - -Unfortunately, because SteamOS doesn't include a `SYSEXT_LEVEL`, this -installation method breaks when the system version changes. Repair is simple: -Re-run the second step of the installation, and everything should come back up -as you had it. - -### Why this happens - -Extension images have to declare their compatibility using the OS ID and either -the SYSEXT_LEVEL or VERSION_ID, which have to match what the system declares. - -SteamOS doesn't declare a SYSEXT_LEVEL, and the VERSION_ID increments with every -system update, so there's no stable values to declare compatibility against. +recommended to tweak those files directly. The configuration file at +`/etc/default/tailscaled` is left alone. The configuration file at +`/etc/systemd/system/tailscaled.service.d/override.conf` is reset every time this script is run to ensure the path to the binary is correct, but the preexisting file will be backed up in that directory as `override.conf.bak`. If something goes wrong, copy those files somewhere else and re-run the install script to get back to a working state. ## Common issues @@ -82,10 +44,6 @@ Resolution: Delete `/etc/default/tailscaled` and re-run installer script. ## How it works -It uses the same system extension method as the official guide, but we put the -`tailscaled.service` file directly in `/etc/systemd/system/` because it's -actually safe to put things there. Changes in `/etc/` are preserved in -`/var/lib/overlays/etc/upper/` via an overlayfs, meaning that they survive -updates. +The Tailscale binaries `tailscale` and `tailscaled` are installed in `/opt/tailscale/`. The Tailscale systemd unit file is installed at `/etc/systemd/system/tailscale.service`. The override file to reconfigure the services `Exec` commands is installed at `/etc/systemd/system/tailscaled.service.d/override.conf`. The defaults file for the variables `PORT` and `FLAGS` is installed at `/etc/default/tailscaled` -[official-guide]: https://tailscale.com/blog/steam-deck/ +The service is then started and enabled via `systemctl`. From 2b671d612ce4257f1def1ae192506c18dc62bcd0 Mon Sep 17 00:00:00 2001 From: Zac Holland Date: Wed, 20 Dec 2023 09:38:33 -0800 Subject: [PATCH 27/28] add daemon-reload after the override file is added --- tailscale.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tailscale.sh b/tailscale.sh index 046c57e..6069631 100644 --- a/tailscale.sh +++ b/tailscale.sh @@ -97,6 +97,9 @@ fi mkdir -p /etc/systemd/system/tailscaled.service.d cp -f override.conf /etc/systemd/system/tailscaled.service.d/override.conf +# capture the above override file in systemd +systemctl daemon-reload + echo "done." echo -n "Starting required services..." From 4decd0d07677405deca5a0e143cf53eacc26a572 Mon Sep 17 00:00:00 2001 From: Zac Holland Date: Wed, 20 Dec 2023 09:55:55 -0800 Subject: [PATCH 28/28] remove source /etc/os-release --- tailscale.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/tailscale.sh b/tailscale.sh index 6069631..1b26937 100644 --- a/tailscale.sh +++ b/tailscale.sh @@ -1,8 +1,5 @@ #!/usr/bin/env bash -# make system configuration vars available -source /etc/os-release - # set invocation settings for this script: # -e: Exit immediately if a command exits with a non-zero status. # -u: Treat unset variables as an error when substituting.