#!/bin/bash
#
# Refresh initrd depending on conditions.
# Currently only the change of /etc/sysconfig/clock is
# honoured but we may add more of conditions.
#
# Author: Werner Fink <werner@suse.de>
#
initrd=$(readlink /boot/initrd)
test -n "$initrd" || exit 0
modules=lib/modules/${initrd#initrd-}

refresh=no
test /etc/sysconfig/clock  -nt $initrd && refresh=yes
test /etc/sysconfig/kernel -nt $initrd && refresh=yes

while read module ; do
    module=${module##*/}
    module=${module%.ko}
    modconfs=$(grep -lE "[[:blank:]]$module[[:blank:]]" /etc/modprobe.d/*)
    for modconf in $modconfs; do
	test $modconf -nt $initrd && refresh=yes
	break 2
    done
done < <(lsinitrd /boot/initrd | grep -E "$modules/.*\.ko")
unset modules module modconfs modconf

test "$refresh" = yes || exit 0

modprobe dm_mod --quiet &> /dev/null || true

line=on
test -e /proc/splash && read line < /proc/splash
line=${line##*: }

SPLASH=no
[[ $line =~ on ]] && SPLASH=yes
test -e /etc/sysconfig/bootsplash && . /etc/sysconfig/bootsplash

test $SPLASH = yes && set -- -s auto
exec -a mkinitrd /sbin/mkinitrd ${1+"$@"}
