#!/bin/sh

rescue()
{
	printf "This is the PID 1 rescue shell.\n"
	printf "Manually \\e[94m/bin/mount\\e[0m a new rootfs and exec \\e[94m/sbin/switch_root\\e[0m to it.\n"
	printf "OR exec \\e[94m/sbin/init\\e[0m to start \\e[94m/etc/inittab\\e[0m to reboot or poweroff.\n"

	# Set flag which indicates that we have obtained controlling terminal.
	export PID1_SHELL=true

	# Interactive shell with controlling tty as PID 1.
	exec setsid cttyhack sh
}

echo -e "PKGLINUX \\e[94mbusyboxfs\\e[0m has started (SHELL @ PID 1) ..."

mount -n -t devtmpfs devtmpfs /dev
mount -n -t proc     proc     /proc
mount -n -t sysfs    sysfs    /sys
mount -n -t tmpfs    tmpfs    /run
mount -n -t tmpfs    tmpfs    /tmp

rescue

# Wait until any key has been pressed.
read -n1 -s
