#!/bin/sh # Publish compact main-network indicators to the 2720 Flip cover display. # Event-driven: called from the NetworkManager dispatcher and Sxmo hooks, so # the idle cover daemon never has to poll mmcli/nmcli itself. set -u COVERCTL="${BANANARCHY_COVERCTL:-/usr/bin/bananarchy-coverctl}" MMCLI="${BANANARCHY_MMCLI:-/usr/bin/mmcli}" GPS_MODEM="${BANANARCHY_GPS_MODEM:-/usr/bin/bananarchy-gps-modem.sh}" modem="" if [ -x "$GPS_MODEM" ]; then modem="$("$GPS_MODEM" path 2>/dev/null | head -n1)" fi case "$modem" in ''|*[!0-9a-zA-Z/_-]*) modem=any ;; esac tech="" signal="" if command -v jq >/dev/null 2>&1; then info="$("$MMCLI" -m "$modem" -J 2>/dev/null || true)" if [ -n "$info" ]; then rawtech="$(printf '%s' "$info" | jq -r \ '.modem.generic."access-technologies"[0]? // empty' 2>/dev/null || true)" case "$rawtech" in *5gnr*) tech="5G" ;; *lte*) tech="4G" ;; *hspa*|*umts*|*hsupa*|*hsdpa*) tech="3G" ;; *edge*) tech="E" ;; *gsm*|*gprs*) tech="2G" ;; esac signal="$(printf '%s' "$info" | jq -r \ '.modem.generic."signal-quality".value // empty' 2>/dev/null || true)" fi fi line="" [ -n "$tech" ] && line="$tech" case "$signal" in ''|*[!0-9]*) ;; *) line="$line SIG$signal" ;; esac if command -v nmcli >/dev/null 2>&1; then case "$(nmcli -t -f TYPE,STATE device 2>/dev/null || true)" in *wifi:connected*) line="$line WIFI" ;; esac fi line="$(printf '%s' "$line" | tr -s ' ' | sed 's/^ *//' | cut -c1-40)" [ -n "$line" ] && "$COVERCTL" NETWORK "$line" >/dev/null 2>&1 || true for d in /sys/class/power_supply/*; do [ -r "$d/type" ] && [ -r "$d/capacity" ] || continue read -r pstype < "$d/type" 2>/dev/null || continue [ "$pstype" = "Battery" ] || continue read -r pct < "$d/capacity" 2>/dev/null || continue case "$pct" in ''|*[!0-9]*) ;; *) "$COVERCTL" BATTERY "$pct" >/dev/null 2>&1 || true ;; esac break done exit 0