#!/bin/sh /etc/rc.common
# Copyright (C) 2006 OpenWrt.org

START=95
REBOOT_FILE_PATH="/log/reboot"

add_event() {
	ubus call log write_ext "{
			\"event\":\"$1\",
			\"sender\":\"Startup\",
			\"table\":1,
			${2:+\"priority\":$2,}
			\"write_db\":1
		}"
}

add_startup_event() {
	if [ -f "$REBOOT_FILE_PATH" ]; then
		#Some applications need an indication that the device has rebooted.
		#move the file to a temporary location instead of deleting it
		mv "$REBOOT_FILE_PATH" /tmp/reboot
	else
		add_event "Device startup after unexpected shutdown"
	fi

	add_event "Device startup completed" 5
}

boot() {
	mount_root done
	rm -f /sysupgrade.tgz && sync

	# process user commands
	[ -f /etc/rc.local ] && {
		sh /etc/rc.local
	}

	add_startup_event
}
