#!/bin/sh -efu

. sh-functions
. shell-var

BIN_SPLASH=/sbin/splash

[ -x "$BIN_SPLASH" ] &&
	grep -qs '[[:space:]]splash_' "/boot/System.map-$kernel" ||
	exit 0

config="/etc/sysconfig/bootsplash"

[ -s "$config" ] &&
	. "$config" &&
	shell_var_is_yes "${SPLASH:-no}" &&
	[ -n "${THEME-}" ] &&
	fbresolution="$(fbresolution 2>/dev/null)" ||
	exit 0

themefile="/etc/bootsplash/themes/$THEME/config/bootsplash-$fbresolution.cfg"

[ -f "$themefile" ] ||
	exit 0

if ! "$BIN_SPLASH" -f -s "$themefile" > "$rootdir/bootsplash"; then
	rm -rf -- "$rootdir/bootsplash"
	exit 1
fi
