lilo_image_entry()  {

  cat  <<  EOF

image			=	/boot/vmlinubz-$VERSION
	label		=	linux-$VERSION
	read-only
	restricted

EOF

}

grub_image_entry()  {

. $DEPENDS_CONFIG/grub

  cat  <<  EOF

title   linux-$VERSION
kernel  $GRUB_BOOT/vmlinubz-$VERSION
root    $GRUB_ROOT

EOF

}


update_lilo()  {
  if  !  grep  -q  "$VERSION"  /etc/lilo.conf;  then

    IFS_OLD=$IFS
    export  IFS="
"

    rm  -rf  /etc/lilo.conf.new
    cp  /etc/lilo.conf  /etc/lilo.conf.old

    (( IMAGE_COUNT=0  ))

    for  LINE  in  `cat /etc/lilo.conf`;  do

      if   echo  $LINE  |  grep  -q  "image"  ||
           echo  $LINE  |  grep  -q  "other"  ;  then
        if  (( IMAGE_COUNT  == 0  ));  then
          echo  -e  "`lilo_image_entry`"  >>  /etc/lilo.conf.new
        fi
        ((  IMAGE_COUNT++  ))
      fi

      if  ((  IMAGE_COUNT == 14  ));  then
        break
      fi
    
      echo  $LINE  >>  /etc/lilo.conf.new

    done

    if  ((  IMAGE_COUNT ==  0  ));  then
      echo  -e  "`lilo_image_entry`"  >>  /etc/lilo.conf.new
    fi

    cp  /etc/lilo.conf.new  /etc/lilo.conf

    export  IFS=$IFS_OLD

  fi

  case  $CONFIG_LILO in
    y|Y|j|J)  ${EDITOR:-nano}  /etc/lilo.conf  ;;
  esac

  /sbin/lilo

}


update_grub()  {
  if  !  grep  -q  "$VERSION"  /boot/grub/menu.lst;  then

    IFS_OLD=$IFS
    export  IFS="
"

    rm  -rf  /boot/grub/menu.lst.new
    cp  /boot/grub/menu.lst  /boot/grub/menu.lst.old

    (( IMAGE_COUNT=0  ))

    for  LINE  in  `cat /boot/grub/menu.lst`;  do

      if   echo  $LINE  |  grep  -q  "title";  then
        if  (( IMAGE_COUNT  == 0  ));  then
          echo  -e  "`grub_image_entry`"  >>  /boot/grub/menu.lst.new
        fi
        ((  IMAGE_COUNT++  ))
      fi

      if  ((  IMAGE_COUNT == 14  ));  then
        break
      fi
    
      echo  $LINE  >>  /boot/grub/menu.lst.new

    done

    if  ((  IMAGE_COUNT ==  0  ));  then
      echo  -e  "`grub_image_entry`"  >>  /boot/grub/menu.lst.new
    fi

    cp  /boot/grub/menu.lst.new  /boot/grub/menu.lst

    export  IFS=$IFS_OLD

  fi

  case  $CONFIG_GRUB in

    y|Y)  if [ -n "$EDITOR" ];             then
            $EDITOR  /boot/grub/menu.lst;  else
            nano     /boot/grub/menu.lst
          fi
          ;;
  esac

  message "Install GRUB into MBR of first drive? [y|Y]"
  read GRUB_FIRST_DRIVE
  case $GRUB_FIRST_DRIVE in
    y|Y) GRUB_BOOT_DEVICE="(hd0)" ;; 
    *  ) 
         message "Otherwise please specify in GRUB notation the desired drive/partition"
         message "Using parenthesis and NO spaces!"
         message "Samples: (hd1)    2nd drive MBR"
         message "         (hd1,0)  2nd drive with 1st partition"
         message "         (hd0,2)  1st drive with 3rd partition"
         echo -n "GRUB_BOOT_DEVICE=(hd#,#):  "
         read GRUB_BOOT_DEVICE
  esac
  
  /usr/sbin/grub-install "$GRUB_BOOT_DEVICE"
  sleep 4

}

update_aboot() {
  case  $CONFIG_ABOOT in

    y|Y)  if [ -n "$EDITOR" ];             then
            $EDITOR  /etc/aboot.conf;  else
            nano     /etc/aboot.conf
          fi
          ;;
  esac
}

case  $BOOT_LOADER  in
  lilo)  [ $CONFIG_LILO = y ] && update_lilo  ;;
  grub)  [ $CONFIG_GRUB = y ] && update_grub  ;;
  aboot) [ $CONFIG_ABOOT = y ] && update_aboot ;;
esac


#  Reinstall packages that add their own kernel modules

rm  -f  $BOOST_LOCK
if  module_installed  ftpfs;          then  lin  ftpfs;          fi
if  module_installed  cvsfs;          then  lin  cvsfs;          fi
if  module_installed  NVIDIA_kernel;  then  lin  NVIDIA_kernel;  fi
if  module_installed  alsa-driver;    then  lin  alsa-driver;    fi
if  module_installed  cryptoapi;      then  lin  cryptoapi;      fi
if  module_installed  pcmcia-cs;      then  lin -r -c pcmcia-cs; fi
if  module_installed  mwavem;         then  lin  mwavem;         fi
if  module_installed  cipe;           then  lin  cipe;           fi
if  module_installed  snare-core;     then  lin  snare-core;     fi
if  module_installed  ltmodem;        then  lin  ltmodem;        fi
