#!/bin/bash

# AutoRPM trigger script for kernel RPM
# To enabled, put this command in your action(updated){} block:
#    Trigger("kernel", "/path/to/script/kernel");

# DO NOT USE THIS SCRIPT UNLESS YOU ARE ABSOLUTELY SURE IT WON'T HOSE
# YOUR SYSTEM.  I ONLY WROTE IT FOR ONE SPECIFIC SITUATION.

newpkg="$1"  # such as "kernel-2.4.9-6"
action="$2"  # INSTALLED, UPGRADED, or FAILED
oldpkg="$3"  # such as "kernel-2.4.9-6"

# Ignore failures
[ "$action" == "FAILED" ] && exit 0

newkernel=`rpm -ql "$newpkg" | grep '^/boot/vmlinuz'`

echo -n "         Activating new kernel: $newkernel... "

if sed "s!^image=.*!image=$newkernel!" /etc/lilo.conf > /etc/lilo.conf.new ; then
   if cp /etc/lilo.conf.new /etc/lilo.conf ; then
      rm -f /etc/lilo.conf.new
   else
      echo "ERROR: Failed to replace /etc/lilo.conf for new kernel!!" >&2
      exit 1
   fi
else
   echo "ERROR: Failed to modify /etc/lilo.conf for new kernel!!" >&2
   exit 1
fi

lilo >/dev/null || {
   echo "ERROR: Execution of LILO failed after new kernel installation!" >&2
   exit 1
}

echo "Done."
exit 0

