# Usplash hooks for /lib/init/splash-functions-base

# Internal function, do not use in external scripts
usplash_pidfound()
{
	pidof usplash > /dev/null 2>&1 || return 1
	return 0
}

splash_running()
{
	status usplash | grep -q start/running
}

splash_stop()
{
	# We don't want to stop usplash when shutting down the machine.
	case $RUNLEVEL in
		0|6) 
		    /sbin/usplash_write FADEOUT
		    return 0 ;;
	esac
	stop usplash || return 1
	return 0
}

splash_start()
{
	start usplash || return 1
	return 0
}

custom_splash_progress()
{
	splash_running || return 0
	/sbin/usplash_write "PROGRESS $1" || return 1
	return 0
}

splash_start_indefinite()
{
	splash_running || return 0
	# TIMOUT 0 is not indefinite
	/sbin/usplash_write "TIMEOUT 600" || return 1
	/sbin/usplash_write "PULSATE" || return 1
	return 0
}

splash_stop_indefinite()
{
	splash_running || return 0
	/sbin/usplash_write "TIMEOUT 15" || return 1
	return 0
}

splash_user_input()
{
	splash_running || return 1
	[ -p /dev/.initramfs/usplash_outfifo ] || return 1

	case "$2" in
		regular)
		/sbin/usplash_write "INPUT $1" || return 1
		;;
		password)
		/sbin/usplash_write "INPUTQUIET $1" || return 1
		;;
		enter)
		/sbin/usplash_write "INPUTENTER $1" || return 1
		;;
		*)
		return 1
		;;
	esac
	cat /dev/.initramfs/usplash_outfifo 2> /dev/null || return 1
	return 0
}

# This isn't unlinked when usplash shuts down, so it indicates that usplash
# was started at boot time.
if [ -p /dev/.initramfs/usplash_fifo ]; then
	export CONSOLE=/dev/tty8
fi
