[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 4 years ago committed by GitHub
parent 283187efb7
commit 668eee97fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

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

@ -37,4 +37,4 @@ if [ "${untagged_todo}" ]; then
fi fi
echo -e "\n${ANSI_GREEN}Luacheck results" 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

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

@ -7,7 +7,7 @@ source "${CI_DIR}/common.sh"
rm -rf "${HOME}/.luarocks" rm -rf "${HOME}/.luarocks"
mkdir "${HOME}/.luarocks" mkdir "${HOME}/.luarocks"
cp "${CI_BUILD_DIR}/install/etc/luarocks/config.lua" "${HOME}/.luarocks/config.lua" 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 travis_retry luarocks --local install luafilesystem
# for verbose_print module # for verbose_print module
travis_retry luarocks --local install ansicolors travis_retry luarocks --local install ansicolors

@ -13,14 +13,14 @@ for shellscript in "${shellscript_locations[@]}"; do
echo -e "${ANSI_GREEN}Running shellcheck on ${shellscript}" echo -e "${ANSI_GREEN}Running shellcheck on ${shellscript}"
shellcheck "${shellscript}" || SHELLSCRIPT_ERROR=1 shellcheck "${shellscript}" || SHELLSCRIPT_ERROR=1
echo -e "${ANSI_GREEN}Running shfmt on ${shellscript}" 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:" 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 continue
fi 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:" 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 fi
done done

@ -31,8 +31,7 @@ if [ ! -f "${CI_BUILD_DIR}/install/bin/luarocks" ]; then
git checkout 6529891 git checkout 6529891
cmake . -DWITH_LUAJIT21=ON -DCMAKE_INSTALL_PREFIX="${CI_BUILD_DIR}/install" cmake . -DWITH_LUAJIT21=ON -DCMAKE_INSTALL_PREFIX="${CI_BUILD_DIR}/install"
make install make install
} || exit } && popd || exit
popd
else else
echo -e "${ANSI_GREEN}Using cached luarocks." echo -e "${ANSI_GREEN}Using cached luarocks."
fi fi
@ -50,9 +49,10 @@ else
fi fi
#install our own updated shellcheck #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 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" chmod +x "${HOME}/bin/shellcheck"
shellcheck --version shellcheck --version
else else
@ -60,8 +60,8 @@ else
fi fi
# install shfmt # install shfmt
SHFMT_URL="https://github.com/mvdan/sh/releases/download/v1.3.1/shfmt_v1.3.1_linux_amd64" SHFMT_URL="https://github.com/mvdan/sh/releases/download/v3.0.1/shfmt_v3.0.1_linux_amd64"
if [ "$(shfmt --version)" != "v1.3.1" ]; then if [ "$(shfmt --version)" != "v3.0.1" ]; then
curl -sSL "${SHFMT_URL}" -o "${HOME}/bin/shfmt" curl -sSL "${SHFMT_URL}" -o "${HOME}/bin/shfmt"
chmod +x "${HOME}/bin/shfmt" chmod +x "${HOME}/bin/shfmt"
else else

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

52
kodev

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

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

@ -8,7 +8,7 @@ sleep 1
PCB_ID=$(/usr/bin/ntxinfo /dev/mmcblk0 | grep pcb | cut -d ":" -f2) PCB_ID=$(/usr/bin/ntxinfo /dev/mmcblk0 | grep pcb | cut -d ":" -f2)
DISK=/dev/mmcblk 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" PARTITION="${DISK}0p7"
else else
PARTITION="${DISK}0p4" PARTITION="${DISK}0p4"
@ -16,11 +16,11 @@ fi
MOUNT_ARGS="noatime,nodiratime,shortname=mixed,utf8" 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 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

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

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

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

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

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

@ -11,8 +11,8 @@ lsmod | grep -q "${WIFI_MODULE}" || insmod "${WIFI_MODULE_PATH}"
sleep 1 sleep 1
ifconfig "${INTERFACE}" up 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 \ pidof wpa_supplicant >/dev/null ||
|| env -u LD_LIBRARY_PATH \ 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 wpa_supplicant -D wext -s -i "${INTERFACE}" -O /var/run/wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -B

@ -203,9 +203,9 @@ CRASH_TS=0
CRASH_PREV_TS=0 CRASH_PREV_TS=0
# Because we *want* an initial fbdepth pass ;). # Because we *want* an initial fbdepth pass ;).
RETURN_VALUE=85 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 # 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 ;). # Do an update check now, so we can actually update KOReader via the "Restart KOReader" menu entry ;).
ko_update_check ko_update_check
# Do or double-check the fb depth switch, or restore original bitdepth if requested # 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=$? RETURN_VALUE=$?
# Did we crash? # 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 # Increment the crash counter
CRASH_COUNT=$((CRASH_COUNT + 1)) CRASH_COUNT=$((CRASH_COUNT + 1))
CRASH_TS=$(date +'%s') 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' ';')" 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. # 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 # Height @ ~56.7%, w/ a margin worth 1.5 lines
bombHeight=$((viewHeight/2 + viewHeight/15)) bombHeight=$((viewHeight / 2 + viewHeight / 15))
bombMargin=$((FONTH + FONTH/2)) bombMargin=$((FONTH + FONTH / 2))
# With a little notice at the top of the screen, on a big gray screen of death ;). # 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})" ./fbink -q -b -c -B GRAY9 -m -y 1 "Don't Panic! (Crash n°${CRASH_COUNT} -> ${RETURN_VALUE})"
if [ ${CRASH_COUNT} -eq 1 ]; then 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... # 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')" 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 # 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. # 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 ./fbink -q -f -s top=0,left=0
# Cue a lemming's faceplant sound effect! # 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 "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))" echo "Running FW $(cut -f3 -d',' /mnt/onboard/.kobo/version) on Linux $(uname -r) ($(uname -v))"
} >>crash.log 2>&1 } >>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 "Attempting to restart KOReader . . ." >>crash.log 2>&1
echo "!!!!" >>crash.log 2>&1 echo "!!!!" >>crash.log 2>&1
fi 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... # 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 ;). # 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 "Too many consecutive crashes, aborting . . ." >>crash.log 2>&1
echo "!!!! ! !!!!" >>crash.log 2>&1 echo "!!!! ! !!!!" >>crash.log 2>&1
break break
@ -337,4 +337,4 @@ else
fi fi
fi fi
exit $RETURN_VALUE exit ${RETURN_VALUE}

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

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

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

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

Loading…
Cancel
Save