From 72fd93c4ddae4542ffc1f34793b52f618a14d9db Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Sat, 11 Jan 2020 04:05:14 +0100 Subject: [PATCH] Unbreak OTA on Kindle (#5758) * Deref hardlinks in tarballs * Ensure an OTA won't break the launcher script, which'd screw the user on exit. --- Makefile | 10 +++++----- platform/kindle/koreader.sh | 18 ++++++++++++++++++ platform/kindle/libkohelper.sh | 4 ++-- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index a92f9a58a..535a4ab03 100644 --- a/Makefile +++ b/Makefile @@ -202,7 +202,7 @@ kindleupdate: all # note that the targz file extension is intended to keep ISP from caching # the file, see koreader#1644. cd $(INSTALL_DIR) && \ - tar -I"gzip --rsyncable" -cah --no-recursion -f ../$(KINDLE_PACKAGE_OTA) \ + tar --hard-dereference -I"gzip --rsyncable" -cah --no-recursion -f ../$(KINDLE_PACKAGE_OTA) \ -T koreader/ota/package.index KOBO_PACKAGE:=koreader-kobo$(KODEDUG_SUFFIX)-$(VERSION).zip @@ -233,7 +233,7 @@ koboupdate: all koreader/ota/package.index koreader.png README_kobo.txt # make gzip koboupdate for zsync OTA update cd $(INSTALL_DIR) && \ - tar -I"gzip --rsyncable" -cah --no-recursion -f ../$(KOBO_PACKAGE_OTA) \ + tar --hard-dereference -I"gzip --rsyncable" -cah --no-recursion -f ../$(KOBO_PACKAGE_OTA) \ -T koreader/ota/package.index PB_PACKAGE:=koreader-pocketbook$(KODEDUG_SUFFIX)-$(VERSION).zip @@ -272,7 +272,7 @@ pbupdate: all applications/koreader/ota/package.index system # make gzip pbupdate for zsync OTA update cd $(INSTALL_DIR)/applications && \ - tar -I"gzip --rsyncable" -cah --no-recursion -f ../../$(PB_PACKAGE_OTA) \ + tar --hard-dereference -I"gzip --rsyncable" -cah --no-recursion -f ../../$(PB_PACKAGE_OTA) \ -T koreader/ota/package.index utupdate: all @@ -410,7 +410,7 @@ sony-prstuxupdate: all koreader/ota/package.index # make gzip sonyprstux update for zsync OTA update cd $(INSTALL_DIR) && \ - tar -I"gzip --rsyncable" -cah --no-recursion -f ../$(SONY_PRSTUX_PACKAGE_OTA) \ + tar --hard-dereference -I"gzip --rsyncable" -cah --no-recursion -f ../$(SONY_PRSTUX_PACKAGE_OTA) \ -T koreader/ota/package.index CERVANTES_PACKAGE:=koreader-cervantes$(KODEDUG_SUFFIX)-$(VERSION).zip @@ -439,7 +439,7 @@ cervantesupdate: all koreader/ota/package.index # make gzip cervantes update for zsync OTA update cd $(INSTALL_DIR) && \ - tar -I"gzip --rsyncable" -cah --no-recursion -f ../$(CERVANTES_PACKAGE_OTA) \ + tar --hard-dereference -I"gzip --rsyncable" -cah --no-recursion -f ../$(CERVANTES_PACKAGE_OTA) \ -T koreader/ota/package.index update: diff --git a/platform/kindle/koreader.sh b/platform/kindle/koreader.sh index db82f15cb..55e2b6ec3 100755 --- a/platform/kindle/koreader.sh +++ b/platform/kindle/koreader.sh @@ -1,4 +1,15 @@ #!/bin/sh + +# NOTE: Stupid workaround to make sure the script we end up running is a *copy*, +# living in a magical land that doesn't suffer from gross filesystem deficiencies. +# Otherwise, the vfat+fuse mess means an OTA update will break the script on exit, +# and potentially leave the user in a broken state, with the WM still paused... +if [ "$(dirname "${0}")" != "/var/tmp" ]; then + cp -pf "${0}" /var/tmp/koreader.sh + chmod 777 /var/tmp/koreader.sh + exec /var/tmp/koreader.sh "$@" +fi + export LC_ALL="en_US.UTF-8" PROC_KEYPAD="/proc/keypad" @@ -9,6 +20,10 @@ PROC_FIVEWAY="/proc/fiveway" # KOReader's working directory export KOREADER_DIR="/mnt/us/koreader" +# NOTE: Same vfat+fuse shenanigans needed for FBInk, before we source libko... +cp -pf "${KOREADER_DIR}/fbink" /var/tmp/fbink +chmod 777 /var/tmp/fbink + # Load our helper functions... if [ -f "${KOREADER_DIR}/libkohelper.sh" ]; then # shellcheck source=/dev/null @@ -352,4 +367,7 @@ if [ "${PASSCODE_DISABLED}" = "yes" ]; then touch "/var/local/system/userpasswdenabled" fi +# Wipe the clones on exit +rm -f /var/tmp/koreader.sh /var/tmp/fbink + exit ${RETURN_VALUE} diff --git a/platform/kindle/libkohelper.sh b/platform/kindle/libkohelper.sh index 62fa36f20..466af905b 100644 --- a/platform/kindle/libkohelper.sh +++ b/platform/kindle/libkohelper.sh @@ -18,8 +18,8 @@ fi ## Check if we have an FBInk binary available somewhere... # Default to something that won't horribly blow up... FBINK_BIN="true" -for my_dir in koreader libkh/bin linkss/bin linkfonts/bin usbnet/bin; do - my_fbink="/mnt/us/${my_dir}/fbink" +for my_dir in /var/tmp /mnt/us/koreader /mnt/us/libkh/bin /mnt/us/linkss/bin /mnt/us/linkfonts/bin /mnt/us/usbnet/bin; do + my_fbink="${my_dir}/fbink" if [ -x "${my_fbink}" ]; then FBINK_BIN="${my_fbink}" # Got it!