Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·189 lines (173 loc) · 9.8 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·189 lines (173 loc) · 9.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/bin/sh
# MudiModem installer — run ON the GL-E5800 ("Mudi"). Self-contained: fetches
# every source file from GitHub and installs it, gzipping the view chunks on the
# box (busybox gzip). No toolchain, no committed artifacts. Idempotent.
# Run it from a root shell on the router (ssh root@<router> first if remote):
#
# curl -fsSL https://raw.githubusercontent.com/kevinherzig/MudiModem/main/install.sh | sh
#
# Env: MUDIMODEM_REF (branch/tag, default main), MUDIMODEM_BASE (override raw URL).
set -eu
REF="${MUDIMODEM_REF:-main}"
BASE="${MUDIMODEM_BASE:-https://raw.githubusercontent.com/kevinherzig/MudiModem/$REF}"
# Model guard: on some LANs 192.168.8.1 is a DIFFERENT GL router (AXT1800). Never
# write to anything that isn't a Mudi.
MODEL=$(cat /proc/device-tree/model 2>/dev/null | tr -d '\0')
case "$MODEL" in
*E5800*) echo "target OK: $MODEL" ;;
*) echo "REFUSING: this is not a GL-E5800 (got: '${MODEL:-unknown}')" >&2; exit 1 ;;
esac
fetch() { curl -fsSL "$BASE/$1"; } # curl -f => nonzero on HTTP error => set -e aborts
# Fetch a source file to a temp path first, so a mid-stream curl failure can't
# leave a truncated file in place (POSIX sh has no pipefail).
grab() { tmp=$(mktemp); fetch "$1" > "$tmp" || { echo "fetch failed: $1" >&2; rm -f "$tmp"; exit 1; }; }
gz_install() { grab "$1"; gzip -9 -c "$tmp" > "$2"; rm -f "$tmp"; echo " $2"; } # $1 src, $2 .gz target
cp_install() { grab "$1"; cat "$tmp" > "$2"; chmod "$3" "$2"; rm -f "$tmp"; echo " $2"; } # $1 src, $2 target, $3 mode
mkdir -p /www/views /www/mudimodem /usr/lib/mudimodem /usr/share/oui/menu.d \
/usr/share/gl-validator.d /usr/lib/oui-httpd/rpc /usr/sbin /usr/bin \
/etc/init.d /etc/mudimodem /etc/hotplug.d/i2c \
/usr/share/mudimodem/www/views /usr/share/mudimodem/www/mudimodem \
/etc/nginx/gl-conf.d /lib/upgrade/keep.d
# Dual-write a /www file into the FOTA persist tree. abfota drops /www.
persist_www() { cp -f "$1" "/usr/share/mudimodem/www/${1#/www/}"; echo " /usr/share/mudimodem/www/${1#/www/}"; }
echo "installing view chunks + menu + library:"
gz_install src/views/mudimodem.js /www/views/gl-sdk4-ui-mudimodem.common.js.gz
persist_www /www/views/gl-sdk4-ui-mudimodem.common.js.gz
gz_install src/views/mudimodem-tracking.js /www/views/gl-sdk4-ui-mudimodem-tracking.common.js.gz
persist_www /www/views/gl-sdk4-ui-mudimodem-tracking.common.js.gz
gz_install src/views/mudimodem-console.js /www/views/gl-sdk4-ui-mudimodem-console.common.js.gz
persist_www /www/views/gl-sdk4-ui-mudimodem-console.common.js.gz
gz_install src/views/mudimodem-speedtest.js /www/views/gl-sdk4-ui-mudimodem-speedtest.common.js.gz
persist_www /www/views/gl-sdk4-ui-mudimodem-speedtest.common.js.gz
# Battery tab is an in-page lazy chunk (no menu JSON) — same pattern as Tracking.
gz_install src/views/mudimodem-battery.js /www/views/gl-sdk4-ui-mudimodem-battery.common.js.gz
persist_www /www/views/gl-sdk4-ui-mudimodem-battery.common.js.gz
gz_install src/at-library.snapshot.json /www/mudimodem/at-library.json.gz
persist_www /www/mudimodem/at-library.json.gz
cp_install src/upgrade/keep.d/mudimodem /lib/upgrade/keep.d/mudimodem 0644
cp_install src/nginx/mudimodem.conf /etc/nginx/gl-conf.d/mudimodem.conf 0644
cp_install src/menu/mudimodem.json /usr/share/oui/menu.d/mudimodem.json 0644
cp_install src/menu/mudimodem-tracking.json /usr/share/oui/menu.d/mudimodem-tracking.json 0644
cp_install src/menu/mudimodem-speedtest.json /usr/share/oui/menu.d/mudimodem-speedtest.json 0644
cp_install version.json /etc/mudimodem/version.json 0644
echo "installing AT channel + library tool:"
cp_install tools/mudimodem-at.py /usr/lib/mudimodem/mudimodem-at.py 0644
cp_install tools/mudimodem-lib /usr/lib/mudimodem/mudimodem-lib 0755
echo "installing speedtest runner + scheduler:"
cp_install tools/mudimodem-speedtest.py /usr/lib/mudimodem/mudimodem-speedtest.py 0755
cp_install src/sbin/mudimodem-speedtestd /usr/sbin/mudimodem-speedtestd 0755
cp_install src/etc/init.d/mudimodem-speedtestd /etc/init.d/mudimodem-speedtestd 0755
# Scheduler is off-by-default in its config; enable the service so a user who
# turns scheduling on later doesn't need a separate enable step (matches deploy).
/etc/init.d/mudimodem-speedtestd enable 2>/dev/null || true
/etc/init.d/mudimodem-speedtestd restart 2>/dev/null || true
echo " speedtest installed + scheduler (re)started"
echo "installing watchdog + validator + backend:"
# Watchdog + validator BEFORE the backend: set_bands needs the watchdog present,
# and the validator must exist before nginx reloads the plugin (§8).
cp_install src/sbin/mudimodem-revert /usr/sbin/mudimodem-revert 0755
cp_install src/sbin/mudimodem-selfupdate /usr/sbin/mudimodem-selfupdate 0755
cp_install src/validator/mudimodem.lua /usr/share/gl-validator.d/mudimodem.lua 0644
cp_install src/rpc/mudimodem /usr/lib/oui-httpd/rpc/mudimodem 0644
# RESTART not reload: nginx caches the plugin per worker; reload leaves stale
# workers serving -32601 for the new methods (§8). ~1s admin blip, no link touch.
/etc/init.d/nginx restart 2>/dev/null || true
echo " nginx restarted"
echo "installing history collector service:"
cp_install src/sbin/mudimodem-collectd /usr/sbin/mudimodem-collectd 0755
cp_install src/etc/init.d/mudimodem-collectd /etc/init.d/mudimodem-collectd 0755
/etc/init.d/mudimodem-collectd enable 2>/dev/null || true
/etc/init.d/mudimodem-collectd restart 2>/dev/null || true
echo " collector enabled + started"
echo "installing battery charge limit:"
# Off first if a previous install's watcher is active — replacing the binary
# under a running watcher is racy.
if [ -x /usr/bin/glbattlimit ]; then
/usr/bin/glbattlimit off 2>/dev/null || true
fi
cp_install src/sbin/glbattlimit /usr/bin/glbattlimit 0755
cp_install src/hotplug/20-glbattlimit /etc/hotplug.d/i2c/20-glbattlimit 0755
cp_install src/etc/init.d/glbattlimit /etc/init.d/glbattlimit 0755
# Default policy only if absent — never clobber user settings on upgrade.
if [ ! -f /etc/mudimodem/battlimit.json ]; then
echo '{"enabled":false,"limit_gui":80}' > /etc/mudimodem/battlimit.json
chmod 0644 /etc/mudimodem/battlimit.json
echo " /etc/mudimodem/battlimit.json (default disabled)"
fi
# History eMMC backup policy — off by default; never clobber user choice.
if [ ! -f /etc/mudimodem/history.json ]; then
echo '{"enabled":false}' > /etc/mudimodem/history.json
chmod 0644 /etc/mudimodem/history.json
echo " /etc/mudimodem/history.json (default disabled)"
fi
/etc/init.d/glbattlimit enable 2>/dev/null || true
# Do NOT start a limit on install (default disabled; start would no-op anyway).
echo " battery charge limit stack installed"
lcd_geom=$(cat /sys/class/graphics/fb0/virtual_size 2>/dev/null || echo "?")
if [ "$lcd_geom" = "240,320" ]; then
echo "installing LCD front-panel renderer (MudiUI):"
cp_install src/lcd/mudi.py /usr/bin/mudi.py 0755
cp_install src/lcd/mudi-watch.py /usr/bin/mudi-watch.py 0755
cp_install src/lcd/mudi.init /etc/init.d/mudi 0755
cp_install src/lcd/mudi-watch.init /etc/init.d/mudi-watch 0755
# default settings only if absent — never clobber user LCD config on upgrade
if [ ! -f /etc/config/mudi ]; then
cp_install src/lcd/mudi.config /etc/config/mudi 0644
fi
# renderer python deps. The list, the --nodeps pillow rule and the libtiff6
# ordering all live in mudimodem-lcddeps, which the init scripts also call to
# self-heal after a firmware upgrade wipes site-packages. Keeping the recipe in
# one place is the point: an install-path/boot-path drift is what silently
# broke the panel after the 4.10 FOTA.
cp_install src/sbin/mudimodem-lcddeps /usr/sbin/mudimodem-lcddeps 0755
/usr/sbin/mudimodem-lcddeps install || true
# DEFAULT OFF: the renderer seizes /dev/fb0 from gl_screen. It is enabled only
# from the admin "LCD Display" tab — do NOT enable or start it here.
echo " LCD renderer installed (disabled by default — enable from the LCD Display tab)"
else
echo " no 240x320 front panel — skipping LCD renderer install"
fi
# Survive a firmware upgrade (our files live outside /etc/config). Idempotent.
echo "registering files in /etc/sysupgrade.conf:"
f=/etc/sysupgrade.conf; touch "$f"
for p in \
/www/views/gl-sdk4-ui-mudimodem.common.js.gz \
/www/views/gl-sdk4-ui-mudimodem-tracking.common.js.gz \
/www/views/gl-sdk4-ui-mudimodem-console.common.js.gz \
/www/views/gl-sdk4-ui-mudimodem-speedtest.common.js.gz \
/www/views/gl-sdk4-ui-mudimodem-battery.common.js.gz \
/www/mudimodem/at-library.json.gz \
/usr/share/oui/menu.d/mudimodem.json \
/usr/share/oui/menu.d/mudimodem-tracking.json \
/usr/share/oui/menu.d/mudimodem-speedtest.json \
/usr/lib/mudimodem/mudimodem-at.py \
/usr/lib/mudimodem/mudimodem-lib \
/usr/lib/mudimodem/mudimodem-speedtest.py \
/usr/sbin/mudimodem-speedtestd \
/etc/init.d/mudimodem-speedtestd \
/usr/sbin/mudimodem-revert \
/usr/sbin/mudimodem-selfupdate \
/usr/sbin/mudimodem-lcddeps \
/usr/share/gl-validator.d/mudimodem.lua \
/usr/lib/oui-httpd/rpc/mudimodem \
/usr/sbin/mudimodem-collectd \
/etc/init.d/mudimodem-collectd \
/etc/mudimodem/version.json \
/usr/bin/glbattlimit \
/etc/hotplug.d/i2c/20-glbattlimit \
/etc/init.d/glbattlimit \
/etc/mudimodem/battlimit.json \
/etc/mudimodem/history.json \
/etc/mudimodem/history \
/usr/bin/mudi.py \
/usr/bin/mudi-watch.py \
/etc/init.d/mudi \
/etc/init.d/mudi-watch \
/lib/upgrade/keep.d/mudimodem \
/etc/nginx/gl-conf.d/mudimodem.conf \
/usr/share/mudimodem \
; do grep -qxF "$p" "$f" || echo "$p" >> "$f"; done
echo " done"
echo ""
echo "MudiModem installed. Reload the GL admin in your browser — a MODEM item"
echo "appears in the top navigation. No reboot needed."