#!/bin/sh /etc/rc.common
# adb over USB: adbd in the USB gadget unless "mu300-usb adb off" (/etc/mu300/adb; on by default). Every computer
# gets a root shell without a key ("mu300-usb adb auth open", the default), or only the keys in /etc/mu300/adb_keys
# ("adb auth keys"). See /opt/mu300/bin/mu300-adbd.
# Early (S19, with the network): adding adb rebinds the gadget, which the computer sees as a replug.
START=19
STOP=89
USE_PROCD=1
export PATH="$PATH:/opt/mu300/busybox-bin"

start_service() {
	[ -x /opt/mu300/bin/adbd ] || return 0
	[ "$(cat /etc/mu300/adb 2>/dev/null)" != off ] || return 0
	procd_open_instance adbd
	procd_set_param command /opt/mu300/bin/mu300-adbd run
	# the TERM of a stop goes to the loop, which takes adb out of the gadget and binds it again
	procd_set_param term_timeout 20
	procd_set_param stdout 1
	procd_set_param stderr 1
	procd_close_instance
}
