Browse Source

[CI] Add curly braces check (#5809)

Update shellcheck and shfmt to the latest version.

Fixes <https://github.com/koreader/koreader/issues/5152>.

Btw, you can apply shellcheck suggestions with a command like:

```
shellcheck --include=SC2250 -f diff *.sh | git apply
```
reviewable/pr5823/r1
Frans de Jonge 1 year ago
committed by GitHub
parent
commit
668eee97fa
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 124 additions and 124 deletions
  1. +3
    -3
      .ci/after_success.sh
  2. +5
    -5
      .ci/before_install.sh
  3. +1
    -1
      .ci/check.sh
  4. +14
    -14
      .ci/common.sh
  5. +1
    -1
      .ci/helper_luarocks.sh
  6. +4
    -4
      .ci/helper_shellchecks.sh
  7. +6
    -6
      .ci/install.sh
  8. +1
    -0
      .shellcheckrc
  9. +26
    -26
      kodev
  10. +5
    -5
      platform/appimage/AppRun
  11. +4
    -4
      platform/cervantes/disable-usbms.sh
  12. +5
    -5
      platform/cervantes/enable-usbms.sh
  13. +4
    -4
      platform/cervantes/koreader-standalone.sh
  14. +3
    -4
      platform/debian/do_debian_package.sh
  15. +3
    -3
      platform/debian/koreader.sh
  16. +1
    -1
      platform/kindle/extensions/koreader/bin/koreader-ext.sh
  17. +3
    -3
      platform/kobo/enable-wifi.sh
  18. +9
    -9
      platform/kobo/koreader.sh
  19. +4
    -4
      platform/pocketbook/koreader.app
  20. +3
    -3
      platform/ubuntu-touch/koreader.sh
  21. +8
    -8
      plugins/backgroundrunner.koplugin/luawrapper.sh
  22. +11
    -11
      plugins/backgroundrunner.koplugin/wrapper.sh

+ 3
- 3
.ci/after_success.sh View File

@ -8,7 +8,7 @@ set +e
if [ -z "${CIRCLE_PULL_REQUEST}" ] && [ "${CIRCLE_BRANCH}" = 'master' ]; then
echo "CIRCLE_NODE_INDEX: ${CIRCLE_NODE_INDEX}"
if [ "$CIRCLE_NODE_INDEX" = 1 ]; then
if [ "${CIRCLE_NODE_INDEX}" = 1 ]; then
echo -e "\\n${ANSI_GREEN}Updating translation source file."
make pot
pushd l10n && {
@ -27,7 +27,7 @@ if [ -z "${CIRCLE_PULL_REQUEST}" ] && [ "${CIRCLE_BRANCH}" = 'master' ]; then
# push doc update
pushd doc && {
luajit "$(which ldoc)" . 2>/dev/null
luajit "$(command -v ldoc)" . 2>/dev/null
if [ ! -d html ]; then
echo "Failed to generate documents..."
exit 1
@ -48,7 +48,7 @@ if [ -z "${CIRCLE_PULL_REQUEST}" ] && [ "${CIRCLE_BRANCH}" = 'master' ]; then
make testfront BUSTED_OVERRIDES="--output=junit -Xoutput junit-test-results.xml"
fi
if [ "$CIRCLE_NODE_INDEX" = 0 ]; then
if [ "${CIRCLE_NODE_INDEX}" = 0 ]; then
travis_retry make coverage
pushd koreader-*/koreader && {
# see https://github.com/codecov/example-lua

+ 5
- 5
.ci/before_install.sh View File

@ -1,15 +1,15 @@
#!/usr/bin/env bash
# don't do this for clang
if [ "$CXX" = "g++" ]; then
if [ "${CXX}" = "g++" ]; then
export CXX="g++-5" CC="gcc-5"
fi
# in case anything ignores the environment variables, override through PATH
mkdir bin
ln -s "$(which gcc-5)" bin/cc
ln -s "$(which gcc-5)" bin/gcc
ln -s "$(which c++)" bin/c++
ln -s "$(which g++-5)" bin/g++
ln -s "$(command -v gcc-5)" bin/cc
ln -s "$(command -v gcc-5)" bin/gcc
ln -s "$(command -v c++)" bin/c++
ln -s "$(command -v g++-5)" bin/g++
# Travis only makes a shallow clone of --depth=50. KOReader is small enough that
# we can just grab it all. This is necessary to generate the version number,

+ 1
- 1
.ci/check.sh View File

@ -37,4 +37,4 @@ if [ "${untagged_todo}" ]; then
fi
echo -e "\n${ANSI_GREEN}Luacheck results"
luajit "$(which luacheck)" --no-color -q {reader,setupkoenv,datastorage}.lua frontend plugins spec
luajit "$(command -v luacheck)" --no-color -q {reader,setupkoenv,datastorage}.lua frontend plugins spec

+ 14
- 14
.ci/common.sh View File

@ -15,23 +15,23 @@ travis_retry() {
local count=1
set +e
while [ $count -le 3 ]; do
[ $result -ne 0 ] && {
echo -e "\n${ANSI_RED}The command \"$*\" failed. Retrying, $count of 3.${ANSI_RESET}\n" >&2
while [ ${count} -le 3 ]; do
[ ${result} -ne 0 ] && {
echo -e "\n${ANSI_RED}The command \"$*\" failed. Retrying, ${count} of 3.${ANSI_RESET}\n" >&2
}
"$@"
result=$?
[ $result -eq 0 ] && break
[ ${result} -eq 0 ] && break
count=$((count + 1))
sleep 1
done
[ $count -gt 3 ] && {
[ ${count} -gt 3 ] && {
echo -e "\n${ANSI_RED}The command \"$*\" failed 3 times.${ANSI_RESET}\n" >&2
}
set -e
return $result
return ${result}
}
retry_cmd() {
@ -42,23 +42,23 @@ retry_cmd() {
retry_cnt=$1
shift 1
while [ $count -le "${retry_cnt}" ]; do
[ $result -ne 0 ] && {
echo -e "\n${ANSI_RED}The command \"$*\" failed. Retrying, $count of ${retry_cnt}${ANSI_RESET}\n" >&2
while [ ${count} -le "${retry_cnt}" ]; do
[ ${result} -ne 0 ] && {
echo -e "\n${ANSI_RED}The command \"$*\" failed. Retrying, ${count} of ${retry_cnt}${ANSI_RESET}\n" >&2
}
"$@"
result=$?
[ $result -eq 0 ] && break
[ ${result} -eq 0 ] && break
count=$((count + 1))
sleep 1
done
[ $count -gt "${retry_cnt}" ] && {
[ ${count} -gt "${retry_cnt}" ] && {
echo -e "\n${ANSI_RED}The command \"$*\" failed ${retry_cnt} times.${ANSI_RESET}\n" >&2
}
set -e
return $result
return ${result}
}
# export CI_BUILD_DIR=${TRAVIS_BUILD_DIR}
@ -67,8 +67,8 @@ eval CI_BUILD_DIR="${CIRCLE_WORKING_DIRECTORY}"
export CI_BUILD_DIR
test -e "${HOME}/bin" || mkdir "${HOME}/bin"
export PATH=$PWD/bin:$HOME/bin:$PATH
export PATH=$PATH:${CI_BUILD_DIR}/install/bin
export PATH=${PWD}/bin:${HOME}/bin:${PATH}
export PATH=${PATH}:${CI_BUILD_DIR}/install/bin
if [ -f "${CI_BUILD_DIR}/install/bin/luarocks" ]; then
# add local rocks to $PATH
eval "$(luarocks path --bin)"

+ 1
- 1
.ci/helper_luarocks.sh View File

@ -7,7 +7,7 @@ source "${CI_DIR}/common.sh"
rm -rf "${HOME}/.luarocks"
mkdir "${HOME}/.luarocks"
cp "${CI_BUILD_DIR}/install/etc/luarocks/config.lua" "${HOME}/.luarocks/config.lua"
echo "wrap_bin_scripts = false" >>"$HOME/.luarocks/config.lua"
echo "wrap_bin_scripts = false" >>"${HOME}/.luarocks/config.lua"
travis_retry luarocks --local install luafilesystem
# for verbose_print module
travis_retry luarocks --local install ansicolors

+ 4
- 4
.ci/helper_shellchecks.sh View File

@ -13,14 +13,14 @@ for shellscript in "${shellscript_locations[@]}"; do
echo -e "${ANSI_GREEN}Running shellcheck on ${shellscript}"
shellcheck "${shellscript}" || SHELLSCRIPT_ERROR=1
echo -e "${ANSI_GREEN}Running shfmt on ${shellscript}"
if ! shfmt -i 4 "${shellscript}" >/dev/null 2>&1; then
if ! shfmt -i 4 -ci "${shellscript}" >/dev/null 2>&1; then
echo -e "${ANSI_RED}Warning: ${shellscript} contains the following problem:"
shfmt -i 4 "${shellscript}" || SHELLSCRIPT_ERROR=1
shfmt -i 4 -ci "${shellscript}" || SHELLSCRIPT_ERROR=1
continue
fi
if [ "$(cat "${shellscript}")" != "$(shfmt -i 4 "${shellscript}")" ]; then
if [ "$(cat "${shellscript}")" != "$(shfmt -i 4 -ci "${shellscript}")" ]; then
echo -e "${ANSI_RED}Warning: ${shellscript} does not abide by coding style, diff for expected style:"
shfmt -i 4 "${shellscript}" | diff "${shellscript}" - || SHELLSCRIPT_ERROR=1
shfmt -i 4 -ci "${shellscript}" | diff "${shellscript}" - || SHELLSCRIPT_ERROR=1
fi
done

+ 6
- 6
.ci/install.sh View File

@ -31,8 +31,7 @@ if [ ! -f "${CI_BUILD_DIR}/install/bin/luarocks" ]; then
git checkout 6529891
cmake . -DWITH_LUAJIT21=ON -DCMAKE_INSTALL_PREFIX="${CI_BUILD_DIR}/install"
make install
} || exit
popd
} && popd || exit
else
echo -e "${ANSI_GREEN}Using cached luarocks."
fi
@ -50,9 +49,10 @@ else
fi
#install our own updated shellcheck
SHELLCHECK_URL="https://s3.amazonaws.com/travis-blue-public/binaries/ubuntu/14.04/x86_64/shellcheck-0.4.5.tar.bz2"
SHELLCHECK_VERSION="v0.7.0"
SHELLCHECK_URL="https://storage.googleapis.com/shellcheck/shellcheck-${SHELLCHECK_VERSION?}.linux.x86_64.tar.xz"
if ! command -v shellcheck; then
curl -sSL "${SHELLCHECK_URL}" | tar --exclude 'SHA256SUMS' --strip-components=1 -C "${HOME}/bin" -xjf -
curl -sSL "${SHELLCHECK_URL}" | tar --exclude 'SHA256SUMS' --strip-components=1 -C "${HOME}/bin" -xJf -
chmod +x "${HOME}/bin/shellcheck"
shellcheck --version
else
@ -60,8 +60,8 @@ else
fi
# install shfmt
SHFMT_URL="https://github.com/mvdan/sh/releases/download/v1.3.1/shfmt_v1.3.1_linux_amd64"
if [ "$(shfmt --version)" != "v1.3.1" ]; then
SHFMT_URL="https://github.com/mvdan/sh/releases/download/v3.0.1/shfmt_v3.0.1_linux_amd64"
if [ "$(shfmt --version)" != "v3.0.1" ]; then
curl -sSL "${SHFMT_URL}" -o "${HOME}/bin/shfmt"
chmod +x "${HOME}/bin/shfmt"
else

+ 1
- 0
.shellcheckrc View File

@ -0,0 +1 @@
enable=require-variable-braces

+ 26
- 26
kodev View File

@ -40,26 +40,26 @@ function gnuplot_wrapper() {
# inspired by https://gist.github.com/nicolasazrak/32d68ed6c845a095f75f037ecc2f0436
trap capture_ctrl_c INT
TEMP_DIR=$(mktemp --directory /tmp/tmp.koreaderXXX)
LOG="$TEMP_DIR/memory.log"
SCRIPT_PNG="$TEMP_DIR/script_png.p"
SCRIPT_SHOW="$TEMP_DIR/script_show.p"
IMAGE_PNG="$TEMP_DIR/graph.png"
LOG="${TEMP_DIR}/memory.log"
SCRIPT_PNG="${TEMP_DIR}/script_png.p"
SCRIPT_SHOW="${TEMP_DIR}/script_show.p"
IMAGE_PNG="${TEMP_DIR}/graph.png"
echo "Memory plot output to $TEMP_DIR"
echo "Memory plot output to ${TEMP_DIR}"
cat >"$SCRIPT_PNG" <<EOL
cat >"${SCRIPT_PNG}" <<EOL
set term pngcairo size 1600,1200
set output "$IMAGE_PNG"
set output "${IMAGE_PNG}"
set ylabel "RSS"
set y2label "VSZ"
set ytics nomirror
set y2tics nomirror in
set yrange [0:*]
set y2range [0:*]
plot "$LOG" using 3 with lines axes x1y1 title "RSS", "$LOG" using 2 with lines axes x1y2 title "VSZ"
plot "${LOG}" using 3 with lines axes x1y1 title "RSS", "${LOG}" using 2 with lines axes x1y2 title "VSZ"
EOL
cat >"$SCRIPT_SHOW" <<EOL
cat >"${SCRIPT_SHOW}" <<EOL
set term wxt noraise
set ylabel "RSS"
set y2label "VSZ"
@ -67,15 +67,15 @@ set ytics nomirror
set y2tics nomirror in
set yrange [0:*]
set y2range [0:*]
plot "$LOG" using 3 with lines axes x1y1 title "RSS", "$LOG" using 2 with lines axes x1y2 title "VSZ"
plot "${LOG}" using 3 with lines axes x1y1 title "RSS", "${LOG}" using 2 with lines axes x1y2 title "VSZ"
pause 1
reread
EOL
function capture_ctrl_c() {
kill "$LOOP_PID"
kill "$GNUPLOT_PID"
gnuplot "$SCRIPT_PNG"
kill "${LOOP_PID}"
kill "${GNUPLOT_PID}"
gnuplot "${SCRIPT_PNG}"
exit
}
@ -87,7 +87,7 @@ EOL
sleep 1
done &
LOOP_PID=$!
gnuplot "$SCRIPT_SHOW" &
gnuplot "${SCRIPT_SHOW}" &
GNUPLOT_PID=$!
}
@ -161,7 +161,7 @@ ${SUPPORTED_TARGETS}"
KODEBUG_NO_DEFAULT=1
;;
*)
echo "ERROR: unknown option \"$PARAM\""
echo "ERROR: unknown option \"${PARAM}\""
echo "${BUILD_HELP_MSG}"
exit 1
;;
@ -215,7 +215,7 @@ ${SUPPORTED_TARGETS}"
assert_ret_zero $?
;;
pocketbook)
if ! command -v arm-obreey-linux-gnueabi-gcc>/dev/null && [ ! -d "${CURDIR}/base/toolchain/pocketbook-toolchain" ]; then
if ! command -v arm-obreey-linux-gnueabi-gcc >/dev/null && [ ! -d "${CURDIR}/base/toolchain/pocketbook-toolchain" ]; then
make pocketbook-toolchain
assert_ret_zero $?
fi
@ -278,7 +278,7 @@ ${SUPPORTED_TARGETS}"
KODEBUG_NO_DEFAULT=1
;;
*)
echo "ERROR: unknown option \"$PARAM\""
echo "ERROR: unknown option \"${PARAM}\""
echo "${BUILD_HELP_MSG}"
exit 1
;;
@ -383,7 +383,7 @@ ${SUPPORTED_RELEASE_TARGETS}"
exit 0
;;
*)
echo "ERROR: unknown option \"$PARAM\""
echo "ERROR: unknown option \"${PARAM}\""
echo "${RELEASE_HELP_MSG}"
exit 1
;;
@ -427,13 +427,13 @@ ${SUPPORTED_RELEASE_TARGETS}"
;;
android)
kodev-build android
export PATH=$PATH:${CURDIR}/base/toolchain/android-sdk-linux/tools
export PATH=${PATH}:${CURDIR}/base/toolchain/android-sdk-linux/tools
command -v android &>/dev/null || {
make -C "${CURDIR}/base/toolchain" android-sdk
}
ANDROID_HOME=$(dirname "$(dirname "$(command -v android)")")
export ANDROID_HOME
export PATH=$PATH:${NDK}
export PATH=${PATH}:${NDK}
make TARGET=android update
;;
pocketbook)
@ -595,7 +595,7 @@ TARGET:
exit 0
;;
*)
echo "ERROR: unknown option \"$PARAM\""
echo "ERROR: unknown option \"${PARAM}\""
echo "${RUN_HELP_MSG}"
exit 1
;;
@ -670,7 +670,7 @@ TARGET:
args="$*"
[[ "${args}" != /* ]] && args="${CURDIR}/${args}"
fi
KOREADER_COMMAND="$KOREADER_COMMAND ${args}"
KOREADER_COMMAND="${KOREADER_COMMAND} ${args}"
RETURN_VALUE=85
while [ "${RETURN_VALUE}" -eq 85 ]; do
@ -717,7 +717,7 @@ OPTIONS:
exit 0
;;
*)
echo "ERROR: unknown option \"$PARAM\""
echo "ERROR: unknown option \"${PARAM}\""
echo "${TEST_HELP_MSG}"
exit 1
;;
@ -783,7 +783,7 @@ OPTIONS:
exit 0
;;
*)
echo "ERROR: unknown option \"$PARAM\""
echo "ERROR: unknown option \"${PARAM}\""
echo "${COV_HELP_MSG}"
exit 1
;;
@ -804,8 +804,8 @@ OPTIONS:
-o "./spec/${target}/unit/verbose_print" \
--coverage \
--exclude-tags=nocov "${test_path}" || {
echo "Failed to run tests!" && exit 1
}
echo "Failed to run tests!" && exit 1
}
fi
if [ "${show_full}" -eq 1 ]; then
cat luacov.report.out

+ 5
- 5
platform/appimage/AppRun View File

@ -8,14 +8,14 @@ KOREADER_DIR="${0%/*}"
cd "${KOREADER_DIR}" || exit
# export load library path
export LD_LIBRARY_PATH=${KOREADER_DIR}/libs:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=${KOREADER_DIR}/libs:${LD_LIBRARY_PATH}
RETURN_VALUE=85
if [ $# -eq 0 ]; then
# no arguments
if [ -n "${XDG_DOCUMENTS_DIR+x}" ]; then
start_path=$XDG_DOCUMENTS_DIR
start_path=${XDG_DOCUMENTS_DIR}
else
start_path=$(pwd)
fi
@ -23,9 +23,9 @@ else
start_path="$*"
fi
while [ $RETURN_VALUE -eq 85 ]; do
./reader.lua "$start_path"
while [ ${RETURN_VALUE} -eq 85 ]; do
./reader.lua "${start_path}"
RETURN_VALUE=$?
done
exit $RETURN_VALUE
exit ${RETURN_VALUE}

+ 4
- 4
platform/cervantes/disable-usbms.sh View File

@ -8,7 +8,7 @@ sleep 1
PCB_ID=$(/usr/bin/ntxinfo /dev/mmcblk0 | grep pcb | cut -d ":" -f2)
DISK=/dev/mmcblk
if [ "$PCB_ID" -eq 22 ] || [ "$PCB_ID" -eq 23 ]; then
if [ "${PCB_ID}" -eq 22 ] || [ "${PCB_ID}" -eq 23 ]; then
PARTITION="${DISK}0p7"
else
PARTITION="${DISK}0p4"
@ -16,11 +16,11 @@ fi
MOUNT_ARGS="noatime,nodiratime,shortname=mixed,utf8"
dosfsck -a -w "$PARTITION" >dosfsck.log 2>&1
dosfsck -a -w "${PARTITION}" >dosfsck.log 2>&1
mount -o "$MOUNT_ARGS" -t vfat "$PARTITION" /mnt/onboard
mount -o "${MOUNT_ARGS}" -t vfat "${PARTITION}" /mnt/onboard
PARTITION=${DISK}1p1
[ -e "$PARTITION" ] && mount -o "$MOUNT_ARGS" -t vfat "$PARTITION" /mnt/sd
[ -e "${PARTITION}" ] && mount -o "${MOUNT_ARGS}" -t vfat "${PARTITION}" /mnt/sd

+ 5
- 5
platform/cervantes/enable-usbms.sh View File

@ -7,7 +7,7 @@ lsmod | grep -q g_file_storage && exit 1
PCB_ID=$(/usr/bin/ntxinfo /dev/mmcblk0 | grep pcb | cut -d ":" -f2)
DISK=/dev/mmcblk
if [ "$PCB_ID" -eq 22 ] || [ "$PCB_ID" -eq 23 ]; then
if [ "${PCB_ID}" -eq 22 ] || [ "${PCB_ID}" -eq 23 ]; then
PRODUCT_ID=${PRODUCT_ID:-"0xAD78"}
PARTITIONS="${DISK}0p7"
else
@ -21,13 +21,13 @@ sync
echo 3 >/proc/sys/vm/drop_caches
for name in public sd; do
DIR=/mnt/"$name"
if grep -q "$DIR" /proc/mounts; then
umount "$DIR" || umount -l "$DIR"
DIR=/mnt/"${name}"
if grep -q "${DIR}" /proc/mounts; then
umount "${DIR}" || umount -l "${DIR}"
fi
done
MODULE_PARAMETERS="vendor=0x2A47 product=${PRODUCT_ID} vendor_id=BQ product_id=Cervantes"
modprobe g_file_storage file="$PARTITIONS" stall=1 removable=1 "$MODULE_PARAMETERS"
modprobe g_file_storage file="${PARTITIONS}" stall=1 removable=1 "${MODULE_PARAMETERS}"
sleep 1

+ 4
- 4
platform/cervantes/koreader-standalone.sh View File

@ -16,7 +16,7 @@ fi
# assign public & private partition devices based on pcb.
PCB_ID=$(/usr/bin/ntxinfo /dev/mmcblk0 | grep pcb | cut -d ":" -f2)
if [ "$PCB_ID" -eq 22 ] || [ "$PCB_ID" -eq 23 ]; then
if [ "${PCB_ID}" -eq 22 ] || [ "${PCB_ID}" -eq 23 ]; then
PRIVATE="/dev/mmcblk0p5"
PUBLIC="/dev/mmcblk0p7"
else
@ -25,8 +25,8 @@ else
fi
# mount internal partitions
mount $PRIVATE /mnt/private
mount $PUBLIC /mnt/public
mount ${PRIVATE} /mnt/private
mount ${PUBLIC} /mnt/public
# mount sdcard if present
if [ -b /dev/mmcblk1p1 ]; then
@ -37,7 +37,7 @@ fi
[ -x /etc/init.d/connman ] && /etc/init.d/connman stop
# for Cervantes 4 unload realtek module.
if [ "$PCB_ID" -eq 68 ] && lsmod | grep -q 8189fs; then
if [ "${PCB_ID}" -eq 68 ] && lsmod | grep -q 8189fs; then
modprobe -r 8189fs
fi

+ 3
- 4
platform/debian/do_debian_package.sh View File

@ -33,7 +33,7 @@ command_exists() {
# Run only if dpkg-deb exists
COMMAND="dpkg-deb"
if command_exists "$COMMAND"; then
if command_exists "${COMMAND}"; then
mkdir -p "${INSTALL_DIR}/debian/DEBIAN"
{
echo "Section: graphics"
@ -52,12 +52,11 @@ if command_exists "$COMMAND"; then
} >"${INSTALL_DIR}/debian/DEBIAN/control"
(cd "${INSTALL_DIR}/.." \
&& fakeroot dpkg-deb -b "${INSTALL_DIR}/debian" "koreader-${VERSION}-${ARCH}.deb")
(cd "${INSTALL_DIR}/.." &&
fakeroot dpkg-deb -b "${INSTALL_DIR}/debian" "koreader-${VERSION}-${ARCH}.deb")
else
echo "${COMMAND} not found, unable to build Debian package"
exit 1
fi
exit 0

+ 3
- 3
platform/debian/koreader.sh View File

@ -21,10 +21,10 @@ KOREADER_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../lib/koreader"
cd "${KOREADER_DIR}" || exit
# export load library path
export LD_LIBRARY_PATH=${KOREADER_DIR}/libs:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=${KOREADER_DIR}/libs:${LD_LIBRARY_PATH}
RETURN_VALUE=85
while [ $RETURN_VALUE -eq 85 ]; do
while [ ${RETURN_VALUE} -eq 85 ]; do
./reader.lua "${ARGS}"
RETURN_VALUE=$?
# do not restart with saved arguments
@ -34,5 +34,5 @@ done
# remove the flag to avoid emulator confusion
export -n KO_MULTIUSER
exit $RETURN_VALUE
exit ${RETURN_VALUE}

+ 1
- 1
platform/kindle/extensions/koreader/bin/koreader-ext.sh View File

@ -77,7 +77,7 @@ update_koreader() {
unzip -q -o "${found_koreader_package}" -d "/mnt/us"
fail=$?
fi
if [ $fail -eq 0 ]; then
if [ ${fail} -eq 0 ]; then
# Cleanup behind us...
rm -f "${found_koreader_package}"
# Flush to disk first...

+ 3
- 3
platform/kobo/enable-wifi.sh View File

@ -11,8 +11,8 @@ lsmod | grep -q "${WIFI_MODULE}" || insmod "${WIFI_MODULE_PATH}"
sleep 1
ifconfig "${INTERFACE}" up
[ "$WIFI_MODULE" != "8189fs" ] && [ "${WIFI_MODULE}" != "8192es" ] && wlarm_le -i "${INTERFACE}" up
[ "${WIFI_MODULE}" != "8189fs" ] && [ "${WIFI_MODULE}" != "8192es" ] && wlarm_le -i "${INTERFACE}" up
pidof wpa_supplicant >/dev/null \
|| env -u LD_LIBRARY_PATH \
pidof wpa_supplicant >/dev/null ||
env -u LD_LIBRARY_PATH \
wpa_supplicant -D wext -s -i "${INTERFACE}" -O /var/run/wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -B

+ 9
- 9
platform/kobo/koreader.sh View File

@ -203,9 +203,9 @@ CRASH_TS=0
CRASH_PREV_TS=0
# Because we *want* an initial fbdepth pass ;).
RETURN_VALUE=85
while [ $RETURN_VALUE -ne 0 ]; do
while [ ${RETURN_VALUE} -ne 0 ]; do
# 85 is what we return when asking for a KOReader restart
if [ $RETURN_VALUE -eq 85 ]; then
if [ ${RETURN_VALUE} -eq 85 ]; then
# Do an update check now, so we can actually update KOReader via the "Restart KOReader" menu entry ;).
ko_update_check
# Do or double-check the fb depth switch, or restore original bitdepth if requested
@ -216,7 +216,7 @@ while [ $RETURN_VALUE -ne 0 ]; do
RETURN_VALUE=$?
# Did we crash?
if [ $RETURN_VALUE -ne 0 ] && [ $RETURN_VALUE -ne 85 ]; then
if [ ${RETURN_VALUE} -ne 0 ] && [ ${RETURN_VALUE} -ne 85 ]; then
# Increment the crash counter
CRASH_COUNT=$((CRASH_COUNT + 1))
CRASH_TS=$(date +'%s')
@ -241,8 +241,8 @@ while [ $RETURN_VALUE -ne 0 ]; do
eval "$(./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))
bombHeight=$((viewHeight / 2 + viewHeight / 15 ))
bombMargin=$((FONTH + FONTH / 2 ))
# With a little notice at the top of the screen, on a big gray screen of death ;).
./fbink -q -b -c -B GRAY9 -m -y 1 "Don't Panic! (Crash n°${CRASH_COUNT} -> ${RETURN_VALUE})"
if [ ${CRASH_COUNT} -eq 1 ]; then
@ -255,7 +255,7 @@ while [ $RETURN_VALUE -ne 0 ]; do
# 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
./fbink -q -b -O -t regular=./fonts/droid/DroidSansMono.ttf,top=$((viewHeight/2 + FONTH * 2 + FONTH/2)),left=$((viewWidth/60)),right=$((viewWidth/60)),px=$((viewHeight/64)) "${crashLog}"
./fbink -q -b -O -t regular=./fonts/droid/DroidSansMono.ttf,top=$((viewHeight / 2 + FONTH * 2 + FONTH / 2 )),left=$((viewWidth / 60 )),right=$((viewWidth / 60 )),px=$((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.
./fbink -q -f -s top=0,left=0
# Cue a lemming's faceplant sound effect!
@ -265,7 +265,7 @@ while [ $RETURN_VALUE -ne 0 ]; do
echo "Uh oh, something went awry... (Crash n°${CRASH_COUNT}: $(date +'%x @ %X'))"
echo "Running FW $(cut -f3 -d',' /mnt/onboard/.kobo/version) on Linux $(uname -r) ($(uname -v))"
} >>crash.log 2>&1
if [ $CRASH_COUNT -lt 5 ] && [ "${ALWAYS_ABORT}" = "false" ]; then
if [ ${CRASH_COUNT} -lt 5 ] && [ "${ALWAYS_ABORT}" = "false" ]; then
echo "Attempting to restart KOReader . . ." >>crash.log 2>&1
echo "!!!!" >>crash.log 2>&1
fi
@ -282,7 +282,7 @@ while [ $RETURN_VALUE -ne 0 ]; do
# But if we've crashed more than 5 consecutive times, exit, because we wouldn't want to be stuck in a loop...
# NOTE: No need to check for ALWAYS_ABORT, CRASH_COUNT will always be 1 when it's true ;).
if [ $CRASH_COUNT -ge 5 ]; then
if [ ${CRASH_COUNT} -ge 5 ]; then
echo "Too many consecutive crashes, aborting . . ." >>crash.log 2>&1
echo "!!!! ! !!!!" >>crash.log 2>&1
break
@ -337,4 +337,4 @@ else
fi
fi
exit $RETURN_VALUE
exit ${RETURN_VALUE}

+ 4
- 4
platform/pocketbook/koreader.app View File

@ -9,8 +9,8 @@ NEWUPDATE="${KOREADER_DIR}/ota/koreader.updated.tar"
INSTALLED="${KOREADER_DIR}/ota/koreader.installed.tar"
if [ -f "${NEWUPDATE}" ]; then
# TODO: any graphic indication for the updating progress?
cd /mnt/ext1/ && "${KOREADER_DIR}/tar" xf "${NEWUPDATE}" --no-same-permissions --no-same-owner \
&& mv "${NEWUPDATE}" "${INSTALLED}"
cd /mnt/ext1/ && "${KOREADER_DIR}/tar" xf "${NEWUPDATE}" --no-same-permissions --no-same-owner &&
mv "${NEWUPDATE}" "${INSTALLED}"
rm -f "${NEWUPDATE}" # always purge newupdate in all cases to prevent update loop
fi
@ -43,7 +43,7 @@ if [ -e crash.log ]; then
fi
RETURN_VALUE=85
while [ $RETURN_VALUE -eq 85 ]; do
while [ ${RETURN_VALUE} -eq 85 ]; do
./reader.lua "${args}" >>crash.log 2>&1
RETURN_VALUE=$?
done
@ -52,4 +52,4 @@ if pidof reader.lua >/dev/null 2>&1; then
killall -TERM reader.lua
fi
exit $RETURN_VALUE
exit ${RETURN_VALUE}

+ 3
- 3
platform/ubuntu-touch/koreader.sh View File

@ -8,7 +8,7 @@ KOREADER_DIR="${0%/*}"
cd "${KOREADER_DIR}" || exit
# export load library path for some old firmware
export LD_LIBRARY_PATH=${KOREADER_DIR}/libs:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=${KOREADER_DIR}/libs:${LD_LIBRARY_PATH}
# export trained OCR data directory
export TESSDATA_PREFIX="data"
@ -21,9 +21,9 @@ export SDL_FULLSCREEN=1
RETURN_VALUE=85
while [ $RETURN_VALUE -eq 85 ]; do
while [ ${RETURN_VALUE} -eq 85 ]; do
./reader.lua -d ~/Documents
RETURN_VALUE=$?
done
exit $RETURN_VALUE
exit ${RETURN_VALUE}

+ 8
- 8
plugins/backgroundrunner.koplugin/luawrapper.sh View File

@ -3,32 +3,32 @@
# Converts the return of "sh wrapper.sh $@" into Lua format.
CURRENT_DIR=$(dirname "$0")
sh "$CURRENT_DIR/wrapper.sh" "$@" >/dev/null 2>&1 &
sh "${CURRENT_DIR}/wrapper.sh" "$@" >/dev/null 2>&1 &
JOB_ID=$!
while true; do
if ps -p $JOB_ID >/dev/null 2>&1; then
if ps -p ${JOB_ID} >/dev/null 2>&1; then
# Unblock f:read().
echo
else
wait $JOB_ID
wait ${JOB_ID}
EXIT_CODE=$?
if [ "$EXIT_CODE" -eq "255" ]; then
if [ "${EXIT_CODE}" -eq "255" ]; then
TIMEOUT="true"
else
TIMEOUT="false"
fi
if [ "$EXIT_CODE" -eq "127" ]; then
if [ "${EXIT_CODE}" -eq "127" ]; then
BADCOMMAND="true"
else
BADCOMMAND="false"
fi
echo "return { \
result = $EXIT_CODE, \
timeout = $TIMEOUT, \
bad_command = $BADCOMMAND, \
result = ${EXIT_CODE}, \
timeout = ${TIMEOUT}, \
bad_command = ${BADCOMMAND}, \
}"
exit 0
fi

+ 11
- 11
plugins/backgroundrunner.koplugin/wrapper.sh View File

@ -5,35 +5,35 @@
# to start, this script returns 127. If the command is timed out, this script
# returns 255. Otherwise the return value of the command will be returned.
echo "TIMEOUT in environment: $TIMEOUT"
echo "TIMEOUT in environment: ${TIMEOUT}"
if [ -z "$TIMEOUT" ]; then
if [ -z "${TIMEOUT}" ]; then
TIMEOUT=3600
fi
echo "Timeout has been set to $TIMEOUT seconds"
echo "Timeout has been set to ${TIMEOUT} seconds"
echo "Will start command $*"
echo "$@" | nice -n 19 sh &
JOB_ID=$!
echo "Job id: $JOB_ID"
echo "Job id: ${JOB_ID}"
for i in $(seq 1 1 $TIMEOUT); do
if ps -p $JOB_ID >/dev/null 2>&1; then
for i in $(seq 1 1 ${TIMEOUT}); do
if ps -p ${JOB_ID} >/dev/null 2>&1; then
# Job is still running.
sleep 1
ROUND=$(printf "%s" "$i" | tail -c 1)
if [ "$ROUND" -eq "0" ]; then
echo "Job $JOB_ID is still running ... waited for $i seconds."
ROUND=$(printf "%s" "${i}" | tail -c 1)
if [ "${ROUND}" -eq "0" ]; then
echo "Job ${JOB_ID} is still running ... waited for ${i} seconds."
fi
else
wait $JOB_ID
wait ${JOB_ID}
exit $?
fi
done
echo "Command $* has timed out"
kill -9 $JOB_ID
kill -9 ${JOB_ID}
exit 255

Loading…
Cancel
Save