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

@ -10,34 +10,36 @@ if [ "${TRAVIS_PULL_REQUEST}" = false ] && [ "${TRAVIS_BRANCH}" = 'master' ]; th
travis_retry luarocks --local install ldoc travis_retry luarocks --local install ldoc
# get deploy key for doc repo # get deploy key for doc repo
openssl aes-256-cbc -k "${doc_build_secret:?}" -in .ci/koreader_doc.enc -out ~/.ssh/koreader_doc -d openssl aes-256-cbc -k "${doc_build_secret:?}" -in .ci/koreader_doc.enc -out ~/.ssh/koreader_doc -d
chmod 600 ~/.ssh/koreader_doc # make agent happy chmod 600 ~/.ssh/koreader_doc # make agent happy
eval "$(ssh-agent)" > /dev/null eval "$(ssh-agent)" >/dev/null
ssh-add ~/.ssh/koreader_doc > /dev/null ssh-add ~/.ssh/koreader_doc >/dev/null
echo -e "\n${ANSI_GREEN}Check out koreader/doc for update." echo -e "\n${ANSI_GREEN}Check out koreader/doc for update."
git clone git@github.com:koreader/doc.git koreader_doc git clone git@github.com:koreader/doc.git koreader_doc
# push doc update # push doc update
pushd doc pushd doc && {
luajit "$(which ldoc)" . 2> /dev/null luajit "$(which 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
fi fi
} || exit
popd popd
cp -r doc/html/* koreader_doc/ cp -r doc/html/* koreader_doc/
pushd koreader_doc pushd koreader_doc && {
git add -A
git add -A echo -e "\n${ANSI_GREEN}Pusing document update..."
echo -e "\n${ANSI_GREEN}Pusing document update..." git -c user.name="KOReader build bot" -c user.email="non-reply@koreader.rocks" \
git -c user.name="KOReader build bot" -c user.email="non-reply@koreader.rocks" \ commit -a --amend -m 'Automated documentation build from travis-ci.'
commit -a --amend -m 'Automated documentation build from travis-ci.' git push -f --quiet origin gh-pages >/dev/null
git push -f --quiet origin gh-pages > /dev/null echo -e "\n${ANSI_GREEN}Documentation update pushed."
echo -e "\n${ANSI_GREEN}Documentation update pushed." } || exit
popd popd
travis_retry make coverage travis_retry make coverage
pushd koreader-*/koreader pushd koreader-*/koreader && {
luajit "$(which luacov-coveralls)" luajit "$(which luacov-coveralls)"
} || exit
popd popd
else else
echo -e "\n${ANSI_GREEN}Not on official master branch, skip documentation update and coverage." echo -e "\n${ANSI_GREEN}Not on official master branch, skip documentation update and coverage."

@ -1,8 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# don't do this for clang # don't do this for clang
if [ "$CXX" = "g++" ]; if [ "$CXX" = "g++" ]; then
then export CXX="g++-4.8" CC="gcc-4.8"; export CXX="g++-4.8" CC="gcc-4.8"
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

