#!/bin/bash
if [ $# -lt 2 ]; then
echo "not enough arguments: $0 $*" >&2
exit 1
fi
printf "$0\n"
printf "$1\n"
printf "$2\n"
printf "$3\n"
printf "$4\n"
printf "$5\n"
printf "$6\n"
printf "1\n"
type="$1"
shift
action="$1"
shift
# allow for debugging
run ()
{
#echo "$@"
"$@"
return $?
}
bootPrefix ()
{
case $1 in
*ia64)
echo "/boot/efi/EFI/linux/"
;;
*)
echo "/boot/"
;;
esac
}
run_grubby ()
{
version=$2
pre=$3
initrd=$4
# default to LILO if lilo is installed:
bootloaders=`/sbin/grubby --bootloader-probe`
if echo $bootloaders | grep lilo >& /dev/null; then
bootloader="--lilo"
# LILO won't accept a title longer than 15 characters, so let's just use the version:
title=$(echo "$version" | cut -b -14)
else
bootloader="--grub"
if [ -f /etc/distro-release ] ; then
title="$(cat /etc/distro-release) (${version})"
else
title="$version"
fi
fi
case $1 in
--add)
# first non-commented / entry is the one we want...
rootdev=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/")
{ print $1; exit}
}' /etc/fstab)
label=${rootdev/*=/}
if [ "$label" != "$rootdev" ] ; then
# if nash can find the label, then root=LABEL=/ is OK
# and the root filesystem will be found at boot time
if [ -z $(echo showlabels | /sbin/nash --force --quiet | awk '$2 == "'$label'" {print $1; exit}') ] ; then
# nash couldn't find it, so we have to dig it out
# of the current mount table and use that instead
# of the literal label. Oh, well.
rootdev=$(mount | awk '$3 == "/" {print $1 ; exit}')
fi
fi
# XXX bootargs= for stuff like lilo arguments
# --title="$title" --copy-default --make-default \
run /sbin/grubby $bootloader --add-kernel=${pre}vmlinuz-$version \
--initrd=$initrd \
--title="$title" --make-default \
--args="root=$rootdev" \
--remove-kernel="${pre}vmlinuz-$version" \
$bootargs
;;
--del)
# XXX bootargs= for stuff like lilo arguments
run /sbin/grubby $bootloader --remove-kernel=${pre}vmlinuz-$version $bootargs
;;
esac
}
case $type in
files)
# pick version list from stdin
versionlist=$(sed 's,^/lib/modules/\([^/]*\)/.*,\1,g
s,^/boot/vmlinuz-,,g' | sort -u)
case $action in
update)
printf "2\n"
for version in $versionlist; do
printf "$version\n"
printf "2\n"
pre=$(bootPrefix $version)
if [ -d /lib/modules/$version ] ; then
printf "$pre\n"
printf "3\n"
run /sbin/depmod -ae -F "/boot/System.map-$version" "$version"
initrd=${pre}initrd-${version}.img
if run /sbin/mkinitrd -f $initrd $version ; then
run_grubby --add $version $pre $initrd
/sbin/splash -s -f /usr/share/bootsplash/themes/FDL/config/bootsplash-1024x768.cfg >> $initrd
printf "$initrd\n"
printf "4\n"
fi
else
# no modules, no initrd
run_grubby --add $version $pre ""
printf "5\n"
fi
done
;;
preremove)
/sbin/modprobe loop >& /dev/null
for version in $versionlist; do
pre=$(bootPrefix $version)
if [ -d /lib/modules/$version ] ; then
run rm -f /lib/modules/$version/modules.*
fi
initrd=${pre}initrd-${version}.img
if [ -f $initrd ] ; then
run rm -f ${pre}initrd-${version}.img
fi
run_grubby --del $version $pre ""
done
;;
esac
;;
esac
exit 0