2013-07-10 07:10:38 +00:00
|
|
|
#!/bin/sh
|
|
|
|
export LC_ALL="en_US.UTF-8"
|
|
|
|
|
2014-08-01 04:36:32 +00:00
|
|
|
# working directory of koreader
|
2015-04-26 18:46:30 +00:00
|
|
|
KOREADER_DIR="${0%/*}"
|
2014-08-01 04:36:32 +00:00
|
|
|
|
2017-04-12 07:07:06 +00:00
|
|
|
# we're always starting from our working directory
|
|
|
|
cd "${KOREADER_DIR}" || exit
|
|
|
|
|
2018-07-29 01:53:57 +00:00
|
|
|
# Attempt to switch to a sensible CPUFreq governor when that's not already the case...
|
|
|
|
current_cpufreq_gov="$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor)"
|
|
|
|
# NOTE: We're being fairly conservative here, because what's used and what's available varies depending on HW...
|
|
|
|
if [ "${current_cpufreq_gov}" != "ondemand" ] && [ "${current_cpufreq_gov}" != "interactive" ]; then
|
|
|
|
# NOTE: Go with ondemand, because it's likely to be the lowest common denominator.
|
|
|
|
# Plus, interactive is hard to tune right, and only really interesting when it's a recent version,
|
|
|
|
# which I somehow doubt is the case anywhere here...
|
|
|
|
if grep -q ondemand /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors; then
|
|
|
|
ORIG_CPUFREQ_GOV="${current_cpufreq_gov}"
|
|
|
|
echo "ondemand" >"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
# NOTE: That doesn't actually help us poor userspace plebs, but, short of switching to performance,
|
|
|
|
# I don't really have a golden bullet here... (conservative's rubberbanding is terrible, so that's a hard pass).
|
|
|
|
# All I can say is that userspace is a terrible idea and behaves *very* strangely (c.f., #4114).
|
2018-07-28 14:09:58 +00:00
|
|
|
|
2014-08-01 04:36:32 +00:00
|
|
|
# update to new version from OTA directory
|
2018-07-04 17:25:55 +00:00
|
|
|
ko_update_check() {
|
|
|
|
NEWUPDATE="${KOREADER_DIR}/ota/koreader.updated.tar"
|
|
|
|
INSTALLED="${KOREADER_DIR}/ota/koreader.installed.tar"
|
|
|
|
if [ -f "${NEWUPDATE}" ]; then
|
2018-09-05 23:35:48 +00:00
|
|
|
./fbink -q -y -7 -pmh "Updating KOReader"
|
|
|
|
# NOTE: See frontend/ui/otamanager.lua for a few more details on how we squeeze a percentage out of tar's checkpoint feature
|
|
|
|
# NOTE: %B should always be 512 in our case, so let stat do part of the maths for us instead of using %s ;).
|
|
|
|
FILESIZE="$(stat -c %b "${NEWUPDATE}")"
|
|
|
|
BLOCKS="$((FILESIZE / 20))"
|
|
|
|
export CPOINTS="$((BLOCKS / 100))"
|
2018-07-04 17:25:55 +00:00
|
|
|
# shellcheck disable=SC2016
|
2018-09-05 23:35:48 +00:00
|
|
|
./tar xf "${NEWUPDATE}" --strip-components=1 --no-same-permissions --no-same-owner --checkpoint="${CPOINTS}" --checkpoint-action=exec='./fbink -q -y -6 -P $(($TAR_CHECKPOINT/$CPOINTS))'
|
2018-07-04 17:25:55 +00:00
|
|
|
fail=$?
|
|
|
|
# Cleanup behind us...
|
|
|
|
if [ "${fail}" -eq 0 ]; then
|
|
|
|
mv "${NEWUPDATE}" "${INSTALLED}"
|
|
|
|
./fbink -q -y -6 -pm "Update successful :)"
|
|
|
|
./fbink -q -y -5 -pm "KOReader will start momentarily . . ."
|
|
|
|
else
|
|
|
|
# Huh ho...
|
|
|
|
./fbink -q -y -6 -pmh "Update failed :("
|
|
|
|
./fbink -q -y -5 -pm "KOReader may fail to function properly!"
|
|
|
|
fi
|
|
|
|
rm -f "${NEWUPDATE}" # always purge newupdate in all cases to prevent update loop
|
2018-09-05 23:35:48 +00:00
|
|
|
unset BLOCKS CPOINTS
|
2018-07-03 21:16:45 +00:00
|
|
|
fi
|
2018-07-04 17:25:55 +00:00
|
|
|
}
|
2018-07-07 20:27:38 +00:00
|
|
|
# NOTE: Keep doing an initial update check, in addition to one during the restart loop, so we can pickup potential updates of this very script...
|
2018-07-04 17:25:55 +00:00
|
|
|
ko_update_check
|
2018-07-07 20:27:38 +00:00
|
|
|
# If an update happened, and was successful, reexec
|
|
|
|
if [ -n "${fail}" ] && [ "${fail}" -eq 0 ]; then
|
|
|
|
# By now, we know we're in the right directory, and our script name is pretty much set in stone, so we can forgo using $0
|
|
|
|
exec ./koreader.sh "${@}"
|
|
|
|
fi
|
2014-08-01 04:36:32 +00:00
|
|
|
|
2015-04-13 02:54:28 +00:00
|
|
|
# load our own shared libraries if possible
|
2015-04-26 18:46:30 +00:00
|
|
|
export LD_LIBRARY_PATH="${KOREADER_DIR}/libs:${LD_LIBRARY_PATH}"
|
2015-04-13 02:54:28 +00:00
|
|
|
|
2013-07-10 07:10:38 +00:00
|
|
|
# export trained OCR data directory
|
|
|
|
export TESSDATA_PREFIX="data"
|
|
|
|
|
|
|
|
# export dict directory
|
|
|
|
export STARDICT_DATA_DIR="data/dict"
|
|
|
|
|
2015-01-27 18:17:54 +00:00
|
|
|
# export external font directory
|
|
|
|
export EXT_FONT_DIR="/mnt/onboard/fonts"
|
2015-01-25 08:52:01 +00:00
|
|
|
|
2014-08-18 23:48:31 +00:00
|
|
|
# fast and dirty way of check if we are called from nickel
|
[chore] A round of Kobo specific script cleanup (#3876)
* Flag those scripts as executable in git
Somewhat irrelevant because we'll end up living on a FAT32 drive, but,
still.
* Cleanup Kobo startup script
Support KFMon >= 0.9.5
Don't siphon PRODUCT from nickel, it's exported by rcS, so fmon/KFMon
already inherit it.
Siphon NICKEL_HOME, on the off-chance nickel fails to figure that one
out for itself on restart.
Siphon LANG (This may be a terrible idea, rcS sets LANG to en_US.UTF-8,
while we set LC_ALL to en_US.UTF-8, but I don't know if nickel itself
ever updates LANG, since I have mine set to en_US also ;)).
My secret hope if that everything's working as it should and this ensures
we default to Nickel's locale on fresh installs?
Remove the extra sync on startup, both @Baskerville's fmon and KFMon are
smart enough not to do anything overly stupid, and recent FW versions
have a slightly more resilient DB anyway (rollback journal -> WAL).
This effectively shaves over a second off our startup time.
* Slimmed down the nickel restart script.
Based on current rcS
Scrapped a bucketload of irrelevant & legacy crap, since we're never
bootstrapping nickel, only restarting it.
* Update Kobo install instrcutions.
Point to KSM09, @Baskerville's fmon, and KFMon.
Deprecate legacy fmon, and as such, stop shipping a useless KoboRoot
tarball.
2018-04-15 13:05:45 +00:00
|
|
|
# through fmon/KFMon, or from another launcher (KSM or advboot)
|
2016-03-15 17:12:01 +00:00
|
|
|
# Do not delete this line because KSM detects newer versions of KOReader by the presence of the phrase 'from_nickel'.
|
2016-03-01 19:01:10 +00:00
|
|
|
export FROM_NICKEL="false"
|
2017-04-11 09:28:01 +00:00
|
|
|
if pkill -0 nickel; then
|
|
|
|
FROM_NICKEL="true"
|
2015-04-26 18:46:30 +00:00
|
|
|
fi
|
2014-06-25 13:31:42 +00:00
|
|
|
|
2017-04-11 09:28:01 +00:00
|
|
|
if [ "${FROM_NICKEL}" = "true" ]; then
|
|
|
|
# Detect if we were started from KFMon
|
|
|
|
FROM_KFMON="false"
|
|
|
|
if pkill -0 kfmon; then
|
|
|
|
# That's a start, now check if KFMon truly is our parent...
|
|
|
|
if [ "$(pidof kfmon)" -eq "${PPID}" ]; then
|
|
|
|
FROM_KFMON="true"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2018-05-10 10:26:07 +00:00
|
|
|
# Siphon a few things from nickel's env (namely, stuff exported by rcS *after* on-animator.sh has been launched)...
|
|
|
|
eval "$(xargs -n 1 -0 <"/proc/$(pidof nickel)/environ" | grep -e DBUS_SESSION_BUS_ADDRESS -e NICKEL_HOME -e WIFI_MODULE -e LANG -e WIFI_MODULE_PATH -e INTERFACE 2>/dev/null)"
|
|
|
|
export DBUS_SESSION_BUS_ADDRESS NICKEL_HOME WIFI_MODULE LANG WIFI_MODULE_PATH INTERFACE
|
2017-04-11 09:28:01 +00:00
|
|
|
|
|
|
|
# flush disks, might help avoid trashing nickel's DB...
|
|
|
|
sync
|
|
|
|
# stop kobo software because it's running
|
2018-05-10 10:26:07 +00:00
|
|
|
# NOTE: We don't need to kill KFMon, it's smart enough not to allow running anything else while we're up
|
2017-04-11 09:28:01 +00:00
|
|
|
killall nickel hindenburg sickel fickel fmon 2>/dev/null
|
2014-08-18 23:48:31 +00:00
|
|
|
fi
|
|
|
|
|
[chore] A round of Kobo specific script cleanup (#3876)
* Flag those scripts as executable in git
Somewhat irrelevant because we'll end up living on a FAT32 drive, but,
still.
* Cleanup Kobo startup script
Support KFMon >= 0.9.5
Don't siphon PRODUCT from nickel, it's exported by rcS, so fmon/KFMon
already inherit it.
Siphon NICKEL_HOME, on the off-chance nickel fails to figure that one
out for itself on restart.
Siphon LANG (This may be a terrible idea, rcS sets LANG to en_US.UTF-8,
while we set LC_ALL to en_US.UTF-8, but I don't know if nickel itself
ever updates LANG, since I have mine set to en_US also ;)).
My secret hope if that everything's working as it should and this ensures
we default to Nickel's locale on fresh installs?
Remove the extra sync on startup, both @Baskerville's fmon and KFMon are
smart enough not to do anything overly stupid, and recent FW versions
have a slightly more resilient DB anyway (rollback journal -> WAL).
This effectively shaves over a second off our startup time.
* Slimmed down the nickel restart script.
Based on current rcS
Scrapped a bucketload of irrelevant & legacy crap, since we're never
bootstrapping nickel, only restarting it.
* Update Kobo install instrcutions.
Point to KSM09, @Baskerville's fmon, and KFMon.
Deprecate legacy fmon, and as such, stop shipping a useless KoboRoot
tarball.
2018-04-15 13:05:45 +00:00
|
|
|
# fallback for old fmon, KFMon and advboot users (-> if no args were passed to the script, start the FM)
|
2017-04-11 09:28:01 +00:00
|
|
|
if [ "$#" -eq 0 ]; then
|
|
|
|
args="/mnt/onboard"
|
2014-08-18 23:48:31 +00:00
|
|
|
else
|
2017-04-11 09:28:01 +00:00
|
|
|
args="$*"
|
2014-08-18 23:48:31 +00:00
|
|
|
fi
|
2013-07-10 07:10:38 +00:00
|
|
|
|
2015-04-26 23:21:54 +00:00
|
|
|
# check whether PLATFORM & PRODUCT have a value assigned by rcS
|
2017-04-11 09:28:01 +00:00
|
|
|
if [ ! -n "${PRODUCT}" ]; then
|
|
|
|
PRODUCT="$(/bin/kobo_config.sh 2>/dev/null)"
|
|
|
|
export PRODUCT
|
2015-04-26 23:21:54 +00:00
|
|
|
fi
|
|
|
|
|
2018-06-16 21:05:20 +00:00
|
|
|
# PLATFORM is used in koreader for the path to the WiFi drivers (as well as when restarting nickel)
|
2017-04-11 09:28:01 +00:00
|
|
|
if [ ! -n "${PLATFORM}" ]; then
|
|
|
|
PLATFORM="freescale"
|
|
|
|
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)"
|
|
|
|
PLATFORM="${CPU}-ntx"
|
|
|
|
fi
|
|
|
|
|
2018-06-16 21:05:20 +00:00
|
|
|
if [ "${PLATFORM}" != "freescale" ] && [ ! -e "/etc/u-boot/${PLATFORM}/u-boot.mmc" ]; then
|
2017-04-11 09:28:01 +00:00
|
|
|
PLATFORM="ntx508"
|
|
|
|
fi
|
|
|
|
export PLATFORM
|
2015-02-09 15:13:07 +00:00
|
|
|
fi
|
2018-05-10 10:26:07 +00:00
|
|
|
|
|
|
|
# Make sure we have a sane-ish INTERFACE env var set...
|
|
|
|
if [ ! -n "${INTERFACE}" ]; then
|
|
|
|
# That's what we used to hardcode anyway
|
|
|
|
INTERFACE="eth0"
|
|
|
|
export INTERFACE
|
|
|
|
fi
|
2015-02-09 15:13:07 +00:00
|
|
|
# end of value check of PLATFORM
|
|
|
|
|
2016-03-01 18:43:56 +00:00
|
|
|
# Remount the SD card RW if it's inserted and currently RO
|
2017-04-11 09:28:01 +00:00
|
|
|
if awk '$4~/(^|,)ro($|,)/' /proc/mounts | grep ' /mnt/sd '; then
|
|
|
|
mount -o remount,rw /mnt/sd
|
2016-02-23 12:46:57 +00:00
|
|
|
fi
|
2016-02-22 09:23:43 +00:00
|
|
|
|
[chore] A round of Kobo specific script cleanup (#3876)
* Flag those scripts as executable in git
Somewhat irrelevant because we'll end up living on a FAT32 drive, but,
still.
* Cleanup Kobo startup script
Support KFMon >= 0.9.5
Don't siphon PRODUCT from nickel, it's exported by rcS, so fmon/KFMon
already inherit it.
Siphon NICKEL_HOME, on the off-chance nickel fails to figure that one
out for itself on restart.
Siphon LANG (This may be a terrible idea, rcS sets LANG to en_US.UTF-8,
while we set LC_ALL to en_US.UTF-8, but I don't know if nickel itself
ever updates LANG, since I have mine set to en_US also ;)).
My secret hope if that everything's working as it should and this ensures
we default to Nickel's locale on fresh installs?
Remove the extra sync on startup, both @Baskerville's fmon and KFMon are
smart enough not to do anything overly stupid, and recent FW versions
have a slightly more resilient DB anyway (rollback journal -> WAL).
This effectively shaves over a second off our startup time.
* Slimmed down the nickel restart script.
Based on current rcS
Scrapped a bucketload of irrelevant & legacy crap, since we're never
bootstrapping nickel, only restarting it.
* Update Kobo install instrcutions.
Point to KSM09, @Baskerville's fmon, and KFMon.
Deprecate legacy fmon, and as such, stop shipping a useless KoboRoot
tarball.
2018-04-15 13:05:45 +00:00
|
|
|
# we keep at most 500KB worth of crash log
|
2017-04-09 08:42:16 +00:00
|
|
|
if [ -e crash.log ]; then
|
2017-04-11 09:28:01 +00:00
|
|
|
tail -c 500000 crash.log >crash.log.new
|
|
|
|
mv -f crash.log.new crash.log
|
2017-04-09 08:42:16 +00:00
|
|
|
fi
|
2017-04-06 20:54:24 +00:00
|
|
|
|
2017-05-16 09:11:11 +00:00
|
|
|
RETURN_VALUE=85
|
|
|
|
while [ $RETURN_VALUE -eq 85 ]; do
|
2018-07-04 17:25:55 +00:00
|
|
|
# Do an update check now, so we can actually update KOReader via the "Restart KOReader" menu entry ;).
|
|
|
|
ko_update_check
|
|
|
|
|
2017-05-16 09:11:11 +00:00
|
|
|
./reader.lua "${args}" >>crash.log 2>&1
|
|
|
|
RETURN_VALUE=$?
|
|
|
|
done
|
2014-08-18 23:48:31 +00:00
|
|
|
|
2018-07-29 01:53:57 +00:00
|
|
|
# Restore original CPUFreq governor if need be...
|
|
|
|
if [ -n "${ORIG_CPUFREQ_GOV}" ]; then
|
|
|
|
echo "${ORIG_CPUFREQ_GOV}" >"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"
|
|
|
|
fi
|
2018-07-28 14:09:58 +00:00
|
|
|
|
2017-04-11 09:28:01 +00:00
|
|
|
if [ "${FROM_NICKEL}" = "true" ]; then
|
|
|
|
if [ "${FROM_KFMON}" != "true" ]; then
|
|
|
|
# start kobo software because it was running before koreader
|
|
|
|
./nickel.sh &
|
|
|
|
else
|
[chore] A round of Kobo specific script cleanup (#3876)
* Flag those scripts as executable in git
Somewhat irrelevant because we'll end up living on a FAT32 drive, but,
still.
* Cleanup Kobo startup script
Support KFMon >= 0.9.5
Don't siphon PRODUCT from nickel, it's exported by rcS, so fmon/KFMon
already inherit it.
Siphon NICKEL_HOME, on the off-chance nickel fails to figure that one
out for itself on restart.
Siphon LANG (This may be a terrible idea, rcS sets LANG to en_US.UTF-8,
while we set LC_ALL to en_US.UTF-8, but I don't know if nickel itself
ever updates LANG, since I have mine set to en_US also ;)).
My secret hope if that everything's working as it should and this ensures
we default to Nickel's locale on fresh installs?
Remove the extra sync on startup, both @Baskerville's fmon and KFMon are
smart enough not to do anything overly stupid, and recent FW versions
have a slightly more resilient DB anyway (rollback journal -> WAL).
This effectively shaves over a second off our startup time.
* Slimmed down the nickel restart script.
Based on current rcS
Scrapped a bucketload of irrelevant & legacy crap, since we're never
bootstrapping nickel, only restarting it.
* Update Kobo install instrcutions.
Point to KSM09, @Baskerville's fmon, and KFMon.
Deprecate legacy fmon, and as such, stop shipping a useless KoboRoot
tarball.
2018-04-15 13:05:45 +00:00
|
|
|
if grep -q "reboot_on_exit=false" "/mnt/onboard/.adds/kfmon/config/koreader.ini" 2>/dev/null; then
|
|
|
|
# KFMon asked us to restart nickel on exit (default since KFMon 0.9.5)
|
2017-04-11 09:28:01 +00:00
|
|
|
./nickel.sh &
|
|
|
|
else
|
[chore] A round of Kobo specific script cleanup (#3876)
* Flag those scripts as executable in git
Somewhat irrelevant because we'll end up living on a FAT32 drive, but,
still.
* Cleanup Kobo startup script
Support KFMon >= 0.9.5
Don't siphon PRODUCT from nickel, it's exported by rcS, so fmon/KFMon
already inherit it.
Siphon NICKEL_HOME, on the off-chance nickel fails to figure that one
out for itself on restart.
Siphon LANG (This may be a terrible idea, rcS sets LANG to en_US.UTF-8,
while we set LC_ALL to en_US.UTF-8, but I don't know if nickel itself
ever updates LANG, since I have mine set to en_US also ;)).
My secret hope if that everything's working as it should and this ensures
we default to Nickel's locale on fresh installs?
Remove the extra sync on startup, both @Baskerville's fmon and KFMon are
smart enough not to do anything overly stupid, and recent FW versions
have a slightly more resilient DB anyway (rollback journal -> WAL).
This effectively shaves over a second off our startup time.
* Slimmed down the nickel restart script.
Based on current rcS
Scrapped a bucketload of irrelevant & legacy crap, since we're never
bootstrapping nickel, only restarting it.
* Update Kobo install instrcutions.
Point to KSM09, @Baskerville's fmon, and KFMon.
Deprecate legacy fmon, and as such, stop shipping a useless KoboRoot
tarball.
2018-04-15 13:05:45 +00:00
|
|
|
# KFMon asked us to restart the device on exit
|
2017-04-11 09:28:01 +00:00
|
|
|
/sbin/reboot
|
|
|
|
fi
|
|
|
|
fi
|
2014-08-18 23:48:31 +00:00
|
|
|
else
|
2017-04-11 09:28:01 +00:00
|
|
|
# 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:
|
|
|
|
# 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
|
|
|
|
/sbin/reboot
|
|
|
|
fi
|
2014-08-18 23:48:31 +00:00
|
|
|
fi
|
2015-04-26 23:59:50 +00:00
|
|
|
|
2017-05-16 09:11:11 +00:00
|
|
|
exit $RETURN_VALUE
|