@ -11,54 +11,54 @@ ANSI_RESET="\033[0m"
ANSI_CLEAR="\033[0K" ANSI_CLEAR="\033[0K"
travis_retry() { travis_retry() {
local result=0 local result=0
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() {
local result=0 local result=0
local count=1 local count=1
set +e set +e
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 PATH=$PWD/bin:$PATH export PATH=$PWD/bin:$PATH

@ -7,7 +7,7 @@ source "${CI_DIR}/common.sh"
rm -rf "${HOME}/.luarocks" rm -rf "${HOME}/.luarocks"
mkdir "${HOME}/.luarocks" mkdir "${HOME}/.luarocks"
cp "${TRAVIS_BUILD_DIR}/install/etc/luarocks/config.lua" "${HOME}/.luarocks/config.lua" cp "${TRAVIS_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
@ -18,4 +18,4 @@ travis_retry luarocks --local install luacov
travis_retry luarocks --local install luasec OPENSSL_LIBDIR=/usr/lib/x86_64-linux-gnu travis_retry luarocks --local install luasec OPENSSL_LIBDIR=/usr/lib/x86_64-linux-gnu
travis_retry luarocks --local install luacov-coveralls --server=http://rocks.moonscript.org/dev travis_retry luarocks --local install luacov-coveralls --server=http://rocks.moonscript.org/dev
travis_retry luarocks --local install luacheck travis_retry luarocks --local install luacheck
travis_retry luarocks --local install lanes # for parallel luacheck travis_retry luarocks --local install lanes # for parallel luacheck

@ -5,7 +5,7 @@ CI_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${CI_DIR}/common.sh" source "${CI_DIR}/common.sh"
# shellcheck disable=2016 # shellcheck disable=2016
mapfile -t shellscript_locations < <( { git grep -lE '^#!(/usr)?/bin/(env )?(bash|sh)' && git submodule --quiet foreach '[ "$path" = "base" ] || git grep -lE "^#!(/usr)?/bin/(env )?(bash|sh)" | sed "s|^|$path/|"' && git ls-files ./*.sh ; } | sort | uniq ) mapfile -t shellscript_locations < <({ git grep -lE '^#!(/usr)?/bin/(env )?(bash|sh)' && git submodule --quiet foreach '[ "$path" = "base" ] || git grep -lE "^#!(/usr)?/bin/(env )?(bash|sh)" | sed "s|^|$path/|"' && git ls-files ./*.sh; } | sort | uniq)
SHELLSCRIPT_ERROR=0 SHELLSCRIPT_ERROR=0
@ -13,8 +13,10 @@ 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}"
[ "$(cat "${shellscript}" )" != "$(shfmt -i 4 "${shellscript}")" ] && echo -e "${ANSI_RED}Warning: ${shellscript} does not abide by coding style" if [ "$(cat "${shellscript}")" != "$(shfmt -i 4 "${shellscript}")" ]; then
# @TODO add error handling with something like && shfmt -i 4 "${shellscript}" | diff "${shellscript}" echo -e "${ANSI_RED}Warning: ${shellscript} does not abide by coding style"
shfmt -i 4 "${shellscript}" | diff "${shellscript}" - || SHELLSCRIPT_ERROR=1
fi
done done
exit "${SHELLSCRIPT_ERROR}" exit "${SHELLSCRIPT_ERROR}"

@ -23,27 +23,28 @@ fi
# install our own updated luarocks # install our own updated luarocks
if [ ! -f "${TRAVIS_BUILD_DIR}/install/bin/luarocks" ]; then if [ ! -f "${TRAVIS_BUILD_DIR}/install/bin/luarocks" ]; then
git clone https://github.com/torch/luajit-rocks.git git clone https://github.com/torch/luajit-rocks.git
pushd luajit-rocks pushd luajit-rocks && {
git checkout 6529891 git checkout 6529891
cmake . -DWITH_LUAJIT21=ON -DCMAKE_INSTALL_PREFIX="${TRAVIS_BUILD_DIR}/install" cmake . -DWITH_LUAJIT21=ON -DCMAKE_INSTALL_PREFIX="${TRAVIS_BUILD_DIR}/install"
make install make install
} || exit
popd popd
else else
echo -e "${ANSI_GREEN}Using cached luarocks." echo -e "${ANSI_GREEN}Using cached luarocks."
fi fi
if [ ! -d "${HOME}/.luarocks" ] || [ ! -f "${HOME}/.luarocks/$(md5sum < "${CI_DIR}/helper_luarocks.sh")" ] ; then if [ ! -d "${HOME}/.luarocks" ] || [ ! -f "${HOME}/.luarocks/$(md5sum <"${CI_DIR}/helper_luarocks.sh")" ]; then
echo -e "${ANSI_GREEN}Grabbing new .luarocks." echo -e "${ANSI_GREEN}Grabbing new .luarocks."
"${CI_DIR}/helper_luarocks.sh" "${CI_DIR}/helper_luarocks.sh"
touch "${HOME}/.luarocks/$(md5sum < "${CI_DIR}/helper_luarocks.sh")" touch "${HOME}/.luarocks/$(md5sum <"${CI_DIR}/helper_luarocks.sh")"
else else
echo -e "${ANSI_GREEN}Using cached .luarocks." echo -e "${ANSI_GREEN}Using cached .luarocks."
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_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 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
@ -52,7 +53,7 @@ fi
# install shfmt # install shfmt
SHFMT_URL="https://github.com/mvdan/sh/releases/download/v1.2.0/shfmt_v1.2.0_linux_amd64" SHFMT_URL="https://github.com/mvdan/sh/releases/download/v1.2.0/shfmt_v1.2.0_linux_amd64"
if ! command -v shfmt ; then if ! command -v shfmt; 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

312
kodev

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

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

@ -8,180 +8,169 @@
KOREADER_DIR="/mnt/us/koreader" KOREADER_DIR="/mnt/us/koreader"
# Load our helper functions... # Load our helper functions...
if [ -f "${KOREADER_DIR}/libkohelper.sh" ] ; then if [ -f "${KOREADER_DIR}/libkohelper.sh" ]; then
# shellcheck source=/dev/null # shellcheck source=/dev/null
. "${KOREADER_DIR}/libkohelper.sh" . "${KOREADER_DIR}/libkohelper.sh"
else else
echo "Can't source helper functions, aborting!" echo "Can't source helper functions, aborting!"
exit 1 exit 1
fi fi
## Handle logging... ## Handle logging...
logmsg() logmsg() {
{ # Use the right tools for the platform
# Use the right tools for the platform if [ "${INIT_TYPE}" = "sysv" ]; then
if [ "${INIT_TYPE}" = "sysv" ] ; then msg "koreader: ${1}" "I"
msg "koreader: ${1}" "I" elif [ "${INIT_TYPE}" = "upstart" ]; then
elif [ "${INIT_TYPE}" = "upstart" ] ; then f_log I koreader kual "" "${1}"
f_log I koreader kual "" "${1}" fi
fi
# And handle user visual feedback via eips...
# And handle user visual feedback via eips... eips_print_bottom_centered "${1}" 1
eips_print_bottom_centered "${1}" 1
} }
## And now the actual useful stuff! ## And now the actual useful stuff!
# Update koreader # Update koreader
update_koreader() update_koreader() {
{ # Check if we were called by install_koreader...
# Check if we were called by install_koreader... if [ "${1}" = "clean" ]; then
if [ "${1}" = "clean" ] ; then do_clean_install="true"
do_clean_install="true" else
else do_clean_install="false"
do_clean_install="false" fi
fi
found_koreader_package="false"
found_koreader_package="false" # Try to find a koreader package... Behavior undefined if there are multiple packages...
# Try to find a koreader package... Behavior undefined if there are multiple packages... for file in /mnt/us/koreader-kindle-*.tar.gz; do
for file in /mnt/us/koreader-kindle-*.tar.gz ; do if [ -f "${file}" ]; then
if [ -f "${file}" ] ; then found_koreader_package="${file}"
found_koreader_package="${file}" koreader_pkg_type="tgz"
koreader_pkg_type="tgz" fi
fi done
done for file in /mnt/us/koreader-kindle-*.zip; do
for file in /mnt/us/koreader-kindle-*.zip ; do if [ -f "${file}" ]; then
if [ -f "${file}" ] ; then found_koreader_package="${file}"
found_koreader_package="${file}" koreader_pkg_type="zip"
koreader_pkg_type="zip" fi
fi done
done
if [ "${found_koreader_package}" = "false" ]; then
if [ "${found_koreader_package}" = "false" ] ; then # Go away
# Go away logmsg "No KOReader package found"
logmsg "No KOReader package found" else
else # Do we want to do a clean install?
# Do we want to do a clean install? if [ "${do_clean_install}" = "true" ]; then
if [ "${do_clean_install}" = "true" ] ; then logmsg "Removing current KOReader directory . . ."
logmsg "Removing current KOReader directory . . ." rm -rf /mnt/us/koreader
rm -rf /mnt/us/koreader logmsg "Uninstall finished."
logmsg "Uninstall finished." fi
fi
# Get the version of the package...
# Get the version of the package... if [ "${koreader_pkg_type}" = "tgz" ]; then
if [ "${koreader_pkg_type}" = "tgz" ] ; then koreader_pkg_ver="${found_koreader_package%.*.*}"
koreader_pkg_ver="${found_koreader_package%.*.*}" else
else koreader_pkg_ver="${found_koreader_package%.*}"
koreader_pkg_ver="${found_koreader_package%.*}" fi
fi koreader_pkg_ver="${koreader_pkg_ver#*-v}"
koreader_pkg_ver="${koreader_pkg_ver#*-v}" # Install it!
# Install it! logmsg "Updating to KOReader ${koreader_pkg_ver} . . ."
logmsg "Updating to KOReader ${koreader_pkg_ver} . . ." if [ "${koreader_pkg_type}" = "tgz" ]; then
if [ "${koreader_pkg_type}" = "tgz" ] ; then tar -C "/mnt/us" -xzf "${found_koreader_package}"
tar -C "/mnt/us" -xzf "${found_koreader_package}" fail=$?
fail=$? else
else 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 logmsg "Update to v${koreader_pkg_ver} successful :)"
logmsg "Update to v${koreader_pkg_ver} successful :)" # Cleanup behind us...
# Cleanup behind us... rm -f "${found_koreader_package}"
rm -f "${found_koreader_package}" else
else logmsg "Failed to update to v${koreader_pkg_ver} :("
logmsg "Failed to update to v${koreader_pkg_ver} :(" fi
fi fi
fi
} }
# Clean install of koreader # Clean install of koreader
install_koreader() install_koreader() {
{ # Let update_koreader do the job for us ;p.
# Let update_koreader do the job for us ;p. update_koreader "clean"
update_koreader "clean"
} }
# Handle cre's settings... # Handle cre's settings...
set_cre_prop() set_cre_prop() {
{ # We need at least two args
# We need at least two args if [ $# -lt 2 ]; then
if [ $# -lt 2 ] ; then logmsg "not enough arg passed to set_cre_prop"
logmsg "not enough arg passed to set_cre_prop" return
return fi
fi
cre_prop_key="${1}"
cre_prop_key="${1}" cre_prop_value="${2}"
cre_prop_value="${2}"
cre_config="/mnt/us/koreader/data/cr3.ini"
cre_config="/mnt/us/koreader/data/cr3.ini"
# Check that the config exists...
# Check that the config exists... if [ -f "${cre_config}" ]; then
if [ -f "${cre_config}" ] ; then # dos2unix
# dos2unix # shellcheck disable=SC2039
# shellcheck disable=SC2039 sed -e "s/$(echo -ne '\r')$//g" -i "${cre_config}"
sed -e "s/$(echo -ne '\r')$//g" -i "${cre_config}"
# And finally set the prop
# 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}" logmsg "Set ${cre_prop_key} to ${cre_prop_value}"
then else
logmsg "Set ${cre_prop_key} to ${cre_prop_value}" logmsg "Failed to set ${cre_prop_key}"
else fi
logmsg "Failed to set ${cre_prop_key}" else
fi logmsg "No CRe config, launch CRe once first"
else fi
logmsg "No CRe config, launch CRe once first"
fi
} }
# Handle CRe's font.hinting.mode # Handle CRe's font.hinting.mode
cre_autohint() cre_autohint() {
{ set_cre_prop "font.hinting.mode" "2"
set_cre_prop "font.hinting.mode" "2"
} }
cre_bci() cre_bci() {
{ set_cre_prop "font.hinting.mode" "1"
set_cre_prop "font.hinting.mode" "1"
} }
cre_nohinting() cre_nohinting() {
{ set_cre_prop "font.hinting.mode" "0"
set_cre_prop "font.hinting.mode" "0"
} }
# Handle CRe's font.kerning.enabled # Handle CRe's font.kerning.enabled
cre_kerning() cre_kerning() {
{ set_cre_prop "font.kerning.enabled" "1"
set_cre_prop "font.kerning.enabled" "1"
} }
cre_nokerning() cre_nokerning() {
{ set_cre_prop "font.kerning.enabled" "0"
set_cre_prop "font.kerning.enabled" "0"
} }
## Main ## Main
case "${1}" in case "${1}" in
"update_koreader" ) "update_koreader")
${1} ${1}
;; ;;
"install_koreader" ) "install_koreader")
${1} ${1}
;; ;;
"cre_autohint" ) "cre_autohint")
${1} ${1}
;; ;;
"cre_bci" ) "cre_bci")
${1} ${1}
;; ;;
"cre_nohinting" ) "cre_nohinting")
${1} ${1}
;; ;;
"cre_kerning" ) "cre_kerning")
${1} ${1}
;; ;;
"cre_nokerning" ) "cre_nokerning")
${1} ${1}
;; ;;
* ) *)
logmsg "invalid action (${1})" logmsg "invalid action (${1})"
;; ;;
esac esac

@ -3,42 +3,41 @@ export LC_ALL="en_US.UTF-8"
PROC_KEYPAD="/proc/keypad" PROC_KEYPAD="/proc/keypad"
PROC_FIVEWAY="/proc/fiveway" PROC_FIVEWAY="/proc/fiveway"
[ -e $PROC_KEYPAD ] && echo unlock > $PROC_KEYPAD [ -e $PROC_KEYPAD ] && echo unlock >$PROC_KEYPAD
[ -e $PROC_FIVEWAY ] && echo unlock > $PROC_FIVEWAY [ -e $PROC_FIVEWAY ] && echo unlock >$PROC_FIVEWAY
# KOReader's working directory # KOReader's working directory
KOREADER_DIR="/mnt/us/koreader" KOREADER_DIR="/mnt/us/koreader"
# Load our helper functions... # Load our helper functions...
if [ -f "${KOREADER_DIR}/libkohelper.sh" ] ; then if [ -f "${KOREADER_DIR}/libkohelper.sh" ]; then
# shellcheck source=/dev/null # shellcheck source=/dev/null
. "${KOREADER_DIR}/libkohelper.sh" . "${KOREADER_DIR}/libkohelper.sh"
else else
echo "Can't source helper functions, aborting!" echo "Can't source helper functions, aborting!"
exit 1 exit 1
fi fi
# Handle logging... # Handle logging...
logmsg() logmsg() {
{ # Use the right tools for the platform
# Use the right tools for the platform if [ "${INIT_TYPE}" = "sysv" ]; then
if [ "${INIT_TYPE}" = "sysv" ] ; then msg "koreader: ${1}" "I"
msg "koreader: ${1}" "I" elif [ "${INIT_TYPE}" = "upstart" ]; then
elif [ "${INIT_TYPE}" = "upstart" ] ; then f_log I koreader wrapper "" "${1}"
f_log I koreader wrapper "" "${1}" fi
fi
# And throw that on stdout too, for the DIY crowd ;)
# And throw that on stdout too, for the DIY crowd ;) echo "${1}"
echo "${1}"
} }
# Go away if we're on FW 5.0, it's not supported # Go away if we're on FW 5.0, it's not supported
if [ "${INIT_TYPE}" = "upstart" ] ; then if [ "${INIT_TYPE}" = "upstart" ]; then
if grep '^Kindle 5\.0' /etc/prettyversion.txt > /dev/null 2>&1 ; then if grep '^Kindle 5\.0' /etc/prettyversion.txt >/dev/null 2>&1; then
logmsg "FW 5.0 is not supported. Update to 5.1!" logmsg "FW 5.0 is not supported. Update to 5.1!"
# And... scene! # And... scene!
exit 0 exit 0
fi fi
fi fi
# Keep track of what we do with pillow... # Keep track of what we do with pillow...
@ -51,35 +50,35 @@ PASSCODE_DISABLED="no"
FROM_KUAL="no" FROM_KUAL="no"
# By default, don't stop the framework. # By default, don't stop the framework.
if [ "$1" = "--framework_stop" ] ; then if [ "$1" = "--framework_stop" ]; then
shift 1 shift 1
STOP_FRAMEWORK="yes" STOP_FRAMEWORK="yes"
NO_SLEEP="no" NO_SLEEP="no"
elif [ "$1" = "--asap" ] ; then elif [ "$1" = "--asap" ]; then
# Start as soon as possible, without sleeping to workaround UI quirks # Start as soon as possible, without sleeping to workaround UI quirks
shift 1 shift 1
NO_SLEEP="yes" NO_SLEEP="yes"
STOP_FRAMEWORK="no" STOP_FRAMEWORK="no"
# Don't sleep during eips calls either... # Don't sleep during eips calls either...
export EIPS_NO_SLEEP="true" export EIPS_NO_SLEEP="true"
else else
STOP_FRAMEWORK="no" STOP_FRAMEWORK="no"
NO_SLEEP="no" NO_SLEEP="no"
fi fi
# Detect if we were started by KUAL by checking our nice value... # Detect if we were started by KUAL by checking our nice value...
if [ "$(nice)" = "5" ] ; then if [ "$(nice)" = "5" ]; then
FROM_KUAL="yes" FROM_KUAL="yes"
if [ "${NO_SLEEP}" = "no" ] ; then if [ "${NO_SLEEP}" = "no" ]; then
# Yield a bit to let stuff stop properly... # Yield a bit to let stuff stop properly...
logmsg "Hush now . . ." logmsg "Hush now . . ."
# NOTE: This may or may not be terribly useful... # NOTE: This may or may not be terribly useful...
usleep 250000 usleep 250000
fi fi
# Kindlet threads spawn with a nice value of 5, go back to a neutral value # Kindlet threads spawn with a nice value of 5, go back to a neutral value
logmsg "Be nice!" logmsg "Be nice!"
renice -n -5 $$ renice -n -5 $$
fi fi
# we're always starting from our working directory # we're always starting from our working directory
@ -88,32 +87,32 @@ cd "${KOREADER_DIR}" || exit
# Handle pending OTA update # Handle pending OTA update
NEWUPDATE="${KOREADER_DIR}/ota/koreader.updated.tar" 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
logmsg "Updating koreader . . ." logmsg "Updating koreader . . ."
# Look for our own GNU tar build to do a fancy progress tracking... # Look for our own GNU tar build to do a fancy progress tracking...
GNUTAR_BIN="${KOREADER_DIR}/tar" GNUTAR_BIN="${KOREADER_DIR}/tar"
if [ -x "${GNUTAR_BIN}" ] ; then if [ -x "${GNUTAR_BIN}" ]; then
# Let our checkpoint script handle the detailed visual feedback... # Let our checkpoint script handle the detailed visual feedback...
eips_print_bottom_centered "Updating koreader" 1 eips_print_bottom_centered "Updating koreader" 1
# shellcheck disable=SC2016 # shellcheck disable=SC2016
${GNUTAR_BIN} -C "/mnt/us" --no-same-owner --no-same-permissions --checkpoint=200 --checkpoint-action=exec='./kotar_cpoint $TAR_CHECKPOINT' -xf "${NEWUPDATE}" ${GNUTAR_BIN} -C "/mnt/us" --no-same-owner --no-same-permissions --checkpoint=200 --checkpoint-action=exec='./kotar_cpoint $TAR_CHECKPOINT' -xf "${NEWUPDATE}"
fail=$? fail=$?
else else
# Fall back to busybox tar # Fall back to busybox tar
eips_print_bottom_centered "Updating koreader . . ." 1 eips_print_bottom_centered "Updating koreader . . ." 1
tar -C "/mnt/us" -xf "${NEWUPDATE}" tar -C "/mnt/us" -xf "${NEWUPDATE}"
fail=$? fail=$?
fi fi
# Cleanup behind us... # Cleanup behind us...
if [ $fail -eq 0 ] ; then if [ $fail -eq 0 ]; then
mv "${NEWUPDATE}" "${INSTALLED}" mv "${NEWUPDATE}" "${INSTALLED}"
logmsg "Update sucessful :)" logmsg "Update sucessful :)"
eips_print_bottom_centered "Update successful :)" 1 eips_print_bottom_centered "Update successful :)" 1
else else
# Huh ho... # Huh ho...
logmsg "Update failed :(" logmsg "Update failed :("
eips_print_bottom_centered "Update failed :(" 1 eips_print_bottom_centered "Update failed :(" 1
fi fi
fi fi
# load our own shared libraries if possible # load our own shared libraries if possible
@ -129,219 +128,219 @@ export STARDICT_DATA_DIR="data/dict"
export EXT_FONT_DIR="/mnt/us/fonts" export EXT_FONT_DIR="/mnt/us/fonts"
# Only setup IPTables on evices where it makes sense to (FW 5.x & K4) # Only setup IPTables on evices where it makes sense to (FW 5.x & K4)
if [ "${INIT_TYPE}" = "upstart" ] || [ "$(uname -r)" = "2.6.31-rt11-lab126" ] ; then if [ "${INIT_TYPE}" = "upstart" ] || [ "$(uname -r)" = "2.6.31-rt11-lab126" ]; then
logmsg "Setting up IPTables rules . . ." logmsg "Setting up IPTables rules . . ."
# accept input ports for zsync plugin # accept input ports for zsync plugin
iptables -A INPUT -i wlan0 -p udp --dport 5670 -j ACCEPT iptables -A INPUT -i wlan0 -p udp --dport 5670 -j ACCEPT
iptables -A INPUT -i wlan0 -p tcp --dport 49152:49162 -j ACCEPT iptables -A INPUT -i wlan0 -p tcp --dport 49152:49162 -j ACCEPT
# accept input ports for calibre companion # accept input ports for calibre companion
iptables -A INPUT -i wlan0 -p udp --dport 8134 -j ACCEPT iptables -A INPUT -i wlan0 -p udp --dport 8134 -j ACCEPT
fi fi
# bind-mount system fonts # bind-mount system fonts
if ! grep ${KOREADER_DIR}/fonts/host /proc/mounts > /dev/null 2>&1 ; then if ! grep ${KOREADER_DIR}/fonts/host /proc/mounts >/dev/null 2>&1; then
logmsg "Mounting system fonts . . ." logmsg "Mounting system fonts . . ."
mount -o bind /usr/java/lib/fonts ${KOREADER_DIR}/fonts/host mount -o bind /usr/java/lib/fonts ${KOREADER_DIR}/fonts/host
fi fi
# bind-mount altfonts # bind-mount altfonts
if [ -d /mnt/us/fonts ] ; then if [ -d /mnt/us/fonts ]; then
mkdir -p ${KOREADER_DIR}/fonts/altfonts mkdir -p ${KOREADER_DIR}/fonts/altfonts
if ! grep ${KOREADER_DIR}/fonts/altfonts /proc/mounts > /dev/null 2>&1 ; then if ! grep ${KOREADER_DIR}/fonts/altfonts /proc/mounts >/dev/null 2>&1; then
logmsg "Mounting altfonts . . ." logmsg "Mounting altfonts . . ."
mount -o bind /mnt/us/fonts ${KOREADER_DIR}/fonts/altfonts mount -o bind /mnt/us/fonts ${KOREADER_DIR}/fonts/altfonts
fi fi
fi fi
# bind-mount csp fonts # bind-mount csp fonts
if [ -d /var/local/font/mnt ] ; then if [ -d /var/local/font/mnt ]; then
mkdir -p ${KOREADER_DIR}/fonts/cspfonts mkdir -p ${KOREADER_DIR}/fonts/cspfonts
if ! grep ${KOREADER_DIR}/fonts/cspfonts /proc/mounts > /dev/null 2>&1 ; then if ! grep ${KOREADER_DIR}/fonts/cspfonts /proc/mounts >/dev/null 2>&1; then
logmsg "Mounting cspfonts . . ." logmsg "Mounting cspfonts . . ."
mount -o bind /var/local/font/mnt ${KOREADER_DIR}/fonts/cspfonts mount -o bind /var/local/font/mnt ${KOREADER_DIR}/fonts/cspfonts
fi fi
fi fi
# bind-mount linkfonts # bind-mount linkfonts
if [ -d /mnt/us/linkfonts/fonts ] ; then if [ -d /mnt/us/linkfonts/fonts ]; then
mkdir -p ${KOREADER_DIR}/fonts/linkfonts mkdir -p ${KOREADER_DIR}/fonts/linkfonts
if ! grep ${KOREADER_DIR}/fonts/linkfonts /proc/mounts > /dev/null 2>&1 ; then if ! grep ${KOREADER_DIR}/fonts/linkfonts /proc/mounts >/dev/null 2>&1; then
logmsg "Mounting linkfonts . . ." logmsg "Mounting linkfonts . . ."
mount -o bind /mnt/us/linkfonts/fonts ${KOREADER_DIR}/fonts/linkfonts mount -o bind /mnt/us/linkfonts/fonts ${KOREADER_DIR}/fonts/linkfonts
fi fi
fi fi
# check if we need to disable the system passcode, because it messes with us in fun and interesting (and, more to the point, intractable) ways... # check if we need to disable the system passcode, because it messes with us in fun and interesting (and, more to the point, intractable) ways...
# NOTE: The most egregious one being that it inhibits the outOfScreenSaver event on wakeup until the passcode is validated, which we can't do, since we capture all input... # NOTE: The most egregious one being that it inhibits the outOfScreenSaver event on wakeup until the passcode is validated, which we can't do, since we capture all input...
if [ -f "/var/local/system/userpasswdenabled" ] ; then if [ -f "/var/local/system/userpasswdenabled" ]; then
logmsg "Disabling system passcode . . ." logmsg "Disabling system passcode . . ."
rm -f "/var/local/system/userpasswdenabled" rm -f "/var/local/system/userpasswdenabled"
PASSCODE_DISABLED="yes" PASSCODE_DISABLED="yes"
fi fi
# check if we are supposed to shut down the Amazon framework # check if we are supposed to shut down the Amazon framework
if [ "${STOP_FRAMEWORK}" = "yes" ] ; then if [ "${STOP_FRAMEWORK}" = "yes" ]; then
logmsg "Stopping the framework . . ." logmsg "Stopping the framework . . ."
# Upstart or SysV? # Upstart or SysV?
if [ "${INIT_TYPE}" = "sysv" ] ; then if [ "${INIT_TYPE}" = "sysv" ]; then
/etc/init.d/framework stop /etc/init.d/framework stop
else else
# The framework job sends a SIGTERM on stop, trap it so we don't get killed if we were launched by KUAL # The framework job sends a SIGTERM on stop, trap it so we don't get killed if we were launched by KUAL
trap "" TERM trap "" TERM
stop lab126_gui stop lab126_gui
# NOTE: Let the framework teardown finish, so we don't start before the black screen... # NOTE: Let the framework teardown finish, so we don't start before the black screen...
usleep 1250000 usleep 1250000
# And remove the trap like a ninja now! # And remove the trap like a ninja now!
trap - TERM trap - TERM
fi fi
fi fi
# check if kpvbooklet was launched for more than once, if not we will disable pillow # check if kpvbooklet was launched for more than once, if not we will disable pillow
# there's no pillow if we stopped the framework, and it's only there on systems with upstart anyway # there's no pillow if we stopped the framework, and it's only there on systems with upstart anyway
if [ "${STOP_FRAMEWORK}" = "no" ] && [ "${INIT_TYPE}" = "upstart" ] ; then if [ "${STOP_FRAMEWORK}" = "no" ] && [ "${INIT_TYPE}" = "upstart" ]; then
count=$(lipc-get-prop -eiq com.github.koreader.kpvbooklet.timer count) count=$(lipc-get-prop -eiq com.github.koreader.kpvbooklet.timer count)
if [ "$count" = "" ] || [ "$count" = "0" ] ; then if [ "$count" = "" ] || [ "$count" = "0" ]; then
# NOTE: Dump the fb so we can restore something useful on exit... # NOTE: Dump the fb so we can restore something useful on exit...
cat /dev/fb0 > /var/tmp/koreader-fb.dump cat /dev/fb0 >/var/tmp/koreader-fb.dump
# NOTE: We want to disable the status bar (at the very least). Unfortunately, the soft hide/unhide method doesn't work properly anymore since FW 5.6.5... # NOTE: We want to disable the status bar (at the very least). Unfortunately, the soft hide/unhide method doesn't work properly anymore since FW 5.6.5...
# shellcheck disable=SC2046 # shellcheck disable=SC2046
if [ "$(printf "%.3s" $(grep '^Kindle 5' /etc/prettyversion.txt 2>&1 | sed -n -r 's/^(Kindle)([[:blank:]]*)([[:digit:].]*)(.*?)$/\3/p' | tr -d '.'))" -ge "565" ] ; then if [ "$(printf "%.3s" $(grep '^Kindle 5' /etc/prettyversion.txt 2>&1 | sed -n -r 's/^(Kindle)([[:blank:]]*)([[:digit:].]*)(.*?)$/\3/p' | tr -d '.'))" -ge "565" ]; then
PILLOW_HARD_DISABLED="yes" PILLOW_HARD_DISABLED="yes"
# FIXME: So we resort to killing pillow completely on FW >= 5.6.5... # FIXME: So we resort to killing pillow completely on FW >= 5.6.5...
logmsg "Disabling pillow . . ." logmsg "Disabling pillow . . ."
lipc-set-prop com.lab126.pillow disableEnablePillow disable lipc-set-prop com.lab126.pillow disableEnablePillow disable
# NOTE: And, oh, joy, on FW >= 5.7.2, this is not enough to prevent the clock from refreshing, so, take the bull by the horns, and SIGSTOP the WM while we run... # NOTE: And, oh, joy, on FW >= 5.7.2, this is not enough to prevent the clock from refreshing, so, take the bull by the horns, and SIGSTOP the WM while we run...
# shellcheck disable=SC2046 # shellcheck disable=SC2046
if [ "$(printf "%.3s" $(grep '^Kindle 5' /etc/prettyversion.txt 2>&1 | sed -n -r 's/^(Kindle)([[:blank:]]*)([[:digit:].]*)(.*?)$/\3/p' | tr -d '.'))" -ge "572" ] ; then if [ "$(printf "%.3s" $(grep '^Kindle 5' /etc/prettyversion.txt 2>&1 | sed -n -r 's/^(Kindle)([[:blank:]]*)([[:digit:].]*)(.*?)$/\3/p' | tr -d '.'))" -ge "572" ]; then
logmsg "Stopping awesome . . ." logmsg "Stopping awesome . . ."
killall -stop awesome killall -stop awesome
AWESOME_STOPPED="yes" AWESOME_STOPPED="yes"
fi fi
else else
logmsg "Hiding the status bar . . ." logmsg "Hiding the status bar . . ."
# NOTE: One more great find from eureka (http://www.mobileread.com/forums/showpost.php?p=2454141&postcount=34) # NOTE: One more great find from eureka (http://www.mobileread.com/forums/showpost.php?p=2454141&postcount=34)
lipc-set-prop com.lab126.pillow interrogatePillow '{"pillowId": "default_status_bar", "function": "nativeBridge.hideMe();"}' lipc-set-prop com.lab126.pillow interrogatePillow '{"pillowId": "default_status_bar", "function": "nativeBridge.hideMe();"}'
PILLOW_SOFT_DISABLED="yes" PILLOW_SOFT_DISABLED="yes"
fi fi
# NOTE: We don't need to sleep at all if we've already SIGSTOPped awesome ;) # NOTE: We don't need to sleep at all if we've already SIGSTOPped awesome ;)
if [ "${NO_SLEEP}" = "no" ] && [ "${AWESOME_STOPPED}" = "no" ] ; then if [ "${NO_SLEEP}" = "no" ] && [ "${AWESOME_STOPPED}" = "no" ]; then
# NOTE: Leave the framework time to refresh the screen, so we don't start before it has finished redrawing after collapsing the title bar # NOTE: Leave the framework time to refresh the screen, so we don't start before it has finished redrawing after collapsing the title bar
usleep 250000 usleep 250000
# NOTE: If we were started from KUAL, we risk getting a list item to popup right over us, so, wait some more... # NOTE: If we were started from KUAL, we risk getting a list item to popup right over us, so, wait some more...
# The culprit appears to be a I WindowManager:flashTimeoutExpired:window=Root 0 0 600x30 # The culprit appears to be a I WindowManager:flashTimeoutExpired:window=Root 0 0 600x30
if [ "${FROM_KUAL}" = "yes" ] ; then if [ "${FROM_KUAL}" = "yes" ]; then
logmsg "Playing possum to wait for the window manager . . ." logmsg "Playing possum to wait for the window manager . . ."
usleep 2500000 usleep 2500000
fi fi
fi fi
fi fi
fi fi
# stop cvm (sysv & framework up only) # stop cvm (sysv & framework up only)
if [ "${STOP_FRAMEWORK}" = "no" ] && [ "${INIT_TYPE}" = "sysv" ] ; then if [ "${STOP_FRAMEWORK}" = "no" ] && [ "${INIT_TYPE}" = "sysv" ]; then
logmsg "Stopping cvm . . ." logmsg "Stopping cvm . . ."
killall -stop cvm killall -stop cvm
fi fi
# finally call reader # finally call reader
logmsg "Starting KOReader . . ." logmsg "Starting KOReader . . ."
# That's not necessary when using KPVBooklet ;). # That's not necessary when using KPVBooklet ;).
if [ "${FROM_KUAL}" = "yes" ] ; then if [ "${FROM_KUAL}" = "yes" ]; then
eips_print_bottom_centered "Starting KOReader . . ." 1 eips_print_bottom_centered "Starting KOReader . . ." 1
fi fi
# we keep maximum 500K worth of crash log # we keep maximum 500K worth of crash log
if [ -e crash.log ]; then if [ -e crash.log ]; then
tail -c 500000 crash.log > crash.log.new tail -c 500000 crash.log >crash.log.new
mv -f crash.log.new crash.log mv -f crash.log.new crash.log
fi fi
./reader.lua "$@" >> crash.log 2>&1 ./reader.lua "$@" >>crash.log 2>&1
# clean up our own process tree in case the reader crashed (if needed, to avoid flooding KUAL's log) # clean up our own process tree in case the reader crashed (if needed, to avoid flooding KUAL's log)
if pidof reader.lua > /dev/null 2>&1 ; then if pidof reader.lua >/dev/null 2>&1; then
logmsg "Sending a SIGTERM to stray KOreader processes . . ." logmsg "Sending a SIGTERM to stray KOreader processes . . ."
killall -TERM reader.lua killall -TERM reader.lua
fi fi
# unmount system fonts # unmount system fonts
if grep ${KOREADER_DIR}/fonts/host /proc/mounts > /dev/null 2>&1 ; then if grep ${KOREADER_DIR}/fonts/host /proc/mounts >/dev/null 2>&1; then
logmsg "Unmounting system fonts . . ." logmsg "Unmounting system fonts . . ."
umount ${KOREADER_DIR}/fonts/host umount ${KOREADER_DIR}/fonts/host
fi fi
# unmount altfonts # unmount altfonts
if grep ${KOREADER_DIR}/fonts/altfonts /proc/mounts > /dev/null 2>&1 ; then if grep ${KOREADER_DIR}/fonts/altfonts /proc/mounts >/dev/null 2>&1; then
logmsg "Unmounting altfonts . . ." logmsg "Unmounting altfonts . . ."
umount ${KOREADER_DIR}/fonts/altfonts umount ${KOREADER_DIR}/fonts/altfonts
fi fi
# unmount cspfonts # unmount cspfonts
if grep ${KOREADER_DIR}/fonts/cspfonts /proc/mounts > /dev/null 2>&1 ; then if grep ${KOREADER_DIR}/fonts/cspfonts /proc/mounts >/dev/null 2>&1; then
logmsg "Unmounting cspfonts . . ." logmsg "Unmounting cspfonts . . ."
umount ${KOREADER_DIR}/fonts/cspfonts umount ${KOREADER_DIR}/fonts/cspfonts
fi fi
# unmount linkfonts # unmount linkfonts
if grep ${KOREADER_DIR}/fonts/linkfonts /proc/mounts > /dev/null 2>&1 ; then if grep ${KOREADER_DIR}/fonts/linkfonts /proc/mounts >/dev/null 2>&1; then
logmsg "Unmounting linkfonts . . ." logmsg "Unmounting linkfonts . . ."
umount ${KOREADER_DIR}/fonts/linkfonts umount ${KOREADER_DIR}/fonts/linkfonts
fi fi
# Resume cvm (only if we stopped it) # Resume cvm (only if we stopped it)
if [ "${STOP_FRAMEWORK}" = "no" ] && [ "${INIT_TYPE}" = "sysv" ] ; then if [ "${STOP_FRAMEWORK}" = "no" ] && [ "${INIT_TYPE}" = "sysv" ]; then
logmsg "Resuming cvm . . ." logmsg "Resuming cvm . . ."
killall -cont cvm killall -cont cvm
# We need to handle the screen refresh ourselves, frontend/device/kindle/device.lua's Kindle3.exit is called before we resume cvm ;). # We need to handle the screen refresh ourselves, frontend/device/kindle/device.lua's Kindle3.exit is called before we resume cvm ;).
echo 'send 139' > /proc/keypad echo 'send 139' >/proc/keypad
echo 'send 139' > /proc/keypad echo 'send 139' >/proc/keypad
fi fi
# Restart framework (if need be) # Restart framework (if need be)
if [ "${STOP_FRAMEWORK}" = "yes" ] ; then if [ "${STOP_FRAMEWORK}" = "yes" ]; then
logmsg "Restarting framework . . ." logmsg "Restarting framework . . ."
if [ "${INIT_TYPE}" = "sysv" ] ; then if [ "${INIT_TYPE}" = "sysv" ]; then
cd / && env -u LD_LIBRARY_PATH /etc/init.d/framework start cd / && env -u LD_LIBRARY_PATH /etc/init.d/framework start
else else
cd / && env -u LD_LIBRARY_PATH start lab126_gui cd / && env -u LD_LIBRARY_PATH start lab126_gui
fi fi
fi fi
# Display chrome bar if need be (upstart & framework up only) # Display chrome bar if need be (upstart & framework up only)
if [ "${STOP_FRAMEWORK}" = "no" ] && [ "${INIT_TYPE}" = "upstart" ] ; then if [ "${STOP_FRAMEWORK}" = "no" ] && [ "${INIT_TYPE}" = "upstart" ]; then
# Depending on the FW version, we may have handled things in a few different manners... # Depending on the FW version, we may have handled things in a few different manners...
if [ "${AWESOME_STOPPED}" = "yes" ] ; then if [ "${AWESOME_STOPPED}" = "yes" ]; then
logmsg "Resuming awesome . . ." logmsg "Resuming awesome . . ."
killall -cont awesome killall -cont awesome
fi fi
if [ "${PILLOW_HARD_DISABLED}" = "yes" ] ; then if [ "${PILLOW_HARD_DISABLED}" = "yes" ]; then
logmsg "Enabling pillow . . ." logmsg "Enabling pillow . . ."
lipc-set-prop com.lab126.pillow disableEnablePillow enable lipc-set-prop com.lab126.pillow disableEnablePillow enable
# NOTE: Try to leave the user with a slightly more useful FB content than our own last screen... # NOTE: Try to leave the user with a slightly more useful FB content than our own last screen...
cat /var/tmp/koreader-fb.dump > /dev/fb0 cat /var/tmp/koreader-fb.dump >/dev/fb0
rm -f /var/tmp/koreader-fb.dump rm -f /var/tmp/koreader-fb.dump
lipc-set-prop com.lab126.appmgrd start app://com.lab126.booklet.home lipc-set-prop com.lab126.appmgrd start app://com.lab126.booklet.home
# NOTE: In case we ever need an extra full flash refresh... # NOTE: In case we ever need an extra full flash refresh...
#eips -s w=${SCREEN_X_RES},h=${SCREEN_Y_RES} -f #eips -s w=${SCREEN_X_RES},h=${SCREEN_Y_RES} -f
fi fi
if [ "${PILLOW_SOFT_DISABLED}" = "yes" ] ; then if [ "${PILLOW_SOFT_DISABLED}" = "yes" ]; then
logmsg "Restoring the status bar . . ." logmsg "Restoring the status bar . . ."
# NOTE: Try to leave the user with a slightly more useful FB content than our own last screen... # NOTE: Try to leave the user with a slightly more useful FB content than our own last screen...
cat /var/tmp/koreader-fb.dump > /dev/fb0 cat /var/tmp/koreader-fb.dump >/dev/fb0
rm -f /var/tmp/koreader-fb.dump rm -f /var/tmp/koreader-fb.dump
lipc-set-prop com.lab126.pillow interrogatePillow '{"pillowId": "default_status_bar", "function": "nativeBridge.showMe();"}' lipc-set-prop com.lab126.pillow interrogatePillow '{"pillowId": "default_status_bar", "function": "nativeBridge.showMe();"}'
lipc-set-prop com.lab126.appmgrd start app://com.lab126.booklet.home lipc-set-prop com.lab126.appmgrd start app://com.lab126.booklet.home
fi fi
fi fi
if [ "${INIT_TYPE}" = "upstart" ] || [ "$(uname -r)" = "2.6.31-rt11-lab126" ] ; then if [ "${INIT_TYPE}" = "upstart" ] || [ "$(uname -r)" = "2.6.31-rt11-lab126" ]; then
logmsg "Restoring IPTables rules . . ." logmsg "Restoring IPTables rules . . ."
# restore firewall rules # restore firewall rules
iptables -D INPUT -i wlan0 -p udp --dport 8134 -j ACCEPT iptables -D INPUT -i wlan0 -p udp --dport 8134 -j ACCEPT
iptables -D INPUT -i wlan0 -p udp --dport 5670 -j ACCEPT iptables -D INPUT -i wlan0 -p udp --dport 5670 -j ACCEPT
iptables -D INPUT -i wlan0 -p tcp --dport 49152:49162 -j ACCEPT iptables -D INPUT -i wlan0 -p tcp --dport 49152:49162 -j ACCEPT
fi fi
if [ "${PASSCODE_DISABLED}" = "yes" ] ; then if [ "${PASSCODE_DISABLED}" = "yes" ]; then
logmsg "Restoring system passcode . . ." logmsg "Restoring system passcode . . ."
touch "/var/local/system/userpasswdenabled" touch "/var/local/system/userpasswdenabled"
fi fi

@ -7,12 +7,12 @@ KOREADER_DIR="/mnt/us/koreader"
export EIPS_NO_SLEEP="true" export EIPS_NO_SLEEP="true"
# Load our helper functions... # Load our helper functions...
if [ -f "${KOREADER_DIR}/libkohelper.sh" ] ; then if [ -f "${KOREADER_DIR}/libkohelper.sh" ]; then
# shellcheck source=/dev/null # shellcheck source=/dev/null
. "${KOREADER_DIR}/libkohelper.sh" . "${KOREADER_DIR}/libkohelper.sh"
else else
echo "Can't source helper functions, aborting!" echo "Can't source helper functions, aborting!"
exit 1 exit 1
fi fi
## First arg is the chekpoint number, and we get one every 200 checkpoints. ## First arg is the chekpoint number, and we get one every 200 checkpoints.
@ -20,11 +20,11 @@ CHECKPOINT_NUM="${1}"
CHECKPOINT_GRANULARITY="200" CHECKPOINT_GRANULARITY="200"
# Use that to build a poor man's progress bar, with dots. # Use that to build a poor man's progress bar, with dots.
PROGRESS_AMOUNT="$(( CHECKPOINT_NUM / CHECKPOINT_GRANULARITY ))" PROGRESS_AMOUNT="$((CHECKPOINT_NUM / CHECKPOINT_GRANULARITY))"
PROGRESS_STRING="Updating koreader " PROGRESS_STRING="Updating koreader "
for _ in $( seq 1 ${PROGRESS_AMOUNT} ) ; do for _ in $(seq 1 ${PROGRESS_AMOUNT}); do
# Append a dot until we hit the needed amount # Append a dot until we hit the needed amount
PROGRESS_STRING="${PROGRESS_STRING}." PROGRESS_STRING="${PROGRESS_STRING}."
done done
# Print our progress :) # Print our progress :)

@ -2,131 +2,130 @@
## A bit of helper functions... ## A bit of helper functions...
# Check which type of init system we're running on # Check which type of init system we're running on
if [ -d /etc/upstart ] ; then if [ -d /etc/upstart ]; then
export INIT_TYPE="upstart" export INIT_TYPE="upstart"
# We'll need that for logging # We'll need that for logging
# shellcheck disable=SC1091 # shellcheck disable=SC1091
[ -f /etc/upstart/functions ] && . /etc/upstart/functions [ -f /etc/upstart/functions ] && . /etc/upstart/functions
else else
export INIT_TYPE="sysv" export INIT_TYPE="sysv"
# We'll need that for logging # We'll need that for logging
# shellcheck disable=SC1091 # shellcheck disable=SC1091
[ -f /etc/rc.d/functions ] && . /etc/rc.d/functions [ -f /etc/rc.d/functions ] && . /etc/rc.d/functions
fi fi
# We need to get the proper constants for our model... # We need to get the proper constants for our model...
kmodel="$(cut -c3-4 /proc/usid)" kmodel="$(cut -c3-4 /proc/usid)"
case "${kmodel}" in case "${kmodel}" in
"13" | "54" | "2A" | "4F" | "52" | "53" ) "13" | "54" | "2A" | "4F" | "52" | "53")
# Voyage... # Voyage...
SCREEN_X_RES=1088 # NOTE: Yes, 1088, not 1072 or 1080... SCREEN_X_RES=1088 # NOTE: Yes, 1088, not 1072 or 1080...
SCREEN_Y_RES=1448 SCREEN_Y_RES=1448
EIPS_X_RES=16 EIPS_X_RES=16
EIPS_Y_RES=24 # Manually mesured, should be accurate. EIPS_Y_RES=24 # Manually mesured, should be accurate.
;; ;;
"24" | "1B" | "1D" | "1F" | "1C" | "20" | "D4" | "5A" | "D5" | "D6" | "D7" | "D8" | "F2" | "17" | "60" | "F4" | "F9" | "62" | "61" | "5F" ) "24" | "1B" | "1D" | "1F" | "1C" | "20" | "D4" | "5A" | "D5" | "D6" | "D7" | "D8" | "F2" | "17" | "60" | "F4" | "F9" | "62" | "61" | "5F")
# PaperWhite... # PaperWhite...
SCREEN_X_RES=768 # NOTE: Yes, 768, not 758... SCREEN_X_RES=768 # NOTE: Yes, 768, not 758...
SCREEN_Y_RES=1024 SCREEN_Y_RES=1024
EIPS_X_RES=16 EIPS_X_RES=16
EIPS_Y_RES=24 # Manually mesured, should be accurate. EIPS_Y_RES=24 # Manually mesured, should be accurate.
;; ;;
"C6" | "DD" ) "C6" | "DD")
# KT2... # KT2...
SCREEN_X_RES=608 SCREEN_X_RES=608
SCREEN_Y_RES=800 SCREEN_Y_RES=800
EIPS_X_RES=16 EIPS_X_RES=16
EIPS_Y_RES=24 EIPS_Y_RES=24
;; ;;
"0F" | "11" | "10" | "12" ) "0F" | "11" | "10" | "12")
# Touch # Touch
SCREEN_X_RES=600 # _v_width @ upstart/functions SCREEN_X_RES=600 # _v_width @ upstart/functions
SCREEN_Y_RES=800 # _v_height @ upstart/functions SCREEN_Y_RES=800 # _v_height @ upstart/functions
EIPS_X_RES=12 # from f_puts @ upstart/functions EIPS_X_RES=12 # from f_puts @ upstart/functions
EIPS_Y_RES=20 # from f_puts @ upstart/functions EIPS_Y_RES=20 # from f_puts @ upstart/functions
;; ;;
* ) *)
# Handle legacy devices... # Handle legacy devices...
if [ -f "/etc/rc.d/functions" ] && grep "EIPS" "/etc/rc.d/functions" > /dev/null 2>&1 ; then if [ -f "/etc/rc.d/functions" ] && grep "EIPS" "/etc/rc.d/functions" >/dev/null 2>&1; then
# Already done... # Already done...
#. /etc/rc.d/functions #. /etc/rc.d/functions
echo "foo" >/dev/null echo "foo" >/dev/null
else else
# Try the new device ID scheme... # Try the new device ID scheme...
kmodel="$(cut -c4-6 /proc/usid)" kmodel="$(cut -c4-6 /proc/usid)"
case "${kmodel}" in case "${kmodel}" in
"0G1" | "0G2" | "0G4" | "0G5" | "0G6" | "0G7" | "0KB" | "0KC" | "0KD" | "0KE" | "0KF" | "0KG" ) "0G1" | "0G2" | "0G4" | "0G5" | "0G6" | "0G7" | "0KB" | "0KC" | "0KD" | "0KE" | "0KF" | "0KG")
# PW3... NOTE: Hopefully matches the KV... # PW3... NOTE: Hopefully matches the KV...
SCREEN_X_RES=1088 SCREEN_X_RES=1088
SCREEN_Y_RES=1448 SCREEN_Y_RES=1448
EIPS_X_RES=16 EIPS_X_RES=16
EIPS_Y_RES=24 EIPS_Y_RES=24
;; ;;
"0GC" | "0GD" | "0GP" | "0GQ" | "0GR" | "0GS" ) "0GC" | "0GD" | "0GP" | "0GQ" | "0GR" | "0GS")
# Oasis... NOTE: Hopefully matches the KV... # Oasis... NOTE: Hopefully matches the KV...
SCREEN_X_RES=1088 SCREEN_X_RES=1088
SCREEN_Y_RES=1448 SCREEN_Y_RES=1448
EIPS_X_RES=16 EIPS_X_RES=16
EIPS_Y_RES=24 EIPS_Y_RES=24
;; ;;
"0DT" | "0K9" | "0KA" ) "0DT" | "0K9" | "0KA")
# KT3... NOTE: Hopefully matches the KT2... # KT3... NOTE: Hopefully matches the KT2...
SCREEN_X_RES=608 SCREEN_X_RES=608
SCREEN_Y_RES=800 SCREEN_Y_RES=800
EIPS_X_RES=16 EIPS_X_RES=16
EIPS_Y_RES=24 EIPS_Y_RES=24
;; ;;
* ) *)
# Fallback... We shouldn't ever hit that. # Fallback... We shouldn't ever hit that.
SCREEN_X_RES=600 SCREEN_X_RES=600
SCREEN_Y_RES=800 SCREEN_Y_RES=800
EIPS_X_RES=12 EIPS_X_RES=12
EIPS_Y_RES=20 EIPS_Y_RES=20
;; ;;
esac esac
fi fi
;; ;;
esac esac
# And now we can do the maths ;) # And now we can do the maths ;)
EIPS_MAXCHARS="$((SCREEN_X_RES / EIPS_X_RES))" EIPS_MAXCHARS="$((SCREEN_X_RES / EIPS_X_RES))"
EIPS_MAXLINES="$((SCREEN_Y_RES / EIPS_Y_RES))" EIPS_MAXLINES="$((SCREEN_Y_RES / EIPS_Y_RES))"
# Adapted from libkh[5] # Adapted from libkh[5]
eips_print_bottom_centered() eips_print_bottom_centered() {
{ # We need at least two args
# We need at least two args if [ $# -lt 2 ]; then
if [ $# -lt 2 ] ; then echo "not enough arguments passed to eips_print_bottom ($# while we need at least 2)"
echo "not enough arguments passed to eips_print_bottom ($# while we need at least 2)" return
return fi
fi
kh_eips_string="${1}" kh_eips_string="${1}"
kh_eips_y_shift_up="${2}" kh_eips_y_shift_up="${2}"
# Get the real string length now # Get the real string length now
kh_eips_strlen="${#kh_eips_string}" kh_eips_strlen="${#kh_eips_string}"
# Add the right amount of left & right padding, since we're centered, and eips doesn't trigger a full refresh, # Add the right amount of left & right padding, since we're centered, and eips doesn't trigger a full refresh,
# so we'll have to padd our string with blank spaces to make sure two consecutive messages don't run into each other # so we'll have to padd our string with blank spaces to make sure two consecutive messages don't run into each other
kh_padlen="$(((EIPS_MAXCHARS - kh_eips_strlen) / 2))" kh_padlen="$(((EIPS_MAXCHARS - kh_eips_strlen) / 2))"
# Left padding... # Left padding...
while [ ${#kh_eips_string} -lt $((kh_eips_strlen + kh_padlen)) ] ; do while [ ${#kh_eips_string} -lt $((kh_eips_strlen + kh_padlen)) ]; do
kh_eips_string=" ${kh_eips_string}" kh_eips_string=" ${kh_eips_string}"
done done
# Right padding (crop to the edge of the screen) # Right padding (crop to the edge of the screen)
while [ ${#kh_eips_string} -lt ${EIPS_MAXCHARS} ] ; do while [ ${#kh_eips_string} -lt ${EIPS_MAXCHARS} ]; do
kh_eips_string="${kh_eips_string} " kh_eips_string="${kh_eips_string} "
done done
# Sleep a tiny bit to workaround the logic in the 'new' (K4+) eInk controllers that tries to bundle updates, # Sleep a tiny bit to workaround the logic in the 'new' (K4+) eInk controllers that tries to bundle updates,
# otherwise it may drop part of our messages because of other screen updates from KUAL... # otherwise it may drop part of our messages because of other screen updates from KUAL...
# Unless we really don't want to sleep, for special cases... # Unless we really don't want to sleep, for special cases...
if [ ! -n "${EIPS_NO_SLEEP}" ] ; then if [ ! -n "${EIPS_NO_SLEEP}" ]; then
usleep 150000 # 150ms usleep 150000 # 150ms
fi fi
# And finally, show our formatted message centered on the bottom of the screen (NOTE: Redirect to /dev/null to kill unavailable character & pixel not in range warning messages) # And finally, show our formatted message centered on the bottom of the screen (NOTE: Redirect to /dev/null to kill unavailable character & pixel not in range warning messages)
eips 0 $((EIPS_MAXLINES - 2 - kh_eips_y_shift_up)) "${kh_eips_string}" >/dev/null eips 0 $((EIPS_MAXLINES - 2 - kh_eips_y_shift_up)) "${kh_eips_string}" >/dev/null
} }

@ -9,11 +9,11 @@ ifconfig eth0 down
# Some sleep in between may avoid system getting hung # Some sleep in between may avoid system getting hung
# (we test if a module is actually loaded to avoid unneeded sleeps) # (we test if a module is actually loaded to avoid unneeded sleeps)
if lsmod | grep -q "${WIFI_MODULE}" ; then if lsmod | grep -q "${WIFI_MODULE}"; then
usleep 200000 usleep 200000
rmmod -r "${WIFI_MODULE}" rmmod -r "${WIFI_MODULE}"
fi fi
if lsmod | grep -q sdio_wifi_pwr ; then if lsmod | grep -q sdio_wifi_pwr; then
usleep 200000 usleep 200000
rmmod -r sdio_wifi_pwr rmmod -r sdio_wifi_pwr
fi fi

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

@ -7,9 +7,9 @@ KOREADER_DIR="${0%/*}"
# update to new version from OTA directory # update to new version from OTA directory
NEWUPDATE="${KOREADER_DIR}/ota/koreader.updated.tar" 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 "${KOREADER_DIR%/*}" && tar xf "${NEWUPDATE}" && mv "${NEWUPDATE}" "${INSTALLED}" cd "${KOREADER_DIR%/*}" && tar xf "${NEWUPDATE}" && mv "${NEWUPDATE}" "${INSTALLED}"
fi fi
# we're always starting from our working directory # we're always starting from our working directory
@ -31,138 +31,138 @@ export EXT_FONT_DIR="/mnt/onboard/fonts"
# through fmon, or from another launcher (KSM or advboot) # through fmon, or from another launcher (KSM or advboot)
# Do not delete this line because KSM detects newer versions of KOReader by the presence of the phrase 'from_nickel'. # Do not delete this line because KSM detects newer versions of KOReader by the presence of the phrase 'from_nickel'.
export FROM_NICKEL="false" export FROM_NICKEL="false"
if pkill -0 nickel ; then if pkill -0 nickel; then
FROM_NICKEL="true" FROM_NICKEL="true"
fi fi
if [ "${FROM_NICKEL}" = "true" ] ; then if [ "${FROM_NICKEL}" = "true" ]; then
# Detect if we were started from KFMon # Detect if we were started from KFMon
FROM_KFMON="false" FROM_KFMON="false"
if pkill -0 kfmon ; then if pkill -0 kfmon; then
# That's a start, now check if KFMon truly is our parent... # That's a start, now check if KFMon truly is our parent...
if [ "$(pidof kfmon)" -eq "${PPID}" ] ; then if [ "$(pidof kfmon)" -eq "${PPID}" ]; then
FROM_KFMON="true" FROM_KFMON="true"
fi fi
fi fi
if [ "${FROM_KFMON}" = "true" ] ; then if [ "${FROM_KFMON}" = "true" ]; then
# Siphon nickel's full environment, since KFMon inherits such a minimal one, and that apparently confuses the hell out of Nickel for some reason if we decide to restart it without a reboot... # Siphon nickel's full environment, since KFMon inherits such a minimal one, and that apparently confuses the hell out of Nickel for some reason if we decide to restart it without a reboot...
for env in $(xargs -n 1 -0 < "/proc/$(pidof nickel)/environ") ; do for env in $(xargs -n 1 -0 <"/proc/$(pidof nickel)/environ"); do
# shellcheck disable=SC2163 # shellcheck disable=SC2163
export "${env}" export "${env}"
done done
else else
# Siphon a few things from nickel's env... # Siphon a few things from nickel's env...
eval "$(xargs -n 1 -0 < "/proc/$(pidof nickel)/environ" | grep -e DBUS_SESSION_BUS_ADDRESS -e WIFI_MODULE -e PLATFORM -e WIFI_MODULE_PATH -e INTERFACE -e PRODUCT 2>/dev/null)" eval "$(xargs -n 1 -0 <"/proc/$(pidof nickel)/environ" | grep -e DBUS_SESSION_BUS_ADDRESS -e WIFI_MODULE -e PLATFORM -e WIFI_MODULE_PATH -e INTERFACE -e PRODUCT 2>/dev/null)"
export DBUS_SESSION_BUS_ADDRESS WIFI_MODULE PLATFORM WIFI_MODULE_PATH INTERFACE PRODUCT export DBUS_SESSION_BUS_ADDRESS WIFI_MODULE PLATFORM WIFI_MODULE_PATH INTERFACE PRODUCT
fi fi
# flush disks, might help avoid trashing nickel's DB... # flush disks, might help avoid trashing nickel's DB...
sync sync
# Double the fun! # Double the fun!
sleep 1 sleep 1
sync sync
# stop kobo software because it's running # stop kobo software because it's running
killall nickel hindenburg sickel fickel fmon 2>/dev/null killall nickel hindenburg sickel fickel fmon 2>/dev/null
# NOTE: Not particularly critical, we should be safe leaving it up, but since we reboot on exit anyway... # NOTE: Not particularly critical, we should be safe leaving it up, but since we reboot on exit anyway...
# Keep KFMon up for now to make sure it's not doing anything overly stupid we might have overlooked ;). # Keep KFMon up for now to make sure it's not doing anything overly stupid we might have overlooked ;).
#if [ "${FROM_KFMON}" == "true" ] ; then #if [ "${FROM_KFMON}" == "true" ] ; then
# killall kfmon 2>/dev/null # killall kfmon 2>/dev/null
#fi #fi
fi fi
# fallback for old fmon (and advboot) users (-> if no args were passed to the sript, start the FM) # fallback for old fmon (and advboot) users (-> if no args were passed to the sript, start the FM)
if [ "$#" -eq 0 ] ; then if [ "$#" -eq 0 ]; then
args="/mnt/onboard" args="/mnt/onboard"
else else
args="$*" args="$*"
fi fi
# check whether PLATFORM & PRODUCT have a value assigned by rcS # check whether PLATFORM & PRODUCT have a value assigned by rcS
if [ ! -n "${PRODUCT}" ] ; then if [ ! -n "${PRODUCT}" ]; then
PRODUCT="$(/bin/kobo_config.sh 2>/dev/null)" PRODUCT="$(/bin/kobo_config.sh 2>/dev/null)"
export PRODUCT export PRODUCT
fi fi
# PLATFORM is used in koreader for the path to the WiFi drivers # PLATFORM is used in koreader for the path to the WiFi drivers
if [ ! -n "${PLATFORM}" ] ; then if [ ! -n "${PLATFORM}" ]; then
PLATFORM="freescale" PLATFORM="freescale"
if dd if="/dev/mmcblk0" bs=512 skip=1024 count=1 | grep -q "HW CONFIG" ; then if dd if="/dev/mmcblk0" bs=512 skip=1024 count=1 | grep -q "HW CONFIG"; then
CPU="$(ntx_hwconfig -s -p /dev/mmcblk0 CPU 2>/dev/null)" CPU="$(ntx_hwconfig -s -p /dev/mmcblk0 CPU 2>/dev/null)"
PLATFORM="${CPU}-ntx" PLATFORM="${CPU}-ntx"
fi fi
if [ "${PLATFORM}" = "freescale" ] ; then if [ "${PLATFORM}" = "freescale" ]; then
if [ ! -s "/lib/firmware/imx/epdc_E60_V220.fw" ] ; then if [ ! -s "/lib/firmware/imx/epdc_E60_V220.fw" ]; then
mkdir -p "/lib/firmware/imx" mkdir -p "/lib/firmware/imx"
dd if="/dev/mmcblk0" bs=512K skip=10 count=1 | zcat > "/lib/firmware/imx/epdc_E60_V220.fw" dd if="/dev/mmcblk0" bs=512K skip=10 count=1 | zcat >"/lib/firmware/imx/epdc_E60_V220.fw"
sync sync
fi fi
elif [ ! -e "/etc/u-boot/${PLATFORM}/u-boot.mmc" ] ; then elif [ ! -e "/etc/u-boot/${PLATFORM}/u-boot.mmc" ]; then
PLATFORM="ntx508" PLATFORM="ntx508"
fi fi
export PLATFORM export PLATFORM
fi fi
# end of value check of PLATFORM # end of value check of PLATFORM
# Remount the SD card RW if it's inserted and currently RO # Remount the SD card RW if it's inserted and currently RO
if awk '$4~/(^|,)ro($|,)/' /proc/mounts | grep ' /mnt/sd ' ; then if awk '$4~/(^|,)ro($|,)/' /proc/mounts | grep ' /mnt/sd '; then
mount -o remount,rw /mnt/sd mount -o remount,rw /mnt/sd
fi fi
# we keep maximum 500K worth of crash log # we keep maximum 500K worth of crash log
if [ -e crash.log ]; then if [ -e crash.log ]; then
tail -c 500000 crash.log > crash.log.new tail -c 500000 crash.log >crash.log.new
mv -f crash.log.new crash.log mv -f crash.log.new crash.log
fi fi
# workaround 32-bit without KSM (KSM is indicated by ${ksmroot} being set) # workaround 32-bit without KSM (KSM is indicated by ${ksmroot} being set)
# shellcheck disable=2154 # shellcheck disable=2154
if [ -z "${ksmroot+x:?}" ]; then if [ -z "${ksmroot+x:?}" ]; then
# TODO: add support for 32bit framebuffer in koreader. This is a workaround # TODO: add support for 32bit framebuffer in koreader. This is a workaround
# to run koreader in 16bpp. Useful since FW 4.0 # to run koreader in 16bpp. Useful since FW 4.0
CUR_ROTATE="$(cat "/sys/class/graphics/fb0/rotate")" CUR_ROTATE="$(cat "/sys/class/graphics/fb0/rotate")"
FB_BPP=$(cat /sys/class/graphics/fb0/bits_per_pixel) FB_BPP=$(cat /sys/class/graphics/fb0/bits_per_pixel)
[ "${FB_BPP}" -gt 16 ] && /usr/sbin/fbset -depth 16 [ "${FB_BPP}" -gt 16 ] && /usr/sbin/fbset -depth 16
# this suffices on normal devices, but H2O is stupid and sets the opposite # this suffices on normal devices, but H2O is stupid and sets the opposite
echo "${CUR_ROTATE}" > "/sys/class/graphics/fb0/rotate" echo "${CUR_ROTATE}" >"/sys/class/graphics/fb0/rotate"
# this therefore turns it around on H2O (and other potential idiots) and merely # this therefore turns it around on H2O (and other potential idiots) and merely
# innocently repeats on sane devices # innocently repeats on sane devices
# shellcheck disable=SC2094 # shellcheck disable=SC2094
cat "/sys/class/graphics/fb0/rotate" > "/sys/class/graphics/fb0/rotate" cat "/sys/class/graphics/fb0/rotate" >"/sys/class/graphics/fb0/rotate"
fi fi
./reader.lua "${args}" >> crash.log 2>&1 ./reader.lua "${args}" >>crash.log 2>&1
RESULT=$? RESULT=$?
# workaround 32-bit without KSM (KSM is indicated by s${ksmroot} being set) # workaround 32-bit without KSM (KSM is indicated by s${ksmroot} being set)
if [ -z "${ksmroot+x:?}" ]; then if [ -z "${ksmroot+x:?}" ]; then
# back to default depth in framebuffer. # back to default depth in framebuffer.
[ "${FB_BPP}" -gt 16 ] && /usr/sbin/fbset -depth "${FB_BPP}" [ "${FB_BPP}" -gt 16 ] && /usr/sbin/fbset -depth "${FB_BPP}"
fi fi
if [ "${FROM_NICKEL}" = "true" ] ; then if [ "${FROM_NICKEL}" = "true" ]; then
if [ "${FROM_KFMON}" != "true" ] ; then if [ "${FROM_KFMON}" != "true" ]; then
# start kobo software because it was running before koreader # start kobo software because it was running before koreader
./nickel.sh & ./nickel.sh &
else else
if grep -q 'reboot_on_exit=false' /mnt/onboard/.adds/kfmon/config/koreader.ini 2>/dev/null ; then if grep -q 'reboot_on_exit=false' /mnt/onboard/.adds/kfmon/config/koreader.ini 2>/dev/null; then
# The user wants to try to restart Nickel instead of rebooting! # The user wants to try to restart Nickel instead of rebooting!
./nickel.sh & ./nickel.sh &
else else
# By default, if we were called from KFMon, just reboot, because there might be a chance Nickel will get its panties in a serious twist on restore for one reason or another... # By default, if we were called from KFMon, just reboot, because there might be a chance Nickel will get its panties in a serious twist on restore for one reason or another...
# And at best, we'd still restart with slightly broken suspend behavior anyway... # And at best, we'd still restart with slightly broken suspend behavior anyway...
/sbin/reboot /sbin/reboot
fi fi
fi fi
else else
# if we were called from advboot then we must reboot to go to the menu # if we were called from advboot then we must reboot to go to the menu
# NOTE: This is actually achieved by checking if KSM or a KSM-related script is running: # NOTE: This is actually achieved by checking if KSM or a KSM-related script is running:
# This might lead to false-positives if you use neither KSM nor advboot to launch KOReader *without nickel running*. # This might lead to false-positives if you use neither KSM nor advboot to launch KOReader *without nickel running*.
if ! pgrep -f kbmenu > /dev/null 2>&1 ; then if ! pgrep -f kbmenu >/dev/null 2>&1; then
/sbin/reboot /sbin/reboot
fi fi
fi fi
return ${RESULT} return ${RESULT}

@ -5,20 +5,23 @@ PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/lib"
cur_rotate="$(cat "/sys/class/graphics/fb0/rotate")" 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. # 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: # environment needed by nickel, from /etc/init.d/rcS:
if [ ! -n "${WIFI_MODULE_PATH}" ] ; then if [ ! -n "${WIFI_MODULE_PATH}" ]; then
INTERFACE="wlan0" INTERFACE="wlan0"
WIFI_MODULE="ar6000" WIFI_MODULE="ar6000"
if [ "${PLATFORM}" != "freescale" ] ; then if [ "${PLATFORM}" != "freescale" ]; then
INTERFACE="eth0" INTERFACE="eth0"
WIFI_MODULE="dhd" WIFI_MODULE="dhd"
fi fi
export INTERFACE export INTERFACE
export WIFI_MODULE export WIFI_MODULE
export WIFI_MODULE_PATH="/drivers/${PLATFORM}/wifi/${WIFI_MODULE}.ko" export WIFI_MODULE_PATH="/drivers/${PLATFORM}/wifi/${WIFI_MODULE}.ko"
fi fi
export NICKEL_HOME="/mnt/onboard/.kobo" export NICKEL_HOME="/mnt/onboard/.kobo"
@ -28,13 +31,13 @@ export LANG="en_US.UTF-8"
# Make sure we kill the WiFi first, because nickel apparently doesn't like it if it's up... (cf. #1520) # Make sure we kill the WiFi first, because nickel apparently doesn't like it if it's up... (cf. #1520)
# NOTE: That check is possibly wrong on PLATFORM == freescale (because I don't know if the sdio_wifi_pwr module exists there), but we don't terribly care about that. # NOTE: That check is possibly wrong on PLATFORM == freescale (because I don't know if the sdio_wifi_pwr module exists there), but we don't terribly care about that.
if lsmod | grep -q sdio_wifi_pwr ; then if lsmod | grep -q sdio_wifi_pwr; then
killall udhcpc default.script wpa_supplicant 2>/dev/null killall udhcpc default.script wpa_supplicant 2>/dev/null
wlarm_le -i ${INTERFACE} down wlarm_le -i ${INTERFACE} down
ifconfig ${INTERFACE} down ifconfig ${INTERFACE} down
# NOTE: Kobo's busybox build is weird. rmmod appears to be modprobe in disguise, defaulting to the -r flag. If re-specifying -r starts to fail one day, switch to rmmod without args, or modprobe -r. # NOTE: Kobo's busybox build is weird. rmmod appears to be modprobe in disguise, defaulting to the -r flag. If re-specifying -r starts to fail one day, switch to rmmod without args, or modprobe -r.
rmmod -r ${WIFI_MODULE} rmmod -r ${WIFI_MODULE}
rmmod -r sdio_wifi_pwr rmmod -r sdio_wifi_pwr
fi fi
# Flush buffers to disk, who knows. # Flush buffers to disk, who knows.
@ -46,54 +49,53 @@ sync
# NOTE: Since we're not cold booting, this is technically redundant... On the other hand, it doesn't really hurt either ;). # NOTE: Since we're not cold booting, this is technically redundant... On the other hand, it doesn't really hurt either ;).
( (
/usr/local/Kobo/pickel disable.rtc.alarm /usr/local/Kobo/pickel disable.rtc.alarm
if [ ! -e "/etc/wpa_supplicant/wpa_supplicant.conf" ] ; then if [ ! -e "/etc/wpa_supplicant/wpa_supplicant.conf" ]; then
cp "/etc/wpa_supplicant/wpa_supplicant.conf.template" "/etc/wpa_supplicant/wpa_supplicant.conf" cp "/etc/wpa_supplicant/wpa_supplicant.conf.template" "/etc/wpa_supplicant/wpa_supplicant.conf"
fi fi
# FWIW, that appears to be gone from recent rcS scripts. AFAICT, still harmless, though. # FWIW, that appears to be gone from recent rcS scripts. AFAICT, still harmless, though.
echo 1 > "/sys/devices/platform/mxc_dvfs_core.0/enable" echo 1 >"/sys/devices/platform/mxc_dvfs_core.0/enable"
/sbin/hwclock -s -u /sbin/hwclock -s -u
) & ) &
# Hey there, nickel! # Hey there, nickel!
if [ ! -e "/usr/local/Kobo/platforms/libkobo.so" ] ; then if [ ! -e "/usr/local/Kobo/platforms/libkobo.so" ]; then
export QWS_KEYBOARD="imx508kbd:/dev/input/event0" export QWS_KEYBOARD="imx508kbd:/dev/input/event0"
export QT_PLUGIN_PATH="/usr/local/Kobo/plugins" export QT_PLUGIN_PATH="/usr/local/Kobo/plugins"
if [ -e "/usr/local/Kobo/plugins/gfxdrivers/libimxepd.so" ] ; then if [ -e "/usr/local/Kobo/plugins/gfxdrivers/libimxepd.so" ]; then
export QWS_DISPLAY="imxepd" export QWS_DISPLAY="imxepd"
else else
export QWS_DISPLAY="Transformed:imx508:Rot90" export QWS_DISPLAY="Transformed:imx508:Rot90"
export QWS_MOUSE_PROTO="tslib_nocal:/dev/input/event1" export QWS_MOUSE_PROTO="tslib_nocal:/dev/input/event1"
fi fi
# NOTE: Send the output to the void, to avoid spamming the shell with the output of the string of killall commands they periodically send # NOTE: Send the output to the void, to avoid spamming the shell with the output of the string of killall commands they periodically send
/usr/local/Kobo/hindenburg > /dev/null 2>&1 & /usr/local/Kobo/hindenburg >/dev/null 2>&1 &
/usr/local/Kobo/nickel -qws -skipFontLoad > /dev/null 2>&1 & /usr/local/Kobo/nickel -qws -skipFontLoad >/dev/null 2>&1 &
else else
/usr/local/Kobo/hindenburg > /dev/null 2>&1 & /usr/local/Kobo/hindenburg >/dev/null 2>&1 &
lsmod | grep -q lowmem || insmod "/drivers/${PLATFORM}/misc/lowmem.ko" & lsmod | grep -q lowmem || insmod "/drivers/${PLATFORM}/misc/lowmem.ko" &
if grep -q "dhcpcd=true" "/mnt/onboard/.kobo/Kobo/Kobo eReader.conf" ; then if grep -q "dhcpcd=true" "/mnt/onboard/.kobo/Kobo/Kobo eReader.conf"; then
dhcpcd -d -t 10 & dhcpcd -d -t 10 &
fi fi
/usr/local/Kobo/nickel -platform kobo -skipFontLoad > /dev/null 2>&1 & /usr/local/Kobo/nickel -platform kobo -skipFontLoad >/dev/null 2>&1 &
fi fi
# Ahoy, annoying sickel! # Ahoy, annoying sickel!
if [ -x /usr/local/Kobo/sickel ] ; then if [ -x /usr/local/Kobo/sickel ]; then
/usr/local/Kobo/sickel -platform kobo:noscreen > /dev/null 2>&1 & /usr/local/Kobo/sickel -platform kobo:noscreen >/dev/null 2>&1 &
fi fi
# Rotation weirdness, part II # Rotation weirdness, part II
echo "${cur_rotate}" > "/sys/class/graphics/fb0/rotate" echo "${cur_rotate}" >"/sys/class/graphics/fb0/rotate"
# shellcheck disable=SC2094 # shellcheck disable=SC2094
cat "/sys/class/graphics/fb0/rotate" > "/sys/class/graphics/fb0/rotate" cat "/sys/class/graphics/fb0/rotate" >"/sys/class/graphics/fb0/rotate"
# Handle sdcard # Handle sdcard
if [ -e "/dev/mmcblk1p1" ] ; then if [ -e "/dev/mmcblk1p1" ]; then
echo sd add /dev/mmcblk1p1 >> /tmp/nickel-hardware-status & echo sd add /dev/mmcblk1p1 >>/tmp/nickel-hardware-status &
fi fi
return 0 return 0

@ -36,12 +36,12 @@ fi
# we keep maximum 500K worth of crash log # we keep maximum 500K worth of crash log
if [ -e crash.log ]; then if [ -e crash.log ]; then
tail -c 500000 crash.log > crash.log.new tail -c 500000 crash.log >crash.log.new
mv -f crash.log.new crash.log mv -f crash.log.new crash.log
fi fi
./reader.lua "${args}" >> crash.log 2>&1 ./reader.lua "${args}" >>crash.log 2>&1
if pidof reader.lua > /dev/null 2>&1 ; then if pidof reader.lua >/dev/null 2>&1; then
killall -TERM reader.lua killall -TERM reader.lua
fi fi

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

Loading…
Cancel
Save