Files
mu300-linux/tools/linux-mode.sh
T
Abdurrahman Kaan DikeçandClaude Opus 5 a36ca4e897 linux-mode: ask for the device password on a terminal, or sudo silently fails
ssh without -t gave sudo no terminal, so "sudo mu300-next-boot android" failed, the fallback without sudo failed
too and the device never rebooted - the script then waited for an Android that never came. Now one sudo call runs
the whole sequence over "ssh -t", the full path to mu300-next-boot is used (it is not in a non-interactive PATH on
OpenWrt), and since the reboot cuts the connection the SSH port is watched instead of trusting ssh's exit status.
A failed attempt now says what to run on the device instead of hanging.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017Z17MBkdHmZPvNPNSLxcHk
2026-09-17 23:10:56 +03:00

50 lines
2.4 KiB
Bash

# Shared by install.sh and uninstall.sh: both need the device in rooted Android, but it may be running MU300 Linux
# right now (then there is no adb device, only SSH on the USB network). Offer to send it back to Android.
# Uses: say(), die(), ask()
MU300_IP=${MU300_IP:-192.168.77.1}
# true when something answers on the Linux SSH port of the USB network
linux_mode_running() {
command -v nc >/dev/null || return 1
nc -z -G 3 -w 3 "$MU300_IP" 22 >/dev/null 2>&1
}
# ask the running Linux to boot Android next and reboot; then wait for adb
linux_mode_to_android() {
say "The device is running MU300 Linux, not Android"
echo " Installing and uninstalling happen from Android (slot a), so the device has to reboot first."
ask go "Reboot the device into Android now? (yes/no)" yes
[ "$go" = yes ] || die "boot Android yourself (on the device: sudo mu300-next-boot android && sudo reboot)"
# -t: sudo needs a terminal to ask for the device password, and everything runs in one sudo call so it is
# asked only once. reboot cuts the connection, so ssh's exit status says nothing: watch the port instead.
for user in ubuntu root; do
echo " $user@$MU300_IP - enter the device password when asked (Ctrl-C to skip)"
ssh -t -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR -o ConnectTimeout=8 \
"$user@$MU300_IP" 'if [ "$(id -u)" = 0 ]; then S=; else S=sudo; fi; $S sh -c "/opt/mu300/bin/mu300-next-boot android && sync && reboot"' || true
n=0
while [ $n -lt 8 ]; do
linux_mode_running || { echo " rebooting"; break; }
n=$((n + 1)); sleep 5
done
linux_mode_running || break
done
if linux_mode_running; then
die "could not reboot it over SSH; on the device run: sudo mu300-next-boot android && sudo reboot"
fi
echo " waiting for Android"
n=0
while [ $n -lt 60 ]; do
[ "$(adb get-state 2>/dev/null)" = device ] && { echo " Android is up"; return 0; }
n=$((n + 1)); sleep 5
done
die "the device did not come back as Android; boot it yourself (mu300-next-boot android)"
}
# call before anything else that needs adb
require_android() {
[ "$(adb get-state 2>/dev/null)" = device ] && return 0
linux_mode_running && linux_mode_to_android && return 0
die "no adb device (boot Android, enable USB debugging)"
}