#!/sbin/sh

################################################################################
#
# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#	Copyright 1992-95 AT&T Global Information Solutions
#
#pragma ident	"@(#)lurename.sh	5.16	05/10/25 SMI"
#
# USAGE     : lurename -e "existing_name" -n "new_name"
# FUNCTION  : Renames the specified boot environment.
# DEVELOPER : Satish
#
# Set a tabspace (ts=2) of 2 for better viewing of this file.
#
# Note: performance testing has proven that "/sbin/sh" provides the best performance over
# /bin/sh and /bin/ksh.
#
################################################################################

LU_PROG_FULL_PATH="$0"
LU_PROG_NAME="`basename ${LU_PROG_FULL_PATH}`"; export LU_PROG_NAME
LU_ALT=""
LURENAME_BOOT=""
LURENAME_MNTED=""
LURENAME_FSTYP=""
GRUB_BE=""

TMPFILE="/tmp/.lurename.tmp.$$"
TMPICF="/tmp/.lurename.luicf.$$"
TMP_RESULT_FILE="/tmp/.lurename.results.tmp.$$"
TMPMNT="/tmp/.lurename.mnt.$$"

################################################################################
# Name:		usage
# Description:	output command line usage information; then call exit_script to terminate execution.
# Local Prefix:	<none>
# Arguments:	$1 = exit code for script ("" defaults to "3").
# Example:	usage 3
# Returns:	<none> 
################################################################################

usage()
{
  ${LUPRINTF} -p2 "`gettext 'USAGE: %s [ -X ] [ -l error_log ] [ -o outfile ] \
-e BE_name -n new_BE_name'`" "${LU_PROG_NAME}"
  ${LUPRINTF} -Ip2 "`gettext 'Any BE_name should be enclosed in single quotes.'`"
  if [ -z "$1" ] ; then
    exit_script 3 no
  fi
  exit_script "$1" no
}

################################################################################
# Name:		exit_script
# Description:	Perform cleanup operations and exit this script.
# Local Prefix:	<none>
# Arguments:	$1 = optional exit value for script ("" or none is = "0")
# Example:      exit_script "0"
# Returns:	<none>
################################################################################

exit_script()
{
  if [ -n "${LU_ALT}" -a -n "${E_NAME}" ] ; then
    $LUBIN/luumount -f "${E_NAME}"
  fi

  if [ -n "$LURENAME_MNTED" ]; then
     /sbin/umount "$LURENAME_BOOT"
     LURENAME_MNTED=""
     LURENAME_BOOT=""
     LURENAME_FSTYP=""
  fi

  GRUB_BE=""

  # Remove all temporary files
  /bin/rm -f "${TMPFILE}" "${TMPICF}" "${TMP_RESULT_FILE}"

  # Remove temporary mount point
  /bin/rmdir "$TMPMNT" > /dev/null 2>&1

  # Determine the exit status code.

  retcode="0"
  if [ -n "$1" ] ; then
    retcode="$1"
  fi

  # Output the exit status message if not suppressed. 
  if [ -z "$2" ] ; then
    if [ "${retcode}" -eq "0" ] ; then
      ${LUPRINTF} -lp1 "`gettext 'Boot environment <%s> renamed to <%s>.'`" "${E_NAME}" "${NEW_NAME}"
    else
      ${LUPRINTF} -lp1 "`gettext 'Unable to rename boot environment.'`"
    fi
  fi

  exit "${retcode}"
}

update_be_definition()
{
 ubd_existingName="$1"
 ubd_newName="$2"
 ubd_mountPoint="$3"

 ubd_beDefFile="${ubd_mountPoint}/${LU_BE_CONFIG_FILE}"

 if [ -f "${ubd_beDefFile}" ] ; then
   ${LUPRINTF} -lp1 "`gettext 'Changing the name of BE in the BE definition file.'`"
   /bin/chmod 644 "${ubd_beDefFile}" 2>/dev/null
   nawk -v THE_NAME="${ubd_newName}" '
		/^LUBECF_BE_NAME=/ { next; } 
		{ print $1; }
		END { printf("LUBECF_BE_NAME=%s\n", THE_NAME) } 
	' < "${ubd_beDefFile}" > $TMPFILE
    if [ "$?" -ne "0" ] ; then
      ${LUPRINTF} -Eelp2 "`gettext 'Unable to modify BE definition file <%s>: cannot rename.'`" "${ubd_beDefFile}"
      return 1
    fi
    /bin/cp "$TMPFILE" "${ubd_beDefFile}"
    if [ "$?" -ne "0" ] ; then
      ${LUPRINTF} -Eelp2 "`gettext 'Unable to copy the BE definition file <%s> to <%s>: cannot rename.'`" "${TMPFILE}" "${ubd_beDefFile}"
      return 1
    fi
    /bin/chmod 444 "${ubd_beDefFile}" 2>/dev/null
 fi
 return 0
}

