Stock layout, Tuya daemons disabled, telnetd + serial root shell, Wi-Fi auto-join and a bind-mount overlay so any file can be made writable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
98 lines
3.4 KiB
Bash
Executable File
98 lines
3.4 KiB
Bash
Executable File
#!/bin/sh
|
|
# Build a "telnet + wifi + writable-overlay" image from the stock parts.
|
|
# - keeps stock uboot/env/dtb/kernel/rootfs/config
|
|
# - rebuilds APP squashfs with: local_bootstrap (wifi station + telnet + serial
|
|
# root shell) and a jffs2-backed bind-mount overlay so you can edit any file.
|
|
set -e
|
|
HERE="$(cd "$(dirname "$0")/.." && pwd)"
|
|
[ "${WIFI_SSID+set}" = set ] || { echo "set WIFI_SSID=... WIFI_PSK=..."; exit 1; }
|
|
WIFI_PSK=${WIFI_PSK-}
|
|
SET=$HERE/parts/telnet
|
|
WORK=$(mktemp -d)
|
|
trap 'rm -rf "$WORK"' EXIT
|
|
|
|
mkdir -p "$SET"
|
|
# raw + unchanged fs parts straight from stock
|
|
for f in uboot env envbk dtb kernel rootfs config; do cp -a "$HERE/parts/stock/$f.bin" "$SET/"; done
|
|
|
|
# patched APP tree
|
|
"$HERE/extract-src.sh"
|
|
cp -a "$HERE/src/app" "$WORK/app"
|
|
|
|
# 1) local bootstrap: overlay -> wifi -> dhcp -> telnet + serial shell
|
|
cat > "$WORK/app/sbin/local_bootstrap.sh" <<'EOS'
|
|
#!/bin/sh
|
|
PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin
|
|
exec >/tmp/local_bootstrap.log 2>&1
|
|
echo "[local] start $(date)"
|
|
|
|
# --- writable overlay: bind-mount every file under /etc/config/overlay over its
|
|
# real path (lets you replace/edit any existing file, persistently on CONFIG) ---
|
|
OV=/etc/config/overlay
|
|
if [ -d "$OV" ]; then
|
|
find "$OV" -type f 2>/dev/null | while read f; do
|
|
tgt=${f#$OV}
|
|
[ -e "$tgt" ] && mount -o bind "$f" "$tgt" && echo "[ovl] bind $tgt"
|
|
done
|
|
# whole-dir overlays: a dir named .DIR marks "bind this dir rw over target"
|
|
find "$OV" -type d -name '.rwdir' 2>/dev/null | while read d; do
|
|
tgt=$(dirname "${d#$OV}")
|
|
mount -o bind "$(dirname "$d")" "$tgt" && echo "[ovl] bind-dir $tgt"
|
|
done
|
|
fi
|
|
|
|
# persistent serial root shell on the console
|
|
(setsid /bin/sh </dev/ttySAK0 >/dev/ttySAK0 2>&1) &
|
|
|
|
# wifi station
|
|
insmod /usr/modules/cfg80211.ko 2>/dev/null
|
|
/usr/sbin/wifi_driver.sh sta
|
|
sleep 2
|
|
CONF=/etc/config/wpa_supplicant.conf
|
|
if [ ! -f "$CONF" ]; then
|
|
CONF=/tmp/wpa_supplicant.conf
|
|
cat > "$CONF" <<WPA
|
|
ctrl_interface=/var/run/wpa_supplicant
|
|
update_config=1
|
|
network={
|
|
scan_ssid=1
|
|
ssid="__WIFI_SSID__"
|
|
psk="__WIFI_PSK__"
|
|
}
|
|
WPA
|
|
fi
|
|
wpa_supplicant -B -iwlan0 -Dnl80211 -c "$CONF"
|
|
i=0; while [ $i -lt 30 ]; do
|
|
[ "$(wpa_cli -iwlan0 status 2>/dev/null | sed -n 's/^wpa_state=//p')" = "COMPLETED" ] && break
|
|
sleep 1; i=$((i+1)); done
|
|
echo "[local] wpa_state=$(wpa_cli -iwlan0 status 2>/dev/null|sed -n 's/^wpa_state=//p') after ${i}s"
|
|
udhcpc -i wlan0 -b
|
|
ifconfig wlan0
|
|
telnetd -l /bin/sh
|
|
echo "[local] ready: telnet on :23 (no password)"
|
|
EOS
|
|
chmod 0755 "$WORK/app/sbin/local_bootstrap.sh"
|
|
sed -i "s/__WIFI_SSID__/$WIFI_SSID/; s/__WIFI_PSK__/$WIFI_PSK/" "$WORK/app/sbin/local_bootstrap.sh"
|
|
|
|
# 2) on-device helper: make any file writable (copy into overlay + bind now)
|
|
cat > "$WORK/app/sbin/rw" <<'EOS'
|
|
#!/bin/sh
|
|
# usage: rw /path/to/file -> makes that file editable & persistent
|
|
f=$1; OV=/etc/config/overlay
|
|
[ -z "$f" ] && { echo "usage: rw /abs/path/file"; exit 1; }
|
|
mkdir -p "$OV$(dirname "$f")"
|
|
[ -e "$OV$f" ] || cp -a "$f" "$OV$f"
|
|
mount -o bind "$OV$f" "$f" 2>/dev/null
|
|
echo "editable now (persists on reboot): $f (backing: $OV$f)"
|
|
EOS
|
|
chmod 0755 "$WORK/app/sbin/rw"
|
|
|
|
# 3) start our bootstrap instead of the Tuya service stack
|
|
sed -i 's#^service.sh start &#/usr/sbin/local_bootstrap.sh \&#' "$WORK/app/sbin/main.sh"
|
|
|
|
# repack APP into the telnet parts set (slot = 0x500000)
|
|
"$HERE/repack-fs.sh" "$WORK/app" "$SET/app.bin" $((0x500000)) squashfs
|
|
|
|
# assemble
|
|
"$HERE/build-image.sh" "$SET" "$HERE/out/camera_flash_telnet.bin"
|