Travis: enforce shellscript coding style

* enormous coding style update

* update luajit-launcher

All changes are formatting only except for:

* new more correct pushd/popd style
	* keeps useful indentation
	* prevents execution of commands when pushd failed (cf. https://github.com/koalaman/shellcheck/wiki/SC2164 and https://github.com/koalaman/shellcheck/issues/863)

```
pushd some_dir && {
    command1
    command2
} || exit
popd
```
pull/2758/head
Frans de Jonge 7 years ago
parent f51285e89b
commit e8c01274f4

@ -17,27 +17,29 @@ if [ "${TRAVIS_PULL_REQUEST}" = false ] && [ "${TRAVIS_BRANCH}" = 'master' ]; th
git clone git@github.com:koreader/doc.git koreader_doc
# push doc update
pushd doc
pushd doc && {
luajit "$(which ldoc)" . 2>/dev/null
if [ ! -d html ]; then
echo "Failed to generate documents..."
exit 1
fi
} || exit
popd
cp -r doc/html/* koreader_doc/
pushd koreader_doc
pushd koreader_doc && {
git add -A
echo -e "\n${ANSI_GREEN}Pusing document update..."
git -c user.name="KOReader build bot" -c user.email="non-reply@koreader.rocks" \
commit -a --amend -m 'Automated documentation build from travis-ci.'
git push -f --quiet origin gh-pages >/dev/null
echo -e "\n${ANSI_GREEN}Documentation update pushed."
} || exit
popd
travis_retry make coverage
pushd koreader-*/koreader
pushd koreader-*/koreader && {
luajit "$(which luacov-coveralls)"
} || exit
popd
else
echo -e "\n${ANSI_GREEN}Not on official master branch, skip documentation update and coverage."

@ -1,8 +1,8 @@
#!/usr/bin/env bash
# don't do this for clang
if [ "$CXX" = "g++" ];
then export CXX="g++-4.8" CC="gcc-4.8";
if [ "$CXX" = "g++" ]; then
export CXX="g++-4.8" CC="gcc-4.8"
fi
# in case anything ignores the environment variables, override through PATH
mkdir bin

@ -13,8 +13,10 @@ 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}"
[ "$(cat "${shellscript}" )" != "$(shfmt -i 4 "${shellscript}")" ] && echo -e "${ANSI_RED}Warning: ${shellscript} does not abide by coding style"
# @TODO add error handling with something like && shfmt -i 4 "${shellscript}" | diff "${shellscript}"
if [ "$(cat "${shellscript}")" != "$(shfmt -i 4 "${shellscript}")" ]; then
echo -e "${ANSI_RED}Warning: ${shellscript} does not abide by coding style"
shfmt -i 4 "${shellscript}" | diff "${shellscript}" - || SHELLSCRIPT_ERROR=1
fi
done
exit "${SHELLSCRIPT_ERROR}"

@ -23,10 +23,11 @@ fi
# install our own updated luarocks
if [ ! -f "${TRAVIS_BUILD_DIR}/install/bin/luarocks" ]; then
git clone https://github.com/torch/luajit-rocks.git
pushd luajit-rocks
pushd luajit-rocks && {
git checkout 6529891
cmake . -DWITH_LUAJIT21=ON -DCMAKE_INSTALL_PREFIX="${TRAVIS_BUILD_DIR}/install"
make install
} || exit
popd
else
echo -e "${ANSI_GREEN}Using cached luarocks."
@ -43,7 +44,7 @@ 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"
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

306
kodev