################################################################################
# Name:		<main>
# Description:	Main code (outside of any function definitions) - executed at script startup.
# Local Prefix:	<none>
# Arguments:	$0...$n = All arguments specified by user on command line that invoked this script.
################################################################################

# Dot the defaults file.

if [ ! -s /etc/default/lu ] ; then
  echo "${LU_PROG_NAME}: ""`gettext 'ERROR: Live Upgrade not installed properly (/etc/default/lu not found).'`"
  exit 1
fi
. /etc/default/lu

LUBIN=${LUBIN:=/usr/lib/lu}
### LU_OPTFS=${LU_OPTFS:=/etc/lu/optfs}
COPYLOCK=${COPYLOCK:=/etc/lu/COPY_LOCK}
NEXT_ACTIVE=${NEXT_ACTIVE:=/etc/lu/.NEXT_ACTIVE}

# Dot the Live Upgrade library functions.

if [ ! -s $LUBIN/lulib ] ; then
  echo "${LU_PROG_NAME}: ""`gettext 'ERROR: The Live Upgrade product is not installed properly (${LUBIN}/lulib not found).'`"
  exit 1
fi

. $LUBIN/lulib

# Check for existence and non-zero size of lutab file.

if [ ! -f ${LU_LUTAB_FILE} -o ! -s ${LU_LUTAB_FILE} ] ; then
  ${LUPRINTF} -Eelp2 "`gettext 'No boot environments are configured on this system.'`"
  exit 1
fi

  ######################################################################################
  ##################### Command line option and argument processing ####################
  ######################################################################################

# Reset all command line parse flags to default values.
flag_e="" # -e "n" - existing be name.
flag_o="" # -o f - output file path.
flag_l="" # -l f - log file path.
flag_n="" # -n "n" - new be name.
flag_x="" # -x n = set debug level to n (PRIVATE).

