#!/bin/sh
#
# Copyright (c) 2021, The Linux Foundation. All rights reserved.
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.


mkdir -p /proc && mount -t proc none /proc
mkdir -p /sys && mount -t sysfs none /sys
mount -t debugfs none /sys/kernel/debug/
udevd --daemon
udevadm trigger

# load modules
for m in /lib/modules/$(uname -r)/*; do
	modprobe $(basename $m .ko)
done

# setup udhcpc client scropt
[ ! -f /usr/share/udhcpc/default.script ] && {
	mkdir -p /usr/share/udhcpc
	echo "#!/bin/sh" > /usr/share/udhcpc/default.script
	echo "ifconfig \$interface \$ip" >> /usr/share/udhcpc/default.script
	chmod +x /usr/share/udhcpc/default.script
}

# setup default root password
[ ! -f /etc/password ] && {
	echo root:x:0:0:root:/root:/bin/ash > /etc/passwd
}

watchdog -t 5 -T 10 /dev/watchdog
