CVS: lunar/var/lib/lunar/functions kernel.lunar,NONE,1.1

elaine at lunar-linux.org elaine at lunar-linux.org
Thu Oct 9 15:57:39 GMT 2003


Update of /var/cvs/lunar/lunar/var/lib/lunar/functions
In directory dbguin.lunar-linux.org:/tmp/cvs-serv22868

Added Files:
	kernel.lunar 
Log Message:
Adding kernel backup and boot conifig functions to lunar


--- NEW FILE: kernel.lunar ---
#!/bin/bash
#                                                          #
# subroutines - Lunar subroutines                          #
#                                                          #
# Copyright Kyle Sallee 2000, 2001                         #
#                                                          #
############################################################
#                                                          #
# kernel.lunar functions for managing kernel installation  #
# and bootloaders                                          #
#                                                          #
############################################################
#                                                          #
# Parts Copyright Terry Chan 2002 GPLv2                    #
# Parts Copyrighted Niki Guldbrand 2003 under GPLv2        #
# Parts Copyright FW Systems llc 2003 GPLv2                #
#                                                          #
############################################################

#
# Description : This function makes backups of the kernels and the kernel
#               module dirs.
# Name        : backup_mods_krnl
# Arg 1       : Filename of the kernel to backup (With or witout full path)
#               With the format $VERSION_$EXTRAVERSION
backup_mods_krnl()
{
  debug_msg "backup_mods_krnl ($@)"

  devoke_installwatch  

  BKUP_KRNL=$1

  if [ -f /boot/${BKUP_KRNL}.old ]; then
    verbose_msg "moving old kernel backup"
    mv -f /boot/${BKUP_KRNL}.old /boot/${BKUP_KRNL}.old_2
  fi

  if [ -f /boot/${BKUP_KRNL} ]; then
    verbose_msg "copying ${BKUP_KRNL}"
    cp -p /boot/${BKUP_KRNL} /boot/${BKUP_KRNL}.old
  fi

  if [ -d /lib/modules/${BKUP_KRNL} ]; then
    rm -rf /lib/modules/${BKUP_KRNL}.old
    cp -a /lib/modules/${BKUP_KRNL} /lib/modules/${BKUP_KRNL}.old
  fi

  invoke_installwatch 

}


# function update_lilo
# Description: creates /etc/lilo.conf stanzas
# usage: update_lilo bootimagename menuname
#

update_lilo()  {

debug_msg "update_lilo ($@)"

IMAGE_NAME=$1
BOOT_LABEL=$2

LILO_IMAGE_ENTRY="
image                   =       /boot/$IMAGE_NAME 
        label           =       $BOOT_LABEL 
        read-only
"

LILO_OLD_IMAGE_ENTRY="
image                   =       /boot/$IMAGE_NAME.old
        label           =       $BOOT_LABEL.old
        read-only 
"

  if  ! ( grep  -q  "$IMAGE_NAME"  /etc/lilo.conf   && 
          grep  -q  "$IMAGE_NAME.old" /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
          if  !  grep  -q  "$IMAGE_NAME"  /etc/lilo.conf;  then
            echo  -e  "$LILO_IMAGE_ENTRY"  >>  /etc/lilo.conf.new
          fi
          if  [ -f /boot/"$IMAGE_NAME.old" ] && 
              !  grep  -q  "$IMAGE_NAME.old"  /etc/lilo.conf ;  then
            echo  -e  "$LILO_OLD_IMAGE_ENTRY"  >>  /etc/lilo.conf.new
          fi
        fi
        ((  IMAGE_COUNT++  ))
      fi

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

    done

    if  ((  IMAGE_COUNT ==  0  ));  then
      if  !  grep  -q  "$IMAGE_NAME"  /etc/lilo.conf;  then
        echo  -e  "$LILO_IMAGE_ENTRY"  >>  /etc/lilo.conf.new
      fi
      if  [ -f /boot/"$IMAGE_NAME.old" ] && 
          !  grep  -q  "$IMAGE_NAME.old"  /etc/lilo.conf ;  then
        echo  -e  "$LILO_OLD_IMAGE_ENTRY"  >>  /etc/lilo.conf.new
      fi
    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

}

# function update_grub
# Description: creates /etc/lilo.conf stanzas
# usage: update_grub bootimagename menuname
#

update_grub()  {

debug_msg "update_grub ($@)"

IMAGE_NAME=$1
BOOT_LABEL=$2

. $DEPENDS_CONFIG/grub

GRUB_IMAGE_ENTRY="
title   $BOOT_LABEL
kernel  $GRUB_BOOT/$IMAGE_NAME
root    $GRUB_ROOT
"

GRUB_OLD_IMAGE_ENTRY="
title   $BOOT_LABEL.old
kernel  $GRUB_BOOT/$IMAGE_NAME.old
root    $GRUB_ROOT
"

if  ! ( grep  -q  "$IMAGE_NAME"     /boot/grub/menu.lst && 
        grep  -q  "$IMAGE_NAME.old" /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
          if  !  grep  -q  "$IMAGE_NAME"  /boot/grub/menu.lst;  then
            echo  -e  "$GRUB_IMAGE_ENTRY"  >>  /boot/grub/menu.lst.new
          fi
          if  [ -f /boot/"$IMAGE_NAME.old" ] && 
              !  grep  -q  "$IMAGE_NAME.old"  /boot/grub/menu.lst ;  then
            echo  -e  "$GRUB_OLD_IMAGE_ENTRY"  >>  /boot/grub/menu.lst.new
          fi
        fi
        ((  IMAGE_COUNT++  ))
      fi

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

    done

    if  ((  IMAGE_COUNT ==  0  ));  then
      if  !  grep  -q  "$IMAGE_NAME"  /boot/grub/menu.lst;  then
        echo  -e  "$GRUB_IMAGE_ENTRY"  >>  /boot/grub/menu.lst.new
      fi
      if   [ -f /boot/"$IMAGE_NAME.old" ] && 
           !  grep  -q  "$IMAGE_NAME.old"  /boot/grub/menu.lst ;  then
        echo  -e  "$GRUB_OLD_IMAGE_ENTRY"  >>  /boot/grub/menu.lst.new
      fi
    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

}




More information about the Lunar-commits mailing list