Kobo: tuer Nickel + siphon env WiFi + reboot a l'arret (refresh fiable)

This commit is contained in:
2026-06-15 12:46:11 +02:00
parent cc92b2f283
commit a7a92ffadf
2 changed files with 56 additions and 16 deletions

View File

@@ -1,29 +1,60 @@
#!/bin/sh #!/bin/sh
# Monitorink — point d'entrée lancé par NickelMenu. # Monitorink — point d'entrée lancé par NickelMenu.
#
# Prend le contrôle complet de l'appareil en TUANT Nickel (sinon Nickel auto-suspend
# l'appareil et coupe le WiFi, en conflit avec notre boucle). On siphonne d'abord les
# variables d'environnement WiFi de Nickel (WIFI_MODULE/PLATFORM/INTERFACE) pour pouvoir
# gérer le WiFi nous-mêmes. À l'arrêt (entrée « Monitorink STOP »), on REBOOT pour
# restaurer Nickel et l'usage normal de la liseuse.
export LC_ALL="en_US.UTF-8" export LC_ALL="en_US.UTF-8"
# PATH complet : l'environnement NickelMenu est minimal (curl/ip absents sinon).
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$PATH" export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$PATH"
BASE="/mnt/onboard/.adds/Monitorink" BASE="/mnt/onboard/.adds/Monitorink"
LOG="$BASE/monitorink.log" # sur la partition USB-visible (debug via USB) LOG="$BASE/monitorink.log"
cd "$BASE" || exit 1 cd "$BASE" || exit 1
# --- Configuration (adapter au besoin) --- # --- Configuration ---
# HTTP direct vers l'IP du homelab (busybox wget, pas de curl/DNS/TLS requis).
export MONITORINK_URL="http://192.168.0.43:8899/image.png" export MONITORINK_URL="http://192.168.0.43:8899/image.png"
export MONITORINK_REFRESH=30 # DEV: refresh rapide pour itérer (repasser à 300-600 en prod) export MONITORINK_REFRESH=30 # DEV: refresh rapide (repasser à 300-600 en prod)
echo "===== monitorink start $(date) =====" >> "$LOG" echo "===== monitorink start $(date) =====" >> "$LOG"; sync
sync
# Gouverneur CPU économe (Libra 2 = policy0 ; fallback générique). # --- Gouverneur CPU économe ---
echo ondemand > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor 2>/dev/null CPUFREQ="/sys/devices/system/cpu/cpufreq/policy0"
for gov in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do [ -d "$CPUFREQ" ] || CPUFREQ="/sys/devices/system/cpu/cpu0/cpufreq"
echo ondemand > "$gov" 2>/dev/null if grep -q ondemand "$CPUFREQ/scaling_available_governors" 2>/dev/null; then
done echo ondemand > "$CPUFREQ/scaling_governor" 2>/dev/null
fi
# Synchronise l'horloge RTC sur l'heure système (sinon rtcwake calcule mal -> suspend KO). # --- Prendre le contrôle : siphonner l'env Nickel (WiFi) puis tuer Nickel ---
if pkill -0 nickel 2>/dev/null; then
NICKEL_PID="$(pidof -s nickel)"
if [ -n "$NICKEL_PID" ]; then
NENV=$(tr '\0' '\n' < "/proc/$NICKEL_PID/environ" 2>/dev/null \
| grep -E '^(WIFI_MODULE|INTERFACE|NICKEL_HOME|DBUS_SESSION_BUS_ADDRESS|LANG|PLATFORM|PRODUCT)=')
[ -n "$NENV" ] && export $NENV
fi
UDEV_PID="$(pidof -s udevd)"
if [ -n "$UDEV_PID" ]; then
[ -z "$PRODUCT" ] && { V=$(tr '\0' '\n' < "/proc/$UDEV_PID/environ" 2>/dev/null | grep -E '^PRODUCT='); [ -n "$V" ] && export $V; }
[ -z "$PLATFORM" ] && { V=$(tr '\0' '\n' < "/proc/$UDEV_PID/environ" 2>/dev/null | grep -E '^PLATFORM='); [ -n "$V" ] && export $V; }
fi
[ -z "$INTERFACE" ] && export INTERFACE="eth0"
echo "[monitorink] WIFI_MODULE=$WIFI_MODULE PLATFORM=$PLATFORM INTERFACE=$INTERFACE PRODUCT=$PRODUCT" >> "$LOG"; sync
sync
killall -q -TERM nickel hindenburg sickel fickel fontickel adobehost foxitpdf iink dhcpcd-dbus dhcpcd 2>/dev/null
t=0; while pkill -0 nickel 2>/dev/null; do [ "$t" -ge 16 ] && break; usleep 250000; t=$((t + 1)); done
rm -f /tmp/nickel-hardware-status
fi
[ -z "$INTERFACE" ] && export INTERFACE="eth0"
# Synchronise l'horloge RTC (sinon rtcwake calcule mal le réveil).
hwclock -w -u 2>/dev/null hwclock -w -u 2>/dev/null
# Lance la boucle, tout est journalisé dans $LOG. # Boucle bloquante. À la sortie (STOP tue monitorinkloop.sh), on reboot pour restaurer Nickel.
exec sh "$BASE/monitorinkloop.sh" >> "$LOG" 2>&1 sh "$BASE/monitorinkloop.sh" >> "$LOG" 2>&1
echo "===== monitorink stop $(date) — reboot =====" >> "$LOG"; sync
sleep 1
reboot

View File

@@ -56,10 +56,19 @@ suspend_for() {
echo 0 > /sys/power/state-extended 2>/dev/null echo 0 > /sys/power/state-extended 2>/dev/null
} }
has_ip() { ip addr show 2>/dev/null | grep -o 'inet [0-9.]*' | grep -qv '127.0'; }
wifi_up() { wifi_up() {
./scripts/enable-wifi.sh >/dev/null 2>&1 ./scripts/enable-wifi.sh >/dev/null 2>&1
./scripts/force-wifi-connection.sh >/dev/null 2>&1 ./scripts/force-wifi-connection.sh >/dev/null 2>&1
# Attend l'association + bail DHCP (jusqu'à ~24 s).
i=0
while [ "$i" -lt 12 ]; do
./scripts/obtain-ip.sh >/dev/null 2>&1 ./scripts/obtain-ip.sh >/dev/null 2>&1
has_ip && return 0
sleep 2; i=$((i + 1))
done
return 1
} }
# MODE DEV : on garde le WiFi allumé (pas de disable, pas de suspend) -> fiable. # MODE DEV : on garde le WiFi allumé (pas de disable, pas de suspend) -> fiable.