@ -2,7 +2,7 @@
CURDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
function assert_ret_zero {
function assert_ret_zero() {
if [ "$1" -ne 0 ]; then
if [ ! -z "$2" ]; then
echo "$2"
@ -11,20 +11,19 @@ function assert_ret_zero {
fi
}
function check_submodules {
if git submodule status | grep -qE '^\-'
then
function check_submodules() {
if git submodule status | grep -qE '^\-'; then
kodev-fetch-thirdparty
fi
}
function setup_env {
function setup_env() {
files=$(ls -d ./koreader-emulator-*/koreader)
assert_ret_zero $? "Emulator not found, please build it first."
export EMU_DIR=${files[0]}
}
function kodev-fetch-thirdparty {
function kodev-fetch-thirdparty() {
make fetchthirdparty
}
@ -41,7 +40,7 @@ SUPPORTED_TARGETS="
win32
"
function kodev-build {
function kodev-build() {
BUILD_HELP_MSG="
usage: build <OPTIONS> <TARGET>
@ -57,13 +56,17 @@ ${SUPPORTED_TARGETS}"
VALUE=$(echo "$1" | awk -F= '{print $2}')
case $PARAM in
-v | --verbose)
export VERBOSE=1 ;;
export VERBOSE=1
;;
-h | --help)
echo "${BUILD_HELP_MSG}"; exit 0 ;;
echo "${BUILD_HELP_MSG}"
exit 0
;;
*)
echo "ERROR: unknown option \"$PARAM\""
echo "${BUILD_HELP_MSG}"
exit 1 ;;
exit 1
;;
esac
shift 1
done
@ -71,40 +74,61 @@ ${SUPPORTED_TARGETS}"
check_submodules
case $1 in
kindle)
make TARGET=kindle; assert_ret_zero $? ;;
make TARGET=kindle
assert_ret_zero $?
;;
kindle5)
make TARGET=kindle5; assert_ret_zero $? ;;
make TARGET=kindle5
assert_ret_zero $?
;;
kindlepw2)
make TARGET=kindlepw2; assert_ret_zero $? ;;
make TARGET=kindlepw2
assert_ret_zero $?
;;
kobo)
make TARGET=kobo; assert_ret_zero $? ;;
make TARGET=kobo
assert_ret_zero $?
;;
kindle-legacy)
make TARGET=kindle-legacy; assert_ret_zero $? ;;
make TARGET=kindle-legacy
assert_ret_zero $?
;;
android)
[[ -n ${NDK+x} ]] || export NDK="${CURDIR}/base/toolchain/android-ndk-r12b"
[ -e "${CURDIR}/base/toolchain/android-toolchain/bin/arm-linux-androideabi-gcc" ] || { \
{ [ -e "${NDK}" ] || make -C "${CURDIR}/base/toolchain" android-ndk; }; \
make android-toolchain; assert_ret_zero $?; \
[ -e "${CURDIR}/base/toolchain/android-toolchain/bin/arm-linux-androideabi-gcc" ] || {
{ [ -e "${NDK}" ] || make -C "${CURDIR}/base/toolchain" android-ndk; }
make android-toolchain
assert_ret_zero $?
}
echo "Using NDK: ${NDK}..."
make TARGET=android; assert_ret_zero $? ;;
make TARGET=android
assert_ret_zero $?
;;
pocketbook)
if [ ! -d "${CURDIR}/base/toolchain/pocketbook-toolchain" ]; then
make pocketbook-toolchain; assert_ret_zero $?
make pocketbook-toolchain
assert_ret_zero $?
fi
make TARGET=pocketbook; assert_ret_zero $? ;;
make TARGET=pocketbook
assert_ret_zero $?
;;
ubuntu-touch)
make TARGET=ubuntu-touch; assert_ret_zero $? ;;
make TARGET=ubuntu-touch
assert_ret_zero $?
;;
win32)
make TARGET=win32; assert_ret_zero $? ;;
make TARGET=win32
assert_ret_zero $?
;;
*)
make
assert_ret_zero $? "Failed to build emulator! Try run with -v for more information."
setup_env ;;
setup_env
;;
esac
}
function kodev-clean {
function kodev-clean() {
CLEAN_HELP_MSG="
usage: clean <TARGET>
@ -113,32 +137,44 @@ ${SUPPORTED_TARGETS}"
case $1 in
-h | --help)
echo "${CLEAN_HELP_MSG}"; exit 0 ;;
echo "${CLEAN_HELP_MSG}"
exit 0
;;
kindle)
make TARGET=kindle clean ;;
make TARGET=kindle clean
;;
kindle5)
make TARGET=kindle5 clean ;;
make TARGET=kindle5 clean
;;
kindlepw2)
make TARGET=kindlepw2 clean ;;
make TARGET=kindlepw2 clean
;;
kobo)
make TARGET=kobo clean ;;
make TARGET=kobo clean
;;
kindle-legacy)
make TARGET=kindle-legacy clean ;;
make TARGET=kindle-legacy clean
;;
android)
make TARGET=android clean
rm -f ./*.apk ;;
rm -f ./*.apk
;;
pocketbook)
make TARGET=pocketbook clean ;;
make TARGET=pocketbook clean
;;
ubuntu-touch)
make TARGET=ubuntu-touch clean ;;
make TARGET=ubuntu-touch clean
;;
win32)
make TARGET=win32 clean ;;
make TARGET=win32 clean
;;
*)
make clean ;;
make clean
;;
esac
}
function kodev-release {
function kodev-release() {
# SUPPORTED_RELEASE_TARGETS=$(echo ${SUPPORTED_TARGETS} | sed 's/win32//')
SUPPORTED_RELEASE_TARGETS="${SUPPORTED_TARGETS/emu*/""}"
RELEASE_HELP_MSG="
@ -146,19 +182,27 @@ usage: release <TARGET>
TARGET:
${SUPPORTED_RELEASE_TARGETS}"
[ $# -lt 1 ] && { echo "${RELEASE_HELP_MSG}"; exit 1; }
[ $# -lt 1 ] && {
echo "${RELEASE_HELP_MSG}"
exit 1
}
while [[ $1 == '-'* ]]; do
PARAM=$(echo "$1" | awk -F= '{print $1}')
VALUE=$(echo "$1" | awk -F= '{print $2}')
case $PARAM in
-v | --verbose)
export VERBOSE=1 ;;
export VERBOSE=1
;;
-h | --help)
echo "${RELEASE_HELP_MSG}"; exit 0 ;;
echo "${RELEASE_HELP_MSG}"
exit 0
;;
*)
echo "ERROR: unknown option \"$PARAM\""
echo "${RELEASE_HELP_MSG}"; exit 1 ;;
echo "${RELEASE_HELP_MSG}"
exit 1
;;
esac
shift 1
done
@ -168,51 +212,61 @@ ${SUPPORTED_RELEASE_TARGETS}"
case $1 in
kindle)
kodev-build kindle
make TARGET=kindle update ;;
make TARGET=kindle update
;;
kindle5)
kodev-build kindle5
make TARGET=kindle5 update ;;
make TARGET=kindle5 update
;;
kindlepw2)
kodev-build kindlepw2
make TARGET=kindlepw2 update ;;
make TARGET=kindlepw2 update
;;
kobo)
kodev-build kobo
make TARGET=kobo update ;;
make TARGET=kobo update
;;
kindle-legacy)
kodev-build kindle-legacy
make TARGET=kindle-legacy update ;;
make TARGET=kindle-legacy update
;;
android)
kodev-build android
export PATH=$PATH:${CURDIR}/base/toolchain/android-sdk-linux/tools
which android &> /dev/null || { \
make -C "${CURDIR}/base/toolchain" android-sdk; \
which android &>/dev/null || {
make -C "${CURDIR}/base/toolchain" android-sdk
}
ANDROID_HOME=$(dirname "$(dirname "$(which android)")")
export ANDROID_HOME
export PATH=$PATH:${NDK}
make TARGET=android update ;;
make TARGET=android update
;;
pocketbook)
kodev-build pocketbook
make TARGET=pocketbook update ;;
make TARGET=pocketbook update
;;
ubuntu-touch)
kodev-build pocketbook
make TARGET=ubuntu-touch update ;;
make TARGET=ubuntu-touch update
;;
*)
echo "Unsupported target for release: $1."
echo "${RELEASE_HELP_MSG}"; exit 1 ;;
echo "${RELEASE_HELP_MSG}"
exit 1
;;
esac
}
function kodev-wbuilder {
function kodev-wbuilder() {
kodev-build
echo "[*] Running wbuilder.lua..."
pushd "${EMU_DIR}"
pushd "${EMU_DIR}" && {
EMULATE_READER_W=540 EMULATE_READER_H=720 ./luajit ./tools/wbuilder.lua
} || exit
popd
}
function kodev-run {
function kodev-run() {
RUN_HELP_MSG="
usage: run <OPTIONS> <ARGS>
@ -230,18 +284,26 @@ OPTIONS:
VALUE=$(echo "$1" | awk -F= '{print $2}')
case $PARAM in
--disable-touch)
export DISABLE_TOUCH=1 ;;
export DISABLE_TOUCH=1
;;
--no-build)
no_build=true ;;
no_build=true
;;
-w | --screen-width)
screen_width=${VALUE} ;;
screen_width=${VALUE}
;;
-h | --screen-height)
screen_height=${VALUE} ;;
screen_height=${VALUE}
;;
-h | --help)
echo "${RUN_HELP_MSG}"; exit 0 ;;
echo "${RUN_HELP_MSG}"
exit 0
;;
*)
echo "ERROR: unknown option \"$PARAM\""
echo "${RUN_HELP_MSG}"; exit 1 ;;
echo "${RUN_HELP_MSG}"
exit 1
;;
esac
shift
done
@ -259,7 +321,7 @@ OPTIONS:
fi
echo "[*] Running KOReader with arguments: $*..."
pushd "${EMU_DIR}"
pushd "${EMU_DIR}" && {
if [ $# -lt 1 ]; then
args=${CURDIR}/test
else
@ -269,10 +331,11 @@ OPTIONS:
EMULATE_READER_W=${screen_width} EMULATE_READER_H=${screen_height} \
./reader.lua -d "$args"
} || exit
popd
}
function kodev-test {
function kodev-test() {
TEST_HELP_MSG="
usage: test <OPTIONS> [front|base] <TEST_NAME>
@ -287,17 +350,25 @@ OPTIONS:
VALUE=$(echo "$1" | awk -F= '{print $2}')
case $PARAM in
--tags)
opts="--tags=${VALUE}" ;;
opts="--tags=${VALUE}"
;;
-h | --help)
echo "${TEST_HELP_MSG}"; exit 0 ;;
echo "${TEST_HELP_MSG}"
exit 0
;;
*)
echo "ERROR: unknown option \"$PARAM\""
echo "${TEST_HELP_MSG}"; exit 1 ;;
echo "${TEST_HELP_MSG}"
exit 1
;;
esac
shift
done
[ $# -lt 1 ] && { echo "${TEST_HELP_MSG}"; exit 1; }
[ $# -lt 1 ] && {
echo "${TEST_HELP_MSG}"
exit 1
}
[[ $1 != "front" && $1 != "base" ]] && {
echo "Invalid test suite: $1!"
echo "${TEST_HELP_MSG}"
@ -307,7 +378,7 @@ OPTIONS:
check_submodules && make
setup_env
make "${EMU_DIR}/.busted"
pushd "${EMU_DIR}"
pushd "${EMU_DIR}" && {
test_path="./spec/$1/unit"
if [ ! -z "$2" ]; then
@ -320,10 +391,11 @@ OPTIONS:
--lazy \
-o "./spec/$1/unit/verbose_print" \
--exclude-tags=notest "${test_path}"
} || exit
popd
}
function kodev-cov {
function kodev-cov() {
COV_HELP_MSG="
usage: cov <OPTIONS>
@ -339,14 +411,20 @@ OPTIONS:
VALUE=$(echo "$1" | awk -F= '{print $2}')
case $PARAM in
--full)
show_full=1 ;;
show_full=1
;;
--show-previous)
show_previous=1 ;;
show_previous=1
;;
-h | --help)
echo "${COV_HELP_MSG}"; exit 0 ;;
echo "${COV_HELP_MSG}"
exit 0
;;
*)
echo "ERROR: unknown option \"$PARAM\""
echo "${COV_HELP_MSG}"; exit 1 ;;
echo "${COV_HELP_MSG}"
exit 1
;;
esac
shift
done
@ -354,7 +432,7 @@ OPTIONS:
check_submodules && make
setup_env
make "${EMU_DIR}/.busted"
pushd "${EMU_DIR}"
pushd "${EMU_DIR}" && {
target=front
test_path="./spec/${target}/unit"
if [ ${show_previous} -eq 0 ]; then
@ -366,7 +444,7 @@ 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
@ -376,11 +454,11 @@ OPTIONS:
+$(($(grep -nm1 -e '^Summary$' luacov.report.out | cut -d: -f1) - 1)) \
luacov.report.out
fi
} || exit
popd
}
function kodev-log {
function kodev-log() {
LOG_HELP_MSG="
usage: log <TARGET>
@ -388,21 +466,27 @@ TARGET:
android
"
[ $# -lt 1 ] && { echo "${LOG_HELP_MSG}"; exit 1; }
[ $# -lt 1 ] && {
echo "${LOG_HELP_MSG}"
exit 1
}
case $1 in
-h | --help)
echo "${LOG_HELP_MSG}"; exit 0 ;;
echo "${LOG_HELP_MSG}"
exit 0
;;
android)
adb logcat 'luajit-launcher:D KOReader:D *:S' ;;
adb logcat 'luajit-launcher:D KOReader:D *:S'
;;
*)
echo "Unsupported target: $1."
echo "${LOG_HELP_MSG}"; exit 1 ;;
echo "${LOG_HELP_MSG}"
exit 1
;;
esac
}
HELP_MSG="
usage: $0 COMMAND <ARGS>
@ -418,41 +502,67 @@ Supported commands:
test Run tests
wbuilder Run wbuilder.lua script (useful for building new UI widget)
"
[ $# -lt 1 ] && { echo "Missing command."; echo "${HELP_MSG}"; exit 1; }
[ $# -lt 1 ] && {
echo "Missing command."
echo "${HELP_MSG}"
exit 1
}
case $1 in
activate)
echo "adding ${CURDIR} to \$PATH..."
export PATH="${PATH}:${CURDIR}"
eval "$(luarocks path --bin)"
exec "${SHELL}" ;;
exec "${SHELL}"
;;
fetch-thirdparty)
kodev-fetch-thirdparty ;;
kodev-fetch-thirdparty
;;
clean)
shift 1; kodev-clean "$@" ;;
shift 1
kodev-clean "$@"
;;
build)
shift 1; kodev-build "$@" ;;
shift 1
kodev-build "$@"
;;
release)
shift 1; kodev-release "$@" ;;
shift 1
kodev-release "$@"
;;
wbuilder)
kodev-wbuilder ;;
kodev-wbuilder
;;
run)
shift 1; kodev-run "$@" ;;
shift 1
kodev-run "$@"
;;
test)
shift 1; kodev-test "$@" ;;
shift 1
kodev-test "$@"
;;
cov)
shift 1; kodev-cov "$@" ;;
shift 1
kodev-cov "$@"
;;
prompt)
kodev-build
pushd "${EMU_DIR}"
pushd "${EMU_DIR}" && {
./luajit -i setupkoenv.lua
} || exit
popd
;;
log)
shift 1; kodev-log "$@" ;;
shift 1
kodev-log "$@"
;;
--help | -h)
echo "${HELP_MSG}"; exit 0 ;;
echo "${HELP_MSG}"
exit 0
;;
*)
echo "Unknown command: $1."
echo "${HELP_MSG}"; exit 1 ;;
echo "${HELP_MSG}"
exit 1
;;
esac

