PocketBook: Avoid arithmetics expansions in startup script

Because everything is terrible.

Fix #7732
reviewable/pr7776/r1
NiLuJe 3 years ago committed by Frans de Jonge
parent 5a468b8cf2
commit 5d82907e3c

@ -33,13 +33,16 @@ ko_update_check() {
# NOTE: See frontend/ui/otamanager.lua for a few more details on how we squeeze a percentage out of tar's checkpoint feature
# NOTE: %B should always be 512 in our case, so let stat do part of the maths for us instead of using %s ;).
FILESIZE="$(stat -c %b "${NEWUPDATE}")"
BLOCKS="$((FILESIZE / 20))"
export CPOINTS="$((BLOCKS / 100))"
# shellcheck disable=SC2003
BLOCKS="$(expr "${FILESIZE}" / 20)"
# shellcheck disable=SC2003
CPOINTS="$(expr "${BLOCKS}" / 100)"
export CPOINTS
# NOTE: We don't run as root, but folders created over USBMS are owned by root, which yields fun permission shenanigans...
# c.f., https://github.com/koreader/koreader/issues/7581
KO_PB_TARLOG="/tmp/.koreader.tar"
# shellcheck disable=SC2016
"${KOREADER_DIR}/tar" --no-same-permissions --no-same-owner --checkpoint="${CPOINTS}" --checkpoint-action=exec='printf "%s" $((TAR_CHECKPOINT / CPOINTS)) > ${FBINK_NAMED_PIPE}' -C "/mnt/ext1" -xf "${NEWUPDATE}" 2>"${KO_PB_TARLOG}"
"${KOREADER_DIR}/tar" --no-same-permissions --no-same-owner --checkpoint="${CPOINTS}" --checkpoint-action=exec='printf "%s" $(expr ${TAR_CHECKPOINT} / ${CPOINTS}) > ${FBINK_NAMED_PIPE}' -C "/mnt/ext1" -xf "${NEWUPDATE}" 2>"${KO_PB_TARLOG}"
fail=$?
kill -TERM "${FBINK_PID}"
# As mentioned above, filter out potential chmod & utime failures...
@ -116,10 +119,12 @@ while [ "${RETURN_VALUE}" -ne 0 ]; do
# Did we crash?
if [ "${RETURN_VALUE}" -ne 0 ] && [ "${RETURN_VALUE}" -ne ${KO_RC_RESTART} ]; then
# Increment the crash counter
CRASH_COUNT=$((CRASH_COUNT + 1))
CRASH_TS=$(date +'%s')
# shellcheck disable=SC2003
CRASH_COUNT="$(expr ${CRASH_COUNT} + 1)"
CRASH_TS="$(date +'%s')"
# Reset it to a first crash if it's been a while since our last crash...
if [ $((CRASH_TS - CRASH_PREV_TS)) -ge 20 ]; then
# shellcheck disable=SC2003
if [ "$(expr "${CRASH_TS}" - "${CRASH_PREV_TS}")" -ge 20 ]; then
CRASH_COUNT=1
fi
@ -139,8 +144,10 @@ while [ "${RETURN_VALUE}" -ne 0 ]; do
eval "$("${KOREADER_DIR}/fbink" -e | tr ';' '\n' | grep -e viewWidth -e viewHeight -e FONTH | tr '\n' ';')"
# Compute margins & sizes relative to the screen's resolution, so we end up with a similar layout, no matter the device.
# Height @ ~56.7%, w/ a margin worth 1.5 lines
bombHeight=$((viewHeight / 2 + viewHeight / 15))
bombMargin=$((FONTH + FONTH / 2))
# shellcheck disable=SC2003
bombHeight="$(expr ${viewHeight} / 2 + ${viewHeight} / 15)"
# shellcheck disable=SC2003
bombMargin="$(expr ${FONTH} + ${FONTH} / 2)"
# With a little notice at the top of the screen, on a big gray screen of death ;).
"${KOREADER_DIR}/fbink" -q -b -c -B GRAY9 -m -y 1 "Don't Panic! (Crash n°${CRASH_COUNT} -> ${RETURN_VALUE})"
if [ ${CRASH_COUNT} -eq 1 ]; then
@ -149,11 +156,12 @@ while [ "${RETURN_VALUE}" -ne 0 ]; do
fi
# U+1F4A3, the hard way, because we can't use \u or \U escape sequences...
# shellcheck disable=SC2039,SC3003
"${KOREADER_DIR}/fbink" -q -b -O -m -t regular=${KOREADER_DIR}/fonts/freefont/FreeSerif.ttf,px=${bombHeight},top=${bombMargin} -- $'\xf0\x9f\x92\xa3'
"${KOREADER_DIR}/fbink" -q -b -O -m -t regular=${KOREADER_DIR}/fonts/freefont/FreeSerif.ttf,px="${bombHeight}",top="${bombMargin}" -- $'\xf0\x9f\x92\xa3'
# And then print the tail end of the log on the bottom of the screen...
crashLog="$(tail -n 25 crash.log | sed -e 's/\t/ /g')"
# The idea for the margins being to leave enough room for an fbink -Z bar, small horizontal margins, and a font size based on what 6pt looked like @ 265dpi
"${KOREADER_DIR}/fbink" -q -b -O -t regular=${KOREADER_DIR}/fonts/droid/DroidSansMono.ttf,top=$((viewHeight / 2 + FONTH * 2 + FONTH / 2)),left=$((viewWidth / 60)),right=$((viewWidth / 60)),px=$((viewHeight / 64)) -- "${crashLog}"
# shellcheck disable=SC2003
"${KOREADER_DIR}/fbink" -q -b -O -t regular=${KOREADER_DIR}/fonts/droid/DroidSansMono.ttf,top="$(expr ${viewHeight} / 2 + ${FONTH} '*' 2 + ${FONTH} / 2)",left="$(expr ${viewWidth} / 60)",right="$(expr ${viewWidth} / 60)",px="$(expr ${viewHeight} / 64)" -- "${crashLog}"
# So far, we hadn't triggered an actual screen refresh, do that now, to make sure everything is bundled in a single flashing refresh.
${KOREADER_DIR}/fbink -q -f -s
# Cue a lemming's faceplant sound effect!

Loading…
Cancel
Save