#!/bin/sh

#
# Standard initramfs preamble
#
prereqs()
{
	return 0
}









case $1 in
	prereqs)
		prereqs
		exit 0
		;;
esac


#
# Helper functions
#
debug_shell() {
	[ "$cryptdebug" = "true" ] && [ -f /conf/conf.d/remoteunlock_allow_debug ] && /bin/sh
}

parse_options() {
	local cryptopts
	cryptopts="$1"

	if [ -z "$cryptopts" ]; then
		return 1
	fi

	local IFS=" ,"
	for x in $cryptopts
	do
		case $x in
			debug=*)
				cryptdebug=${x#debug=}
				;;
			ip=*)
				cryptip=${x#ip=}
				;;
			route=*)
				cryptroute=${x#ip=}
				;;
		esac
	done
	return 0
}




#check boot cmdline for cryptopts and parse'em to look if we're meant to run...
for opt in $(cat /proc/cmdline)
do
	case $opt in
		cryptopts=*)
			parse_options "${opt#cryptopts=}"
			;;
	esac
done

if [ -n "$cryptip" ]
then
	debug_shell

	umount /dev/pts
	killall sshd

	debug_shell
fi

exit 0
