diff --git a/platform/cervantes/koreader.sh b/platform/cervantes/koreader.sh index d82a38489..09049e997 100755 --- a/platform/cervantes/koreader.sh +++ b/platform/cervantes/koreader.sh @@ -4,6 +4,7 @@ export LC_ALL="en_US.UTF-8" # working directory of koreader KOREADER_DIR="${0%/*}" +UNPACK_DIR="${KOREADER_DIR%/*}" # we're always starting from our working directory cd "${KOREADER_DIR}" || exit @@ -14,6 +15,8 @@ ko_update_check() { INSTALLED="${KOREADER_DIR}/ota/koreader.installed.tar" if [ -f "${NEWUPDATE}" ]; then ./fbink -q -y -7 -pmh "Updating KOReader" + # Keep a copy of the old manifest for cleaning leftovers later. + cp "${KOREADER_DIR}/ota/package.index" /tmp/ # Setup the FBInk daemon export FBINK_NAMED_PIPE="/tmp/koreader.fbink" rm -f "${FBINK_NAMED_PIPE}" @@ -30,6 +33,8 @@ ko_update_check() { # Cleanup behind us... if [ "${fail}" -eq 0 ]; then mv "${NEWUPDATE}" "${INSTALLED}" + # Cleanup leftovers from previous install. + (cd "${UNPACK_DIR}" && grep -xvFf "${KOREADER_DIR}/ota/package.index" /tmp/package.index | xargs -r rm -vf) ./fbink -q -y -6 -pm "Update successful :)" ./fbink -q -y -5 -pm "KOReader will start momentarily . . ." else @@ -37,7 +42,7 @@ ko_update_check() { ./fbink -q -y -6 -pmh "Update failed :(" ./fbink -q -y -5 -pm "KOReader may fail to function properly!" fi - rm -f "${NEWUPDATE}" # always purge newupdate to prevent update loops + rm -f /tmp/package.index "${NEWUPDATE}" # always purge newupdate to prevent update loops unset CPOINTS FBINK_NAMED_PIPE unset BLOCKS FILESIZE FBINK_PID # Ensure everything is flushed to disk before we restart. This *will* stall for a while on slow storage! diff --git a/platform/kindle/koreader.sh b/platform/kindle/koreader.sh index 25b99a3e1..086187b96 100755 --- a/platform/kindle/koreader.sh +++ b/platform/kindle/koreader.sh @@ -17,8 +17,9 @@ 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="/mnt/us/koreader" +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 @@ -123,6 +124,8 @@ ko_update_check() { logmsg "Updating KOReader . . ." # Let our checkpoint script handle the detailed visual feedback... eips_print_bottom_centered "Updating KOReader" 3 + # Keep a copy of the old manifest for cleaning leftovers later. + cp "${KOREADER_DIR}/ota/package.index" /tmp/ # Setup the FBInk daemon export FBINK_NAMED_PIPE="/tmp/koreader.fbink" rm -f "${FBINK_NAMED_PIPE}" @@ -146,6 +149,8 @@ ko_update_check() { # Cleanup behind us... if [ "${fail}" -eq 0 ]; then mv "${NEWUPDATE}" "${INSTALLED}" + # Cleanup leftovers from previous install. + (cd "${UNPACK_DIR}" && grep -xvFf "${KOREADER_DIR}/ota/package.index" /tmp/package.index | xargs -r rm -vf) logmsg "Update successful :)" eips_print_bottom_centered "Update successful :)" 2 eips_print_bottom_centered "KOReader will start momentarily . . ." 1 @@ -160,7 +165,7 @@ ko_update_check() { eips_print_bottom_centered "Update failed :(" 2 eips_print_bottom_centered "KOReader may fail to function properly" 1 fi - rm -f "${NEWUPDATE}" # always purge newupdate to prevent update loops + rm -f /tmp/package.index "${NEWUPDATE}" # always purge newupdate to prevent update loops unset CPOINTS FBINK_NAMED_PIPE unset BLOCKS FILESIZE FBINK_PID # Ensure everything is flushed to disk before we restart. This *will* stall for a while on slow storage! diff --git a/platform/kobo/koreader.sh b/platform/kobo/koreader.sh index fd8a2e041..58c218d45 100755 --- a/platform/kobo/koreader.sh +++ b/platform/kobo/koreader.sh @@ -5,6 +5,7 @@ export LC_ALL="en_US.UTF-8" SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)" # NOTE: We need to remember the *actual* KOREADER_DIR, not the relocalized version in /tmp... export KOREADER_DIR="${KOREADER_DIR:-${SCRIPT_DIR}}" +UNPACK_DIR="${KOREADER_DIR%/*}" # We rely on starting from our working directory, and it needs to be set, sane and absolute. cd "${KOREADER_DIR:-/dev/null}" || exit @@ -95,6 +96,8 @@ ko_update_check() { # Clear screen to delete UI leftovers ./fbink --cls ./fbink -q -y -7 -pmh "Updating KOReader" + # Keep a copy of the old manifest for cleaning leftovers later. + cp "${KOREADER_DIR}/ota/package.index" /tmp/ # Setup the FBInk daemon export FBINK_NAMED_PIPE="/tmp/koreader.fbink" rm -f "${FBINK_NAMED_PIPE}" @@ -119,6 +122,8 @@ ko_update_check() { # Cleanup behind us... if [ "${fail}" -eq 0 ]; then mv "${NEWUPDATE}" "${INSTALLED}" + # Cleanup leftovers from previous install. + (cd "${UNPACK_DIR}" && grep -xvFf "${KOREADER_DIR}/ota/package.index" /tmp/package.index | xargs -r rm -vf) ./fbink -q -y -6 -pm "Update successful :)" ./fbink -q -y -5 -pm "KOReader will start momentarily . . ." @@ -131,7 +136,7 @@ ko_update_check() { ./fbink -q -y -6 -pmh "Update failed :(" ./fbink -q -y -5 -pm "KOReader may fail to function properly!" fi - rm -f "${NEWUPDATE}" # always purge newupdate to prevent update loops + rm -f /tmp/package.index "${NEWUPDATE}" # always purge newupdate to prevent update loops unset CPOINTS FBINK_NAMED_PIPE unset BLOCKS FILESIZE FBINK_PID # Ensure everything is flushed to disk before we restart. This *will* stall for a while on slow storage! diff --git a/platform/pocketbook/koreader.app b/platform/pocketbook/koreader.app index 18ef49e74..8445d41d5 100755 --- a/platform/pocketbook/koreader.app +++ b/platform/pocketbook/koreader.app @@ -1,8 +1,9 @@ #!/bin/sh export LC_ALL="en_US.UTF-8" +UNPACK_DIR='/mnt/ext1' # working directory of koreader -KOREADER_DIR="/mnt/ext1/applications/koreader" +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). @@ -30,6 +31,8 @@ ko_update_check() { INSTALLED="${KOREADER_DIR}/ota/koreader.installed.tar" if [ -f "${NEWUPDATE}" ]; then "${KOREADER_DIR}/fbink" -q -y -7 -pmh "Updating KOReader" + # Keep a copy of the old manifest for cleaning leftovers later. + sed 's,^../,,' "${KOREADER_DIR}/ota/package.index" >/tmp/package.index.old # Setup the FBInk daemon export FBINK_NAMED_PIPE="/tmp/.koreader.fbink" rm -f "${FBINK_NAMED_PIPE}" @@ -60,6 +63,9 @@ ko_update_check() { # Cleanup behind us... if [ "${fail}" -eq 0 ]; then mv "${NEWUPDATE}" "${INSTALLED}" + # Cleanup leftovers from previous install. + sed 's,^../,,' "${KOREADER_DIR}/ota/package.index" >/tmp/package.index.new + (cd "${UNPACK_DIR}" && grep -xvFf /tmp/package.index.new /tmp/package.index.old | xargs -r rm -vf) "${KOREADER_DIR}/fbink" -q -y -6 -pm "Update successful :)" "${KOREADER_DIR}/fbink" -q -y -5 -pm "KOReader will start momentarily . . ." else @@ -67,7 +73,7 @@ ko_update_check() { "${KOREADER_DIR}/fbink" -q -y -6 -pmh "Update failed :(" "${KOREADER_DIR}/fbink" -q -y -5 -pm "KOReader may fail to function properly!" fi - rm -f "${NEWUPDATE}" # always purge newupdate to prevent update loops + rm -f /tmp/package.index.old /tmp/package.index.new "${NEWUPDATE}" # always purge newupdate to prevent update loops unset CPOINTS FBINK_NAMED_PIPE unset BLOCKS FILESIZE FBINK_PID # Ensure everything is flushed to disk before we restart. This *will* stall for a while on slow storage! diff --git a/platform/remarkable/koreader.sh b/platform/remarkable/koreader.sh index 0ca060f36..37d763424 100755 --- a/platform/remarkable/koreader.sh +++ b/platform/remarkable/koreader.sh @@ -2,6 +2,7 @@ export LC_ALL="en_US.UTF-8" # working directory of koreader KOREADER_DIR="${0%/*}" +UNPACK_DIR="${KOREADER_DIR%/*}" # we're always starting from our working directory cd "${KOREADER_DIR}" || exit @@ -26,6 +27,8 @@ ko_update_check() { fi ./fbink -q -y -7 -pmh "Updating KOReader" + # Keep a copy of the old manifest for cleaning leftovers later. + cp "${KOREADER_DIR}/ota/package.index" /tmp/ # Setup the FBInk daemon export FBINK_NAMED_PIPE="/tmp/koreader.fbink" rm -f "${FBINK_NAMED_PIPE}" @@ -42,6 +45,8 @@ ko_update_check() { # Cleanup behind us... if [ "${fail}" -eq 0 ]; then mv "${NEWUPDATE}" "${INSTALLED}" + # Cleanup leftovers from previous install. + (cd "${UNPACK_DIR}" && grep -xvFf "${KOREADER_DIR}/ota/package.index" /tmp/package.index | xargs -r rm -vf) ./fbink -q -y -6 -pm "Update successful :)" ./fbink -q -y -5 -pm "KOReader will start momentarily . . ." else @@ -49,7 +54,7 @@ ko_update_check() { ./fbink -q -y -6 -pmh "Update failed :(" ./fbink -q -y -5 -pm "KOReader may fail to function properly!" fi - rm -f "${NEWUPDATE}" # always purge newupdate to prevent update loops + rm -f /tmp/package.index "${NEWUPDATE}" # always purge newupdate to prevent update loops unset CPOINTS FBINK_NAMED_PIPE unset BLOCKS FILESIZE FBINK_PID # Ensure everything is flushed to disk before we restart. This *will* stall for a while on slow storage!