#!/bin/sh
mount -t proc proc /proc >/dev/null 2>&1
export TERM=linux

/usr/bin/clear
if grep -qw quiet /proc/cmdline
then
	/usr/bin/setterm --cursor off
	/usr/bin/ply-image > /dev/null
else
	sleep 2
fi
/sbin/checkmodifier
if [ $? -eq 1 ] || grep -qw recovery /proc/cmdline
then
	export PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/sbin:/usr/sbin"
	trap '' INT
	echo 0 > /proc/sys/kernel/ctrl-alt-del
	for option in $(cat /proc/cmdline); do
	  case $option in
	    osmcdev=*)
	      OPTION_OSMCDEV="${option#*=}"
	      ;;
	  esac
	done
	case $OPTION_OSMCDEV in
	  vero2|vero3)
	    /usr/bin/clear
	    ;;
	  *)
	    fbset -depth 8 && fbset -depth 16
	    ;;
	esac
	/usr/bin/setterm --cursor on
	/bin/mount / -o remount,rw
	/bin/mount /boot 2>/dev/null
	/bin/mount -t sysfs sysfs /sys >/dev/null 2>&1
	/bin/mkdir /dev/pts
	/bin/mount -t devpts devpts /dev/pts
	/bin/hostname -F /etc/hostname
	/bin/echo -e "\n\n\n\n"
	echo "          OSMC Recovery Console."
	echo "          Type 'exit' to reboot when finished."
	echo "          For help and support see http://osmc.tv/help"
	echo
	/usr/bin/setsid -c /bin/bash
	/bin/sync
	echo 1 > /proc/sys/kernel/sysrq
	echo b > /proc/sysrq-trigger
else
	exec /sbin/init $*
fi
