From b8fcc587151c675a7cab599ee7b3c1f19330d723 Mon Sep 17 00:00:00 2001 From: Cosmin Gorgovan Date: Sat, 25 Mar 2017 19:09:12 +0000 Subject: [PATCH] Add support for Koreader's WiFi manager --- build.sh | 20 ++++++++++++-------- build_rootfs.sh | 2 +- files/disable-wifi.sh | 16 ++++++++++++++++ files/enable-wifi.sh | 12 ++++++++++++ files/obtain-ip.sh | 5 +++++ files/okreader.sh | 8 ++++++++ files/release-ip.sh | 3 +++ src/koreader-pkg/DEBIAN/control | 2 +- 8 files changed, 58 insertions(+), 10 deletions(-) create mode 100755 files/disable-wifi.sh create mode 100755 files/enable-wifi.sh create mode 100755 files/obtain-ip.sh create mode 100755 files/okreader.sh create mode 100755 files/release-ip.sh diff --git a/build.sh b/build.sh index 3f6f004..d5eb2b2 100755 --- a/build.sh +++ b/build.sh @@ -126,14 +126,18 @@ compile_koreader() { mkdir opt cd opt tar xf ../../koreader/koreader-kobo-arm-linux-gnueabihf*.targz - - echo "#!/bin/bash" > koreader/okreader.sh - echo "cd /opt/koreader" >> koreader/okreader.sh - echo "while true; do" >> koreader/okreader.sh - echo " ./luajit ./reader.lua /mnt" >> koreader/okreader.sh - echo "done" >> koreader/okreader.sh - chmod +x koreader/okreader.sh - + + cp ../../../files/okreader.sh koreader/ + cp ../../../files/disable-wifi.sh koreader/ + cp ../../../files/enable-wifi.sh koreader/ + cp ../../../files/obtain-ip.sh koreader/ + cp ../../../files/release-ip.sh koreader/ + chmod +x koreader/disable-wifi.sh + chmod +x koreader/enable-wifi.sh + chmod +x koreader/obtain-ip.sh + chmod +x koreader/release-ip.sh + chmod +x koreader/restore-wifi-async.sh + cp ../../../files/defaults.persistent.lua koreader/ cd ../../ diff --git a/build_rootfs.sh b/build_rootfs.sh index 0356332..fd95210 100755 --- a/build_rootfs.sh +++ b/build_rootfs.sh @@ -87,7 +87,7 @@ config_rootfs() { install_packages() { cp src/linux-okreader-modules_2.6.35.3-1_armhf.deb rootfs/ cp src/firmware-okreader_1.0-1_armhf.deb rootfs/ - cp src/koreader_2017.03-1_armhf.deb rootfs/ + cp src/koreader_2017.03-2_armhf.deb rootfs/ cp src/kobo_hwconfig/kobo-hwconfig_1.0-1_armhf.deb rootfs/ chroot rootfs/ bash -c "dpkg -i /*.deb" diff --git a/files/disable-wifi.sh b/files/disable-wifi.sh new file mode 100755 index 0000000..8d8d488 --- /dev/null +++ b/files/disable-wifi.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +# Disable wifi, and remove all modules. + +killall dhcpcd default.script wpa_supplicant 2>/dev/null + +ifconfig wlan0 down + +# Some sleep in between may avoid system getting hung +# (we test if a module is actually loaded to avoid unneeded sleeps) +if lsmod | grep -q $WIFI_MODULE ; then + rmmod $WIFI_MODULE +fi +if lsmod | grep -q sdio_wifi_pwr ; then + rmmod sdio_wifi_pwr +fi diff --git a/files/enable-wifi.sh b/files/enable-wifi.sh new file mode 100755 index 0000000..f20562f --- /dev/null +++ b/files/enable-wifi.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +# Load wifi modules and enable wifi. +lsmod | grep -q $WIFI_MODULE || modprobe $WIFI_MODULE +lsmod | grep -q sdio_wifi_pwr || modprobe sdio_wifi_pwr +sleep 1 + +ifconfig wlan0 up + +pidof wpa_supplicant >/dev/null || \ + ( wpa_supplicant -D wext -iwlan0 -C /var/run/wpa_supplicant -B; \ + ln -s /var/run/wpa_supplicant/wlan0 /var/run/wpa_supplicant/eth0 ) diff --git a/files/obtain-ip.sh b/files/obtain-ip.sh new file mode 100755 index 0000000..ecd83a4 --- /dev/null +++ b/files/obtain-ip.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +./release-ip.sh + +dhcpcd wlan0 diff --git a/files/okreader.sh b/files/okreader.sh new file mode 100755 index 0000000..22a15bf --- /dev/null +++ b/files/okreader.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +export WIFI_MODULE=brcmfmac + +cd /opt/koreader +while true; do + ./luajit ./reader.lua /mnt +done diff --git a/files/release-ip.sh b/files/release-ip.sh new file mode 100755 index 0000000..a3ba619 --- /dev/null +++ b/files/release-ip.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +pkill -9 -f 'dhcpcd' diff --git a/src/koreader-pkg/DEBIAN/control b/src/koreader-pkg/DEBIAN/control index 1e68fd8..4475901 100644 --- a/src/koreader-pkg/DEBIAN/control +++ b/src/koreader-pkg/DEBIAN/control @@ -1,5 +1,5 @@ Package: koreader -Version: 2017.03-1 +Version: 2017.03-2 Maintainer: Cosmin Gorgovan Architecture: armhf Description: An ebook viewer application.