From 8d7b0792fb3d85be4f4357cdd6e65415b977e21a Mon Sep 17 00:00:00 2001 From: Benoit Pierre Date: Mon, 15 Dec 2025 03:36:55 +0100 Subject: [PATCH] kindle / pocketbook / remarkable: fix startup script change detection - prior to #14719, `$KOREADER_DIR` was not part of the environment, so an update relying on it without a restart from the parent launcher would crash KOReader on startup - pocketbook: fix check (`koreader.app` is located in `$KOREADER_DIR/..`) - remarkable: ensure `$KOREADER_DIR` remain correct after relocalization --- frontend/device/kindle/device.lua | 2 +- frontend/device/pocketbook/device.lua | 2 +- frontend/device/remarkable/device.lua | 2 +- platform/kindle/koreader.sh | 12 ++++++------ platform/kobo/koreader.sh | 1 + platform/pocketbook/koreader.app | 12 ++++++------ platform/remarkable/koreader.sh | 13 +++++++------ 7 files changed, 23 insertions(+), 21 deletions(-) diff --git a/frontend/device/kindle/device.lua b/frontend/device/kindle/device.lua index 7125b92a5..2f68032bf 100644 --- a/frontend/device/kindle/device.lua +++ b/frontend/device/kindle/device.lua @@ -801,7 +801,7 @@ end function Kindle:isStartupScriptUpToDate() local md5 = require("ffi/MD5") -- Compare the hash of the *active* script to the *potential* one. - return md5.sumFile("/var/tmp/koreader.sh") == md5.sumFile(os.getenv("KOREADER_DIR") .. "/koreader.sh") + return md5.sumFile("/var/tmp/koreader.sh") == md5.sumFile("koreader.sh") end function Kindle:UIManagerReady(uimgr) diff --git a/frontend/device/pocketbook/device.lua b/frontend/device/pocketbook/device.lua index d24e6e64f..44bfbd429 100644 --- a/frontend/device/pocketbook/device.lua +++ b/frontend/device/pocketbook/device.lua @@ -416,7 +416,7 @@ end function PocketBook:isStartupScriptUpToDate() local md5 = require("ffi/MD5") -- Compare the hash of the *active* script to the *potential* one. - return md5.sumFile("/tmp/koreader.app") == md5.sumFile(os.getenv("KOREADER_DIR") .. "/koreader.app") + return md5.sumFile("/tmp/koreader.app") == md5.sumFile("../koreader.app") end function PocketBook:UIManagerReady(uimgr) diff --git a/frontend/device/remarkable/device.lua b/frontend/device/remarkable/device.lua index 336e0e7ec..6d29e5de6 100644 --- a/frontend/device/remarkable/device.lua +++ b/frontend/device/remarkable/device.lua @@ -429,7 +429,7 @@ end function Remarkable:isStartupScriptUpToDate() local md5 = require("ffi/MD5") -- Compare the hash of the *active* script to the *potential* one. - return md5.sumFile("/tmp/koreader.sh") == md5.sumFile(os.getenv("KOREADER_DIR") .. "/koreader.sh") + return md5.sumFile("/tmp/koreader.sh") == md5.sumFile("koreader.sh") end function Remarkable:setEventHandlers(UIManager) diff --git a/platform/kindle/koreader.sh b/platform/kindle/koreader.sh index a7ef26f84..a069cc5ea 100755 --- a/platform/kindle/koreader.sh +++ b/platform/kindle/koreader.sh @@ -1,5 +1,11 @@ #!/bin/sh +export LC_ALL="en_US.UTF-8" + +UNPACK_DIR='/mnt/us' +# KOReader's working directory. +KOREADER_DIR="${UNPACK_DIR}/koreader" + # 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, @@ -13,17 +19,11 @@ if [ "$(dirname "${0}")" != "/var/tmp" ]; then exec /var/tmp/koreader.sh "$@" fi -export LC_ALL="en_US.UTF-8" - PROC_KEYPAD="/proc/keypad" PROC_FIVEWAY="/proc/fiveway" [ -e "${PROC_KEYPAD}" ] && echo unlock >"${PROC_KEYPAD}" [ -e "${PROC_FIVEWAY}" ] && echo unlock >"${PROC_FIVEWAY}" -UNPACK_DIR='/mnt/us' -# KOReader's working directory -export KOREADER_DIR="${UNPACK_DIR}/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 diff --git a/platform/kobo/koreader.sh b/platform/kobo/koreader.sh index fb4f3c0a6..11419d234 100755 --- a/platform/kobo/koreader.sh +++ b/platform/kobo/koreader.sh @@ -1,4 +1,5 @@ #!/bin/sh + export LC_ALL="en_US.UTF-8" # Compute our working directory in an extremely defensive manner diff --git a/platform/pocketbook/koreader.app b/platform/pocketbook/koreader.app index 7717503ae..fd9482321 100755 --- a/platform/pocketbook/koreader.app +++ b/platform/pocketbook/koreader.app @@ -1,5 +1,11 @@ #!/bin/sh +export LC_ALL="en_US.UTF-8" + +UNPACK_DIR='/mnt/ext1' +# KOReader's working directory. +KOREADER_DIR="${UNPACK_DIR}/applications/koreader" + # Relocalize ourselves to /tmp: this is used by KOReader to detect if the # original script has changed after an update (requiring a complete restart # from the parent launcher). @@ -9,12 +15,6 @@ if [ "$(dirname "${0}")" != '/tmp' ]; then exec '/tmp/koreader.app' "$@" fi -export LC_ALL="en_US.UTF-8" - -UNPACK_DIR='/mnt/ext1' -# working directory of koreader -export KOREADER_DIR="${UNPACK_DIR}/applications/koreader" - # load our own shared libraries if possible, solely because we don't control InkView, and we'd rather not it have load duplicate system libs... # (We handle this via DT_RPATH for our own stuff). export LD_LIBRARY_PATH="${KOREADER_DIR}/libs${LD_LIBRARY_PATH+:}${LD_LIBRARY_PATH}" diff --git a/platform/remarkable/koreader.sh b/platform/remarkable/koreader.sh index 93a15df18..7fb1eaa49 100755 --- a/platform/remarkable/koreader.sh +++ b/platform/remarkable/koreader.sh @@ -1,5 +1,12 @@ #!/bin/sh +export LC_ALL="en_US.UTF-8" + +# KOReader's working directory. +# NOTE: We need to remember the *actual* KOREADER_DIR, not the relocalized version in /tmp... +export KOREADER_DIR="${KOREADER_DIR:-${0%/*}}" +UNPACK_DIR="${KOREADER_DIR%/*}" + # Relocalize ourselves to /tmp: this is used by KOReader to detect if the # original script has changed after an update (requiring a complete restart # from the parent launcher). @@ -9,12 +16,6 @@ if [ "$(dirname "${0}")" != '/tmp' ]; then exec '/tmp/koreader.sh' "$@" fi -export LC_ALL="en_US.UTF-8" - -# working directory of koreader -export KOREADER_DIR="${0%/*}" -UNPACK_DIR="${KOREADER_DIR%/*}" - # we're always starting from our working directory cd "${KOREADER_DIR}" || exit