From bdb82d09c176bcb46197d9286a193748c5ce3e2e Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Sun, 15 Apr 2018 15:05:45 +0200 Subject: [PATCH] [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. --- Makefile | 5 +- platform/kobo/disable-wifi.sh | 2 +- platform/kobo/enable-wifi.sh | 9 ++- platform/kobo/fmon/README.txt | 22 ++++--- platform/kobo/fmon/koreader.sh | 1 + platform/kobo/koreader.sh | 27 +++------ platform/kobo/nickel.sh | 89 +++++------------------------ platform/kobo/obtain-ip.sh | 0 platform/kobo/release-ip.sh | 3 +- platform/kobo/restore-wifi-async.sh | 0 10 files changed, 47 insertions(+), 111 deletions(-) mode change 100644 => 100755 platform/kobo/disable-wifi.sh mode change 100644 => 100755 platform/kobo/enable-wifi.sh mode change 100644 => 100755 platform/kobo/fmon/koreader.sh mode change 100644 => 100755 platform/kobo/obtain-ip.sh mode change 100644 => 100755 platform/kobo/release-ip.sh mode change 100644 => 100755 platform/kobo/restore-wifi-async.sh diff --git a/Makefile b/Makefile index 82885e0b3..1853c08de 100644 --- a/Makefile +++ b/Makefile @@ -195,9 +195,6 @@ koboupdate: all # remove old package if any rm -f koreader-kobo-$(MACHINE)-$(VERSION).zip # Kobo launching scripts - mkdir -p $(INSTALL_DIR)/kobo/mnt/onboard/.kobo - ln -sf ../../../../../$(KOBO_DIR)/fmon $(INSTALL_DIR)/kobo/mnt/onboard/.kobo/ - cd $(INSTALL_DIR)/kobo && tar -czhf ../KoboRoot.tgz mnt cp resources/koreader.png $(INSTALL_DIR)/koreader.png cp $(KOBO_DIR)/fmon/README.txt $(INSTALL_DIR)/README_kobo.txt cp $(KOBO_DIR)/*.sh $(INSTALL_DIR)/koreader @@ -214,7 +211,7 @@ koboupdate: all echo "koreader/ota/package.index" >> $(INSTALL_DIR)/koreader/ota/package.index # update index file in zip package cd $(INSTALL_DIR) && zip -u ../koreader-kobo-$(MACHINE)-$(VERSION).zip \ - koreader/ota/package.index KoboRoot.tgz koreader.png README_kobo.txt + koreader/ota/package.index koreader.png README_kobo.txt # make gzip koboupdate for zsync OTA update cd $(INSTALL_DIR) && \ tar czafh ../koreader-kobo-$(MACHINE)-$(VERSION).targz \ diff --git a/platform/kobo/disable-wifi.sh b/platform/kobo/disable-wifi.sh old mode 100644 new mode 100755 index d59ece1b8..e4f11aec9 --- a/platform/kobo/disable-wifi.sh +++ b/platform/kobo/disable-wifi.sh @@ -4,7 +4,7 @@ killall udhcpc default.script wpa_supplicant 2>/dev/null -wlarm_le -i eth0 down +[ "${WIFI_MODULE}" != "8189fs" ] && wlarm_le -i eth0 down ifconfig eth0 down # Some sleep in between may avoid system getting hung diff --git a/platform/kobo/enable-wifi.sh b/platform/kobo/enable-wifi.sh old mode 100644 new mode 100755 index 2c0acc54a..e296fb6eb --- a/platform/kobo/enable-wifi.sh +++ b/platform/kobo/enable-wifi.sh @@ -5,11 +5,14 @@ lsmod | grep -q sdio_wifi_pwr || insmod "/drivers/${PLATFORM}/wifi/sdio_wifi_pwr.ko" # WIFI_MODULE_PATH = /drivers/$PLATFORM/wifi/$WIFI_MODULE.ko lsmod | grep -q "${WIFI_MODULE}" || insmod "${WIFI_MODULE_PATH}" -sleep 1 + +while [ ! -e /sys/class/net/eth0 ]; do + usleep 200000 +done ifconfig eth0 up -wlarm_le -i eth0 up +[ "$WIFI_MODULE" != "8189fs" ] && wlarm_le -i eth0 up pidof wpa_supplicant >/dev/null \ || env -u LD_LIBRARY_PATH \ - wpa_supplicant -D wext -s -ieth0 -O /var/run/wpa_supplicant -c/etc/wpa_supplicant/wpa_supplicant.conf -B + wpa_supplicant -D wext -s -i eth0 -O /var/run/wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -B diff --git a/platform/kobo/fmon/README.txt b/platform/kobo/fmon/README.txt index a2f9f16cc..e00a6acd5 100644 --- a/platform/kobo/fmon/README.txt +++ b/platform/kobo/fmon/README.txt @@ -1,19 +1,23 @@ Installation instructions for Kobo: -Newer installation based on Start Menu: -- Install "Start Menu" (http://www.mobileread.com/forums/showthread.php?t=255978) -- Extract the koreader folder of the zip into the ".adds" directory (both KoboRoot.tgz and the koreader.png file are only needed for the older installation based on Filemonitor. See below.). +Recommended installation method based on Start Menu: +- Install "Start Menu" (https://www.mobileread.com/forums/showthread.php?t=293804) +- Extract the "koreader" folder from the zip into the ".adds" directory (the koreader.png file are only needed for the alternate installation methods based on fmon. See below.). Select koreader from the Start Menu to start. +---- -Older installation based on Filemonitor: -- Put the image included in the zip (called "koreader.png") in the main folder of your kobo and disconnect it from your computer. Open the image on the reader, go back to the home and then, just to be extra-safe, reboot it. -- Install "Files Monitor" (http://www.mobileread.com/forums/showthread.php?t=218283). -- Extract the remaining content of the zip into the ".kobo" directory (both KoboRoot.tgz and the koreader folder). +Alternate installation method based on fmon: +- Put the image included in the zip (called "koreader.png") in an "icons" folder created in the main folder of your Kobo and disconnect it from your computer. Add the icon to a collection, set the view to List View and open the icon, then restart your device. +- Install "fmon" (https://github.com/baskerville/fmon). +- Extract the remaining content of the zip (the "koreader" folder) into the ".adds" directory. -Selecting the KOReader icon in your home, you will be able to launch KOReader. Simple enough, isn't it? Just be sure to process the image properly (follow those steps carefully) if it's the first time you install koreader, if you made a factory reset or if you deleted it in some way, otherwise you could end up launching koreader automatically at every boot, being unable to exit it without a factory reset. +Select the KOReader icon in your home to launch KOReader. Simple enough, isn't it? Just be sure to process the image properly. Follow these steps carefully if it's your first time installing KOReader, after a factory reset, or if you deleted it in some way. This will ensure KOReader starts properly. -When you update koreader, it should be sufficient to extract the koreader folder, without KoboRoot.tgz - that one is needed to add the launcher. +When you update KOReader manually, it should be sufficient to simply extract the "koreader" folder. + +NOTE: Using the legacy version of fmon (http://www.mobileread.com/forums/showthread.php?t=218283) is *STRONGLY* discouraged. +NOTEĀ²: If you like the concept, and want to check out something a bit more flexible/complex, check out KFMon (https://github.com/NiLuJe/kfmon). diff --git a/platform/kobo/fmon/koreader.sh b/platform/kobo/fmon/koreader.sh old mode 100644 new mode 100755 index 8a3c98be7..29af5e461 --- a/platform/kobo/fmon/koreader.sh +++ b/platform/kobo/fmon/koreader.sh @@ -1,2 +1,3 @@ #!/bin/sh +# NOTE: Legacy fmon script. Not needed with @Baskerville's fmon. "${root:?}/.kobo/fmon/fmon" "${root}/koreader.png" "${root}/.kobo/koreader/koreader.sh" & diff --git a/platform/kobo/koreader.sh b/platform/kobo/koreader.sh index fe95c1944..7dab99172 100755 --- a/platform/kobo/koreader.sh +++ b/platform/kobo/koreader.sh @@ -30,7 +30,7 @@ export STARDICT_DATA_DIR="data/dict" export EXT_FONT_DIR="/mnt/onboard/fonts" # fast and dirty way of check if we are called from nickel -# through fmon, or from another launcher (KSM or advboot) +# through fmon/KFMon, 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'. export FROM_NICKEL="false" if pkill -0 nickel; then @@ -55,26 +55,18 @@ if [ "${FROM_NICKEL}" = "true" ]; then done else # 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)" - export DBUS_SESSION_BUS_ADDRESS WIFI_MODULE PLATFORM WIFI_MODULE_PATH INTERFACE PRODUCT + 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 fi # flush disks, might help avoid trashing nickel's DB... sync - # Double the fun! - sleep 1 - sync # stop kobo software because it's running + # NOTE: We don't need to kill KFMon, it's smart enough not to allow running concurrent instances of ourselves 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... - # Keep KFMon up for now to make sure it's not doing anything overly stupid we might have overlooked ;). - #if [ "${FROM_KFMON}" == "true" ] ; then - # killall kfmon 2>/dev/null - #fi fi -# fallback for old fmon (and advboot) users (-> if no args were passed to the sript, start the FM) +# fallback for old fmon, KFMon and advboot users (-> if no args were passed to the script, start the FM) if [ "$#" -eq 0 ]; then args="/mnt/onboard" else @@ -113,7 +105,7 @@ if awk '$4~/(^|,)ro($|,)/' /proc/mounts | grep ' /mnt/sd '; then mount -o remount,rw /mnt/sd fi -# we keep maximum 500K worth of crash log +# we keep at most 500KB worth of crash log if [ -e crash.log ]; then tail -c 500000 crash.log >crash.log.new mv -f crash.log.new crash.log @@ -130,12 +122,11 @@ if [ "${FROM_NICKEL}" = "true" ]; then # start kobo software because it was running before koreader ./nickel.sh & else - 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! + 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) ./nickel.sh & 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... - # And at best, we'd still restart with slightly broken suspend behavior anyway... + # KFMon asked us to restart the device on exit /sbin/reboot fi fi diff --git a/platform/kobo/nickel.sh b/platform/kobo/nickel.sh index 7e5d655f9..9a65391aa 100755 --- a/platform/kobo/nickel.sh +++ b/platform/kobo/nickel.sh @@ -1,97 +1,38 @@ #!/bin/sh -PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/lib" +PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/lib:" -# Handle the rotation weirdness on some devices -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. +# Ensures fmon will restart. Note that we don't have to worry about reaping this, nickel kills on-animator.sh on start. ( + # NOTE: Recent FW versions appear to do away with the sleep on some platforms (I'm assuming the newer, faster, better ones!) usleep 400000 /etc/init.d/on-animator.sh ) & -# environment needed by nickel, from /etc/init.d/rcS: - -if [ ! -n "${WIFI_MODULE_PATH}" ]; then - INTERFACE="wlan0" - WIFI_MODULE="ar6000" - if [ "${PLATFORM}" != "freescale" ]; then - INTERFACE="eth0" - WIFI_MODULE="dhd" - fi - export INTERFACE - export WIFI_MODULE - export WIFI_MODULE_PATH="/drivers/${PLATFORM}/wifi/${WIFI_MODULE}.ko" -fi - -export NICKEL_HOME="/mnt/onboard/.kobo" +# We don't need to duplicate any of the env setup from rcS, since we will only ever run this to *restart* nickel, and not bootstrap it. +# Meaning we've already got most of the necessary env from nickel itself via both our launcher (fmon/KFMon) and our own startup script. export LD_LIBRARY_PATH="/usr/local/Kobo" -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) # 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 killall udhcpc default.script wpa_supplicant 2>/dev/null - wlarm_le -i ${INTERFACE} down - ifconfig ${INTERFACE} down + [ "${WIFI_MODULE}" != "8189fs" ] && wlarm_le -i "${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. - rmmod -r ${WIFI_MODULE} + rmmod -r "${WIFI_MODULE}" + # c.f., #2394? + usleep 200000 rmmod -r sdio_wifi_pwr fi # Flush buffers to disk, who knows. sync -# start nickel again (inspired from KSM, vlasovsoft & the base rcS), this should -# cover at least firmware versions from 2.6.1 to 3.12.1 (tested on a kobo -# mini with 3.4.1 firmware & a H2O on 3.12.1) - -# 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 - - if [ ! -e "/etc/wpa_supplicant/wpa_supplicant.conf" ]; then - cp "/etc/wpa_supplicant/wpa_supplicant.conf.template" "/etc/wpa_supplicant/wpa_supplicant.conf" - fi - - # FWIW, that appears to be gone from recent rcS scripts. AFAICT, still harmless, though. - echo 1 >"/sys/devices/platform/mxc_dvfs_core.0/enable" - - /sbin/hwclock -s -u -) & - -# Hey there, nickel! -if [ ! -e "/usr/local/Kobo/platforms/libkobo.so" ]; then - export QWS_KEYBOARD="imx508kbd:/dev/input/event0" - export QT_PLUGIN_PATH="/usr/local/Kobo/plugins" - if [ -e "/usr/local/Kobo/plugins/gfxdrivers/libimxepd.so" ]; then - export QWS_DISPLAY="imxepd" - else - export QWS_DISPLAY="Transformed:imx508:Rot90" - export QWS_MOUSE_PROTO="tslib_nocal:/dev/input/event1" - 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 - /usr/local/Kobo/hindenburg >/dev/null 2>&1 & - /usr/local/Kobo/nickel -qws -skipFontLoad >/dev/null 2>&1 & -else - /usr/local/Kobo/hindenburg >/dev/null 2>&1 & - lsmod | grep -q lowmem || insmod "/drivers/${PLATFORM}/misc/lowmem.ko" & - if grep -q "dhcpcd=true" "/mnt/onboard/.kobo/Kobo/Kobo eReader.conf"; then - dhcpcd -d -t 10 & - fi - /usr/local/Kobo/nickel -platform kobo -skipFontLoad >/dev/null 2>&1 & -fi - -# Ahoy, annoying sickel! -if [ -x /usr/local/Kobo/sickel ]; then - /usr/local/Kobo/sickel -platform kobo:noscreen >/dev/null 2>&1 & -fi - -# Rotation weirdness, part II -echo "${cur_rotate}" >"/sys/class/graphics/fb0/rotate" -# shellcheck disable=SC2094 -cat "/sys/class/graphics/fb0/rotate" >"/sys/class/graphics/fb0/rotate" +# And finally, simply restart nickel. +# We don't care about horribly legacy stuff, because if people switch between nickel and KOReader in the first place, I assume they're using a decently recent enough FW version. +# Last tested on an H2O running FW 4.7.x +/usr/local/Kobo/hindenburg & +LIBC_FATAL_STDERR_=1 /usr/local/Kobo/nickel -platform kobo -skipFontLoad & # Handle sdcard if [ -e "/dev/mmcblk1p1" ]; then diff --git a/platform/kobo/obtain-ip.sh b/platform/kobo/obtain-ip.sh old mode 100644 new mode 100755 diff --git a/platform/kobo/release-ip.sh b/platform/kobo/release-ip.sh old mode 100644 new mode 100755 index 9cc284355..d57e8d139 --- a/platform/kobo/release-ip.sh +++ b/platform/kobo/release-ip.sh @@ -1,9 +1,8 @@ #!/bin/sh # PATH export is only needed if you run this script manually from a shell -export PATH=$PATH:/sbin +export PATH="${PATH}:/sbin" # Release IP and shutdown udhcpc. - pkill -9 -f '/bin/sh /etc/udhcpc.d/default.script' ifconfig eth0 0.0.0.0 diff --git a/platform/kobo/restore-wifi-async.sh b/platform/kobo/restore-wifi-async.sh old mode 100644 new mode 100755