@ -1 +1 @@
Subproject commit 3bdf92c1272d969af5f419492edf760aa2947cf3
Subproject commit 7368ab36138a00b38d643a00c940bd4d02475ad1

@ -17,8 +17,7 @@ else
fi
## Handle logging...
logmsg()
{
logmsg() {
# Use the right tools for the platform
if [ "${INIT_TYPE}" = "sysv" ]; then
msg "koreader: ${1}" "I"
@ -33,8 +32,7 @@ logmsg()
## And now the actual useful stuff!
# Update koreader
update_koreader()
{
update_koreader() {
# Check if we were called by install_koreader...
if [ "${1}" = "clean" ]; then
do_clean_install="true"
@ -95,15 +93,13 @@ update_koreader()
}
# Clean install of koreader
install_koreader()
{
install_koreader() {
# Let update_koreader do the job for us ;p.
update_koreader "clean"
}
# Handle cre's settings...
set_cre_prop()
{
set_cre_prop() {
# We need at least two args
if [ $# -lt 2 ]; then
logmsg "not enough arg passed to set_cre_prop"
@ -122,8 +118,7 @@ set_cre_prop()
sed -e "s/$(echo -ne '\r')$//g" -i "${cre_config}"
# And finally set the prop
if sed -re "s/^(${cre_prop_key})(=)(.*?)$/\1\2${cre_prop_value}/" -i "${cre_config}"
then
if sed -re "s/^(${cre_prop_key})(=)(.*?)$/\1\2${cre_prop_value}/" -i "${cre_config}"; then
logmsg "Set ${cre_prop_key} to ${cre_prop_value}"
else
logmsg "Failed to set ${cre_prop_key}"
@ -134,30 +129,24 @@ set_cre_prop()
}
# Handle CRe's font.hinting.mode
cre_autohint()
{
cre_autohint() {
set_cre_prop "font.hinting.mode" "2"
}
cre_bci()
{
cre_bci() {
set_cre_prop "font.hinting.mode" "1"
}
cre_nohinting()
{
cre_nohinting() {
set_cre_prop "font.hinting.mode" "0"
}
# Handle CRe's font.kerning.enabled
cre_kerning()
{
cre_kerning() {
set_cre_prop "font.kerning.enabled" "1"
}
cre_nokerning()
{
cre_nokerning() {
set_cre_prop "font.kerning.enabled" "0"
}
## Main
case "${1}" in
"update_koreader")

@ -19,8 +19,7 @@ else
fi
# Handle logging...
logmsg()
{
logmsg() {
# Use the right tools for the platform
if [ "${INIT_TYPE}" = "sysv" ]; then
msg "koreader: ${1}" "I"

@ -92,8 +92,7 @@ EIPS_MAXCHARS="$((SCREEN_X_RES / EIPS_X_RES))"
EIPS_MAXLINES="$((SCREEN_Y_RES / EIPS_Y_RES))"
# Adapted from libkh[5]
eips_print_bottom_centered()
{
eips_print_bottom_centered() {
# We need at least two args
if [ $# -lt 2 ]; then
echo "not enough arguments passed to eips_print_bottom ($# while we need at least 2)"

@ -10,6 +10,6 @@ sleep 1
ifconfig eth0 up
wlarm_le -i eth0 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 -ieth0 -O /var/run/wpa_supplicant -c/etc/wpa_supplicant/wpa_supplicant.conf -B

@ -5,7 +5,10 @@ PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/lib"
cur_rotate="$(cat "/sys/class/graphics/fb0/rotate")"
# start fmon again. Note that we don't have to worry about reaping this, nickel kills on-animator.sh on start.
( usleep 400000; /etc/init.d/on-animator.sh ) &
(
usleep 400000
/etc/init.d/on-animator.sh
) &
# environment needed by nickel, from /etc/init.d/rcS:
@ -85,7 +88,6 @@ if [ -x /usr/local/Kobo/sickel ] ; then
/usr/local/Kobo/sickel -platform kobo:noscreen >/dev/null 2>&1 &
fi
# Rotation weirdness, part II
echo "${cur_rotate}" >"/sys/class/graphics/fb0/rotate"
# shellcheck disable=SC2094

@ -28,4 +28,3 @@ export EXT_FONT_DIR="${HOME}/fonts"
export SDL_FULLSCREEN=1
./reader.lua -d ~/Documents

Loading…
Cancel
Save