while [ $# -ne 0 ] ; do
  while getopts e:l:n:o:x:X c
  do
    case $c in
      e) # -i abe_icf_file
	 lulib_cannot_duplicate_option "${flag_e}" "${OPTARG}" "-e"
	 flag_e="${OPTARG}"
	 ;;
      l) # -l f - error log file path.
	 # This overrides the LU_ERROR_LOG_FILE setting read from /etc/default/lu
	 lulib_cannot_duplicate_option "${flag_l}" "${OPTARG}" "-l"
	 ${LUPRINTF} -lp2D - "`gettext 'Verifying that the error log file <%s> specified can be created and appended to.'`" "${OPTARG}"
	 ERRMSG="`${LUPRINTF} -c \"${OPTARG}\" 2>&1`"
	 if [ $? -ne 0 ] ; then
	   [ -n "${ERRMSG}" ] && ${LUPRINTF} -elp2 '%s' "${ERRMSG}"
	   ${LUPRINTF} -Eelp2 "`gettext 'Argument <%s> to -l option may not be created or appended to.'`" "${OPTARG}"
	   exit_script 3 no
	 fi
	 flag_l="${OPTARG}"
	 lulib_set_error_log_file "${flag_l}"
	 ;;
      n) # -n "n" - be name.
	 lulib_cannot_duplicate_option "${flag_n}" "${OPTARG}" "-n"
	 flag_n="${OPTARG}"
	 ;;
      o) # -o f - output file path.
	 # This overrides the LU_SESSION_LOG_FILE setting read from /etc/default/lu
	 lulib_cannot_duplicate_option "${flag_o}" "${OPTARG}" "-o"
	 ${LUPRINTF} -lp2D -  "`gettext 'Verifying that the session log file <%s> can be created and appended to.'`" "${OPTARG}"
	 ERRMSG="`${LUPRINTF} -c \"${OPTARG}\" 2>&1`"
	 if [ $? -ne 0 ] ; then
	   [ -n "${ERRMSG}" ] && ${LUPRINTF} -elp2 '%s' "${ERRMSG}"
	   ${LUPRINTF} -Eelp2 "`gettext 'Argument <%s> to -o option may not be created or appended to.'`" "${OPTARG}"
	   exit_script 3 no
	 fi
	 flag_o="${OPTARG}"
	 lulib_set_session_log_file "${flag_o}"
	 ;;
      x) # -x n - set debug level to n (PRIVATE).
	 # This overrides the default setting read from /etc/default/lu
	 lulib_cannot_duplicate_option "${flag_x}" "${OPTARG}" "-x"
	 /bin/test "${OPTARG}" -ge 0 2>/dev/null
	 if [ $? -gt 1 ] ; then
	   ${LUPRINTF} -Eelp2 "`gettext 'Argument <%s> to -x option is not a number.'`" "${OPTARG}"
	   usage 3
	 fi
	 flag_x="${OPTARG}"
	 lulib_set_debug "${flag_x}"
	 ;;
      X) # -X - set XML output mode.
	  lulib_set_output_format 'xml'
	  ;;
      \?) # unknown - option.
	  usage 3
	  esac
  done

  # Found either end of arguments, +option, or non-option argument; shift out
  # what has been processed so far; if a non-option argument is present
  # capture it and continue processing the command line arguments.
  shift `/bin/expr $OPTIND - 1`
  OPTIND=1
  if [ $# -ne 0 -a "$1" = '+X' ] ; then
      # +X - set TEXT output mode.
      lulib_set_output_format 'text'
      shift
  else
    break
  fi
done

# Fixup debug, session log, and error log settings
lulib_fixup_startup_settings

  ######################################################################################
  ############ Validate all command line arguments and options as possible #############
  ######################################################################################

# If any command line arguments provided, exit with error.
if [ "$#" -ne "0" ] ; then
  ${LUPRINTF} -Eelp2 "`gettext 'Command line arguments <%s> not allowed.'`" "$*"
  usage 3
fi

  ######################################################################################
  ########################## If x86, determine boot slice ##############################
  ######################################################################################
if [ "${LU_SYSTEM_ARCH}" = "i386" ]; then

   lulib_check_patch
   if [ "$?" -ne 0 ]; then
      exit_script 2
   fi

  LU_BOOT_LOGICAL=""
  lulib_get_boot_slice
  if [ -z "$LU_BOOT_LOGICAL" ]; then
        ${LUPRINTF} -Eelp2 "`gettext 'Cannot determine logical boot slice.'`"
        exit_script 2
  fi
  BOOT_BLK_SLICE=`/bin/echo "$LU_BOOT_LOGICAL" | /bin/sed 's/\/rdsk\//\/dsk\//g'`
  BOOT_CHR_SLICE="$LU_BOOT_LOGICAL"
fi
  ######################################################################################

# A valid new BE name must be provided.

if [ -z "${flag_n}" ] ; then
  ${LUPRINTF} -Eelp2 "`gettext 'You must use the <-n> option to specify the new name to rename the target BE to.'`"
  usage 3
fi
NEW_NAME="${flag_n}"

# A valid existing BE name must be provided

if [ -z "${flag_e}" ] ; then
  ${LUPRINTF} -Eelp2 "`gettext 'You must use the <-e> option to specify the existing name for the target BE to rename.'`"
  usage 3
fi
E_NAME="${flag_e}"

# See if a copy lock is active.
lulib_validate_lulock
if [ -f $COPYLOCK ] ; then
  . $COPYLOCK
  ${LUPRINTF} -lp2D - "`gettext 'A Copy Lock file <%s> exists: Status <%s> Source BE <%s> Target BE <%s>.'`" "${COPYLOCK}" "${CL_STATUS}" "${CL_SOURCE_BE}" "${CL_TARGET_BE}"
  ${LUPRINTF} -Eelp2 "`gettext 'Another Live Upgrade process is either running or scheduled.'`"
  exit_script 2 no
fi

# Validate the existing BE name is in use.
lulib_is_be_name_inuse "${E_NAME}"
if [ "$?" -ne "0" ] ; then
  ${LUPRINTF} -Eelp2 "`gettext 'Unable to rename the target boot environment <%s>.'`" "${E_NAME}"
  exit_script 2 no
fi

# Validate the new BE name is unused.
# 0 - the be name is valid and is unused.
# 1 - the be name is valid and is inuse.
# 2 - the be name is invalid.
lulib_is_be_name_unused "${NEW_NAME}"
ret="$?"
if [ "${ret}" -eq "1" ] ; then
  ${LUPRINTF} -Eelp2 "`gettext 'Argument <%s> to -n option must be a BE name that is not currently assigned to any BE.'`" "${NEW_NAME}"
  usage
elif [ "${ret}" -eq "2" ] ; then
  ${LUPRINTF} -Eelp2 "`gettext 'Argument <%s> to -n option must be a valid BE name.'`" "${NEW_NAME}"
  usage
fi

# Make sure the BE names are not the same.
if [ "${E_NAME}" = "${NEW_NAME}" ] ; then
  ${LUPRINTF} -Eelp2 "`gettext 'Both the existing and the new BE names may not be the same.'`"
  exit_script 2
fi

# After the error checkings, the following 4 steps are required.
#  1.  Change the BE name in /etc/lutab file.
#  2.  Change the BE name in ICF file of that BE.
#  3.  Propagate the ICF file and lutab file to all BEs.
#  4.  Change the BE name in /etc/lu/.NEXT_ACTIVE file (if it exists).
#  5. For Solaris: Is there a way to show a boot message like
#	what was done in /stand/boot??

# Determine the ID of the BE whose name is to be changed.
ID=`${LUETCBIN}/ludo get_be_id "${E_NAME}" 2>&1`
if [ $? != 0 ] ; then
  ${LUPRINTF} -Eelp2 '%s' "${ID}"
  ${LUPRINTF} -Eelp2 "`gettext 'Unable to rename the target boot environment <%s>.`'" "${E_NAME}"
  exit_script 1 no
fi

# Determine the name of Current BE.
CURR_BE=`lulib_lucurr`
if [ "$?" -ne "0" ] ; then
  ${LUPRINTF} -Eelp2 "`gettext 'Unable to determine the name of the current active boot environment.'`"
  exit_script 1 no
fi

# Tell the user what we are doing

${LUPRINTF} -lp1 "`gettext 'Renaming boot environment <%s> to <%s>.'`" "${E_NAME}" "${NEW_NAME}"

#
# Remove the leading and trailing blank spaces from the new BE name.
#
NEW_NAME="`echo $NEW_NAME | /bin/sed 's/^[ 	]*\(.*\)[ 	]*$/\1/g'`"

#
# 1. Change the name in the BE configuration file on the BE.
#

if [ "${CURR_BE}" = "${E_NAME}" ] ; then
  # Rename the current PBE - no need to attempt to mount it
  update_be_definition "${E_NAME}" "${NEW_NAME}" "/"
  ret="$?"

  GRUB_BE=""
  if [ "$LU_SYSTEM_ARCH" = "i386" -a -f "/${MULTI_BOOT}" -a -s "/${MULTI_BOOT}" ]; then
     GRUB_BE="1"
  fi
else
  # Rename ABE - must mount it first
  # The BE must not currently be mounted.
  lulib_verify_be_unmounted "${E_NAME}"
  if [ "$?" -ne "0" ] ; then
    ${LUPRINTF} -Eelp2 "`gettext 'Unable to rename boot environment <%s>.'`" "${E_NAME}"
    exit_script 1 no
  fi
  LU_ALT=`LU_OUTPUT_FORMAT=text $LUBIN/lumount "${E_NAME}" 2>${TMP_RESULT_FILE}`
  if [ "$?" -ne "0" -o -z "${LU_ALT}" ] ; then
    LU_ALT=""
    [ -s "${TMP_RESULT_FILE}" ] && ${LUPRINTF} -elp2 '%R' < "${TMP_RESULT_FILE}"
    ${LUPRINTF} -Eelp2 "`gettext 'Unable to mount boot environment <%s>.'`" "${E_NAME}"
    exit_script 1
  fi

  GRUB_BE=""
  if [ "$LU_SYSTEM_ARCH" = "i386" -a -f "${LU_ALT}/${MULTI_BOOT}" -a -s "${LU_ALT}/${MULTI_BOOT}" ]; then
     GRUB_BE="1"
  fi

  update_be_definition "${E_NAME}" "${NEW_NAME}" "${LU_ALT}"
  ret="$?"
  $LUBIN/luumount -f "${E_NAME}"
  LU_ALT=""
fi

if [ "${ret}" -ne "0" ] ; then
  ${LUPRINTF} -Eelp2 "`gettext 'Unable to update the BE definition file for BE <%s>.'`" "${E_NAME}"
  exit_script 1
fi

#
# 2. Change the BE name in /etc/lutab file.
#

${LUPRINTF} -lp1 "`gettext 'Changing the name of BE in configuration file.'`"

${LUPRINTF} -lp2D - "`gettext 'Editing <%s> BE ID <%s> change name <%s> to name <%s>.'`" "${LU_LUTAB_FILE}" "${ID}" "${E_NAME}" "${NEW_NAME}"
/bin/sed "s:^${ID}\:${E_NAME}\::${ID}\:${NEW_NAME}\::" ${LU_LUTAB_FILE} > ${TMPFILE}

if [ $? != 0 ] ; then
  ${LUPRINTF} -Eelp2 "`gettext 'Could not rename the BE in BE configuration file <%s>.'`" "${LU_LUTAB_FILE}"
  exit_script 1
fi

/bin/cp $TMPFILE ${LU_LUTAB_FILE}
if [ $? != 0 ] ; then
  ${LUPRINTF} -Eelp2 "`gettext 'Could not rename the BE configuration file from <%s> to <%s>.'`" "$TMPFILE}" "${LU_LUTAB_FILE}"
  exit_script 1
fi

#
# 3. Change BE name in compare filenames
#
E_NAME2=`echo "${E_NAME}" | /bin/sed 's/ /___/g;s%/%_:_%g'`
NEW_NAME2=`echo "${NEW_NAME}" | /bin/sed 's/ /___/g;s%/%_:_%g'`

renamed=0
OLD_PWD="`/bin/pwd`"
cd ${LU_COMPARE_DATABASE_DIR}
for i in `/bin/ls` ; do
	if [ ! -f "$i" ] ; then
		continue
	fi
	j=`echo "$i" | /bin/sed "s/^${E_NAME2}:/${NEW_NAME2}:/g" | \
		     /bin/sed "s/:${E_NAME2}$/:${NEW_NAME2}/g"`
	if [ "$j" != "" -a "$j" != "$i" ] ; then
		/bin/mv "${LU_COMPARE_DATABASE_DIR}/$i" "${LU_COMPARE_DATABASE_DIR}/$j"
		renamed=1
	fi
done
cd ${OLD_PWD}

# Update compare database on all boot environments
if [ "$renamed" = "1" ] ; then
  lulib_update_compare
fi

#
# 4. Change the BE name in ICF file of the BE.
#

${LUPRINTF} -lp1 "`gettext 'Changing the name of BE in Internal Configuration Files.'`"

${LUPRINTF} -lp2D - "`gettext 'Editing <%s> BE ID <%s> change name <%s> to name <%s>.'`" "/etc/lu/ICF.$ID" "${ID}" "${E_NAME}" "${NEW_NAME}"

/bin/sed "s:^${E_NAME}\::${NEW_NAME}\::" /etc/lu/ICF.$ID >$TMPFILE
if [ $? != 0 ] ; then
  ${LUPRINTF} -Eelp2 "`gettext 'Could not rename the BE in the internal configuration file <%s>.'`" "/etc/lu/ICF.${ID}"
  exit_script 1
fi

/bin/cp $TMPFILE /etc/lu/ICF.$ID
if [ $? != 0 ] ; then
  ${LUPRINTF} -Eelp2 "`gettext 'Could not rename the BE internal configuration file from <%s> to <%s>.'`" "$TMPFILE" "/etc/lu/ICF.${ID}"
  exit_script 1
fi

#
# 5. Propagate the lutab file and the ICF file to all BEs.
#

${LUPRINTF} -lp1 "`gettext 'Propagating the boot environment name change to all BEs.'`"


$LUBIN/luupdall ${LU_LUTAB_FILE} /etc/lu/ICF.$ID
if [ $? != 0 ] ; then
  ${LUPRINTF} -Eelp2 "`gettext 'Unable to propagate the files <%s> to all boot environments.'`" "${LU_LUTAB_FILE} /etc/lu/ICF.$ID"
  exit_script 1
fi

#
# 6. Change the name of BE in /etc/lu/.NEXT_ACTIVE file
#

if [ -f $NEXT_ACTIVE ] ; then
  /bin/grep "^${E_NAME}$" $NEXT_ACTIVE >/dev/null
  if [ $? = 0 ] ; then
    echo "$NEW_NAME" > $NEXT_ACTIVE
  fi
fi

#
# Normal exit if BE being renamed is not a GRUB BE
#
if [ -z "$GRUB_BE" ]; then
   exit_script 0
fi

/bin/echo "$BOOT_CHR_SLICE" | /bin/egrep "p0:boot$" > /dev/null 2>&1
if [ "$?" -eq 0 ]; then
   BOOT_REAL_SLICE=`lulib_get_real_boot_partition "$BOOT_CHR_SLICE"`
else
   BOOT_REAL_SLICE="$BOOT_CHR_SLICE"
fi

if [ "$?" -ne 0 -o -z "$BOOT_REAL_SLICE" ]; then
   ${LUPRINTF} -Eelp2 "`gettext 'Cannot derive real boot partition name: <%s>'`" "${BOOT_CHR_SLICE}"
   exit_script 2 no
fi

#
# If a Newboot (GRUB) BE, then update menu.lst
#
LURENAME_BOOT=`/usr/sbin/mount | /bin/nawk -v dev=$BOOT_BLK_SLICE ' { if ($3 == dev) {printf("%s\n", $1); exit 8;}}'`
if [ "$?" -ne 8 ]; then
   LURENAME_BOOT=""
   /bin/mkdir -p "$TMPMNT"
   LURENAME_FSTYP=`lulib_fstyp $BOOT_REAL_SLICE`
   if [ "$?" -ne 0 -o -z "$LURENAME_FSTYP" ]; then
     ${LUPRINTF} -Eelp2 "`gettext 'Cannot determine fstype for boot slice <%s>.'`" "${BOOT_BLK_SLICE}"
     exit_script 2 no
   fi
   /sbin/mount -F "$LURENAME_FSTYP" "$BOOT_BLK_SLICE" "$TMPMNT" 2>$TMPFILE
   if [ "$?" -ne 0 ]; then
      /bin/cat "$TMPFILE"
      ${LUPRINTF} -Eelp2 "`gettext 'Cannot mount boot slice <%s>. Cannot update GRUB menu'`" "${BOOT_BLK_SLICE}"
      exit_script 2 no
   fi
   LURENAME_BOOT="$TMPMNT"
   LURENAME_MNTED=1
fi

if [ ! -f "${LURENAME_BOOT}/${BOOT_MENU}" -o ! -s  "${LURENAME_BOOT}/${BOOT_MENU}" ]; then
      ${LUPRINTF} -Eelp2 "`gettext 'Cannot access GRUB menu <%s>'`" "${LURENAME_BOOT}/${BOOT_MENU}"
      exit_script 2 no
fi

E_FIXED=`lulib_fix_name $E_NAME`
NEW_FIXED=`lulib_fix_name $NEW_NAME`

/usr/bin/grep "${BOOT_MENU_PREFIX}${E_FIXED}${BOOT_MENU_HDR_SUFFIX}" "${LURENAME_BOOT}/${BOOT_MENU}" > /dev/null 2>&1
if [ "$?" -eq 0 ]; then

   /usr/bin/sed "s/${BOOT_MENU_PREFIX}${E_FIXED}${BOOT_MENU_HDR_SUFFIX}/${BOOT_MENU_PREFIX}${NEW_FIXED}${BOOT_MENU_HDR_SUFFIX}/" "${LURENAME_BOOT}/${BOOT_MENU}" > "$TMPFILE"

   /usr/bin/sed "s/title ${E_FIXED}/title ${NEW_FIXED}/" "$TMPFILE" >  "${LURENAME_BOOT}/${BOOT_MENU}"

   /usr/bin/sed "s/title ${E_FIXED} failsafe/title ${NEW_FIXED} failsafe/" "${LURENAME_BOOT}/${BOOT_MENU}" > "$TMPFILE"

   /usr/bin/sed "s/${BOOT_MENU_PREFIX}${E_FIXED}${BOOT_MENU_FTR_SUFFIX}/${BOOT_MENU_PREFIX}${NEW_FIXED}${BOOT_MENU_FTR_SUFFIX}/" "$TMPFILE" > "${LURENAME_BOOT}/${BOOT_MENU}"
fi

/bin/cp -p "${LURENAME_BOOT}/${BOOT_MENU}" "${GRUB_backup_menu}"
$LUBIN/luupdall ${GRUB_backup_menu}
if [ $? != 0 ] ; then
  ${LUPRINTF} -Eelp2 "`gettext 'Unable to propagate the GRUB backup menu <%s> to all boot environments.'`" "${GRUB_backup_menu}"
  exit_script 1
fi

exit_script 0
