#!/bin/sh
#
# 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

tmpfile=$(mktemp)

lsinitrd $initrd | grep -E "$modules/.*\.ko" > "$tmpfile"

while IFS= read -r 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 < "$tmpfile"
rm "$tmpfile"
unset modules module modconfs modconf

test "$refresh" = yes || exit 0

/sbin/modprobe dm_mod --quiet > /dev/null 2>&1 || true

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

SPLASH=no
case $line in
    *on*) SPLASH=yes;;
esac
test -e /etc/sysconfig/bootsplash && . /etc/sysconfig/bootsplash

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

