#!

#
# This is a dummy version of new-kernel-pkg which is just smart enough
# to handle the existing kernel spec files
#

MODE=
while [ $# -gt 1 ] ; do
	case $1 in
	--remove)	MODE=remove;;
	--install)	MODE=install;;
	esac
	shift
done
VER=$1
LOG=/tmp/new-kern-pkg.$RANDOM

if [ $# -lt 1 ] ; then
	echo "new-kernel-pkg: kernel version must be specified" 1>&2
	echo "new-kernel-pkg: kernel version must be specified" >$LOG
	exit 1
fi

if [ -z "$MODE" ] ; then
	echo "new-kernel-pkg: Either --install or --remove must be specified" 1>&2
	echo "new-kernel-pkg: Either --install or --remove must be specified" >$LOG
	exit 1
fi

if [ "$MODE" == "remove" ] ; then
   echo "REMOVE" >$LOG
   echo "rm -f /boot/*$VER*" >>$LOG
         rm -f /boot/*$VER* &>>$LOG
   echo "grub2-mkconfig -o /boot/grub2/grub.cfg" >>$LOG
         grub2-mkconfig -o /boot/grub2/grub.cfg &>>$LOG

elif [ "$MODE" == "install" ] ; then
   echo "INSTALL" >$LOG

   DEPMOD=${DEPMOD=/sbin/depmod}
   SYSMAP=/boot/System.map-$VER
   if [ -x $DEPMOD ] ; then
      if [ -f $SYSMAP ] ; then
         echo "$DEPMOD -ae -F $SYSMAP $VER" >>$LOG
               $DEPMOD -ae -F $SYSMAP $VER &>>$LOG
      else
         echo "$DEPMOD -a $VER" >>$LOG
               $DEPMOD -a $VER &>>$LOG
      fi
   fi
   mount -t proc proc /proc 2>/dev/null || :
   mount -t sysfs sysfs /sysfs 2>/dev/null || :
   echo "/sbin/mkinitrd --force --version $VER --output /boot/initrd-$VER.img" >>$LOG
         /sbin/mkinitrd --force --version $VER --output /boot/initrd-$VER.img &>>$LOG
   sleep 1
   echo "/sbin/grub2-mkconfig -o /boot/grub2/grub.cfg" >>$LOG
         /sbin/grub2-mkconfig -o /boot/grub2/grub.cfg &>>$LOG
   sleep 1
else
   echo "ERROR: Bad mode given: $MODE" 1>&2
   echo "ERROR: Bad mode given: $MODE" >$LOG
   exit 1
fi

