#!/bin/sh /etc/rc.common

START=95
# stopped early at shutdown: the panel's operations log goes to flash then (stop_service)
STOP=05
USE_PROCD=1

start_service() {
	# Complete this short policy step before S99 mu300-post decides whether the
	# device-mode gadget needs its one boot-time rebind. The normal device path
	# performs only local UCI reads; host mode may use a platform power helper.
	/usr/libexec/unisoc-modem/device-usb boot 2>&1 | logger -t unisoc-usb
	procd_open_instance boot-lock-replay
	procd_set_param command /usr/libexec/unisoc-modem/boot-replay
	procd_set_param stdout 1
	procd_set_param stderr 1
	procd_close_instance
}

# "Recent modem operations" (the panel's calls of this boot) to flash before a reboot; between those it is copied
# at most every five minutes, so the last minutes before a crash or a power loss may be missing
stop_service() {
	/usr/libexec/rpcd/mu300dash flush-ops >/dev/null 2>&1 || true
}

service_triggers() {
	procd_add_reload_trigger unisoc_modem
}
