Files
lotherkandClaude Sonnet 5.5 73c9de51a6 licence: the CNCL line in every file Makronix wrote (tools, docs, www, mobile, top level)
consmirror.c: the BSD notice is replaced (Makronix's own file).  Files with
changes of other sessions pending are left for their commit.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-14 11:50:26 +00:00

52 lines
1.9 KiB
Bash

#!/bin/sh
# License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
#
# Reboot the phone N times and run CHECK (a file of POSIX sh, fed to sh on
# the phone) in each boot once its uptime has reached WAIT_UP seconds (default 45);
# one line per boot, "run I: <CHECK's output>", to LOG. Every step finds
# the phone anew (phone_addr: its IPv4 address, else its IPv6 link-local
# one -- the host's USB address comes and goes with the gadget) and every
# wait has a limit, so a boot that does not come back ends the loop
# instead of hanging it. tools/display-loop.sh is the same with a camera.
#
# Usage: boot-loop.sh N LOG CHECKFILE
set -u
. "$(dirname "$0")/lib.sh"
[ $# -eq 3 ] || { echo "usage: $0 N LOG CHECKFILE" >&2; exit 2; }
[ -r "$3" ] || die "no $3"
n=$1 log=$2 check=$3
up=${WAIT_UP:-45}
wait_phone() { # wait_phone SECONDS: the address, once it answers
_t=0
while [ "$_t" -lt "$1" ]; do
_a=$(phone_addr 2>/dev/null) && { echo "$_a"; return 0; }
sleep 3; _t=$((_t + 3))
done
return 1
}
i=1
while [ "$i" -le "$n" ]; do
a=$(wait_phone 60) || { echo "run $i: phone not reachable before the reboot" | tee -a "$log"; exit 1; }
old=$(phone_ssh "$a" 'cut -d. -f1 /proc/uptime' 2>/dev/null)
timeout 20 sh -c ". '$(dirname "$0")/lib.sh'; phone_ssh '$a' 'sync; reboot'" >/dev/null 2>&1
sleep 20
a=$(wait_phone 180) || { echo "run $i: NOT REACHABLE after the reboot" | tee -a "$log"; exit 1; }
now=$(phone_ssh "$a" 'cut -d. -f1 /proc/uptime' 2>/dev/null)
if [ -n "$old" ] && [ -n "$now" ] && [ "$now" -ge "$old" ]; then
echo "run $i: did not reboot (uptime $now s)" | tee -a "$log"
continue
fi
t=0
while [ "$t" -lt 180 ]; do
a=$(phone_addr 2>/dev/null) &&
phone_ssh "$a" "[ \$(cut -d. -f1 /proc/uptime) -ge $up ]" 2>/dev/null && break
sleep 3; t=$((t + 3))
done
echo "run $i: $(timeout 60 sh -c ". '$(dirname "$0")/lib.sh'; phone_ssh '$a' 'sh -s'" < "$check" 2>&1 | tr '\n' ' ')" | tee -a "$log"
i=$((i + 1))
done