From 668eee97fa4a322d434b5de11df8b9b8d1df3329 Mon Sep 17 00:00:00 2001 From: Frans de Jonge Date: Sun, 2 Feb 2020 20:35:21 +0100 Subject: [PATCH] [CI] Add curly braces check (#5809) Update shellcheck and shfmt to the latest version. Fixes . Btw, you can apply shellcheck suggestions with a command like: ``` shellcheck --include=SC2250 -f diff *.sh | git apply ``` --- .ci/after_success.sh | 6 +-- .ci/before_install.sh | 10 ++-- .ci/check.sh | 2 +- .ci/common.sh | 28 +++++----- .ci/helper_luarocks.sh | 2 +- .ci/helper_shellchecks.sh | 8 +-- .ci/install.sh | 12 ++--- .shellcheckrc | 1 + kodev | 52 +++++++++---------- platform/appimage/AppRun | 10 ++-- platform/cervantes/disable-usbms.sh | 8 +-- platform/cervantes/enable-usbms.sh | 10 ++-- platform/cervantes/koreader-standalone.sh | 8 +-- platform/debian/do_debian_package.sh | 7 ++- platform/debian/koreader.sh | 6 +-- .../extensions/koreader/bin/koreader-ext.sh | 2 +- platform/kobo/enable-wifi.sh | 6 +-- platform/kobo/koreader.sh | 18 +++---- platform/pocketbook/koreader.app | 8 +-- platform/ubuntu-touch/koreader.sh | 6 +-- .../backgroundrunner.koplugin/luawrapper.sh | 16 +++--- plugins/backgroundrunner.koplugin/wrapper.sh | 22 ++++---- 22 files changed, 124 insertions(+), 124 deletions(-) create mode 100644 .shellcheckrc diff --git a/.ci/after_success.sh b/.ci/after_success.sh index ac8af06b1..8c0008788 100755 --- a/.ci/after_success.sh +++ b/.ci/after_success.sh @@ -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 diff --git a/.ci/before_install.sh b/.ci/before_install.sh index 986092d76..fa2568c7f 100755 --- a/.ci/before_install.sh +++ b/.ci/before_install.sh @@ -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, diff --git a/.ci/check.sh b/.ci/check.sh index d4cc969dd..6cd2e5268 100755 --- a/.ci/check.sh +++ b/.ci/check.sh @@ -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 diff --git a/.ci/common.sh b/.ci/common.sh index 121dca15a..3f3c0199b 100755 --- a/.ci/common.sh +++ b/.ci/common.sh @@ -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)" diff --git a/.ci/helper_luarocks.sh b/.ci/helper_luarocks.sh index 846780bee..a42640253 100755 --- a/.ci/helper_luarocks.sh +++ b/.ci/helper_luarocks.sh @@ -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 diff --git a/.ci/helper_shellchecks.sh b/.ci/helper_shellchecks.sh index 7bc644e6f..56f6dcbac 100755 --- a/.ci/helper_shellchecks.sh +++ b/.ci/helper_shellchecks.sh @@ -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 diff --git a/.ci/install.sh b/.ci/install.sh index 5f30d27b2..86317e0ee 100755 --- a/.ci/install.sh +++ b/.ci/install.sh @@ -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 diff --git a/.shellcheckrc b/.shellcheckrc new file mode 100644 index 000000000..7228dfbe2 --- /dev/null +++ b/.shellcheckrc @@ -0,0 +1 @@ +enable=require-variable-braces diff --git a/kodev b/kodev index 2350abb9f..528c5768d 100755 --- a/kodev +++ b/kodev @@ -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" <"${SCRIPT_PNG}" <"$SCRIPT_SHOW" <"${SCRIPT_SHOW}" </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 diff --git a/platform/appimage/AppRun b/platform/appimage/AppRun index 7518ca2a3..b5302cc19 100755 --- a/platform/appimage/AppRun +++ b/platform/appimage/AppRun @@ -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} diff --git a/platform/cervantes/disable-usbms.sh b/platform/cervantes/disable-usbms.sh index 86a317f8f..f9768b0e2 100644 --- a/platform/cervantes/disable-usbms.sh +++ b/platform/cervantes/disable-usbms.sh @@ -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 diff --git a/platform/cervantes/enable-usbms.sh b/platform/cervantes/enable-usbms.sh index a43fe5be0..1d1781bd7 100644 --- a/platform/cervantes/enable-usbms.sh +++ b/platform/cervantes/enable-usbms.sh @@ -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 diff --git a/platform/cervantes/koreader-standalone.sh b/platform/cervantes/koreader-standalone.sh index 6eda0bb6b..ec23d1b16 100755 --- a/platform/cervantes/koreader-standalone.sh +++ b/platform/cervantes/koreader-standalone.sh @@ -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 diff --git a/platform/debian/do_debian_package.sh b/platform/debian/do_debian_package.sh index 76d4ce325..0c89fe5d6 100755 --- a/platform/debian/do_debian_package.sh +++ b/platform/debian/do_debian_package.sh @@ -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 - diff --git a/platform/debian/koreader.sh b/platform/debian/koreader.sh index 6f9b88b96..3227b9da6 100755 --- a/platform/debian/koreader.sh +++ b/platform/debian/koreader.sh @@ -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} diff --git a/platform/kindle/extensions/koreader/bin/koreader-ext.sh b/platform/kindle/extensions/koreader/bin/koreader-ext.sh index e7007dd91..0c8f9b620 100755 --- a/platform/kindle/extensions/koreader/bin/koreader-ext.sh +++ b/platform/kindle/extensions/koreader/bin/koreader-ext.sh @@ -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... diff --git a/platform/kobo/enable-wifi.sh b/platform/kobo/enable-wifi.sh index 7390e5317..f95c6d019 100755 --- a/platform/kobo/enable-wifi.sh +++ b/platform/kobo/enable-wifi.sh @@ -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 diff --git a/platform/kobo/koreader.sh b/platform/kobo/koreader.sh index f48256655..b58d90a76 100755 --- a/platform/kobo/koreader.sh +++ b/platform/kobo/koreader.sh @@ -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} diff --git a/platform/pocketbook/koreader.app b/platform/pocketbook/koreader.app index 91f645d5b..6d4fc1fe6 100755 --- a/platform/pocketbook/koreader.app +++ b/platform/pocketbook/koreader.app @@ -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} diff --git a/platform/ubuntu-touch/koreader.sh b/platform/ubuntu-touch/koreader.sh index 7d921ab1b..95920cda9 100755 --- a/platform/ubuntu-touch/koreader.sh +++ b/platform/ubuntu-touch/koreader.sh @@ -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} diff --git a/plugins/backgroundrunner.koplugin/luawrapper.sh b/plugins/backgroundrunner.koplugin/luawrapper.sh index 21aad4381..a939ba0b7 100755 --- a/plugins/backgroundrunner.koplugin/luawrapper.sh +++ b/plugins/backgroundrunner.koplugin/luawrapper.sh @@ -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 diff --git a/plugins/backgroundrunner.koplugin/wrapper.sh b/plugins/backgroundrunner.koplugin/wrapper.sh index e468fea2f..8415f972f 100755 --- a/plugins/backgroundrunner.koplugin/wrapper.sh +++ b/plugins/backgroundrunner.koplugin/wrapper.sh @@ -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