#!/bin/sh
#"@(#)prep_container    05/15/2024      (c) Stromasys LLC"
#"@(#)This script collects a SRP HP9000 Container environment,"
#"@(#)cleans up the IA64 portion, and creates a usable Ignite"
#"@(#)archive image."
#"@(#)"
#
# set -x
HOST=`hostname`
SRP="/var/hpsrp"
TITLE="Container -->  Ignite Archive Image Tool"; TIW=`echo ${TITLE} | wc -c`
((HW=$TIW/2)); COLS=$(tput cols); ((HCOLS=$COLS/2)); ((HS=$HCOLS-$HW)); ((HS+=1))
OS=`uname -a | awk '{print $1}'`
if [[ ${OS} = "HP-UX" ]]
then
  ECHO="echo"
  i=1; chr="="; spc=" "
  while [[ $i -lt $COLS ]]; do HDR=${HDR}$chr; ((i+=1)); done; i=1
  while [[ $i -lt $HS ]]; do HDT=${HDT}$spc; ((i+=1)); done
  CTITLE="${HDR}\n${HDT}${TITLE}\n${HDR}"
else
  ECHO="echo -e"
  ITITLE=`printf "%*s\n" $(((${#TITLE}+$COLS)/2)) "${TITLE}"`
  HDR="`printf '%*s' "$COLS" | tr ' ' "="`"
  CTITLE="${HDR}\n${ITITLE}\n${HDR}"
fi

envvars()
{
  clear
  ${ECHO} "${CTITLE}"
  [[ "${RESUME}" != "" ]] && ${ECHO} "${RESUME}"
  ${ECHO} "Setting Environment Variables\n"
  ${ECHO} "\t- Enter the name of the containerized host: \c"
  read CHOST

  ${ECHO} "\t- Enter the name of the server for the working area [${HOST}]: \c"
  read SERV
  [[ -z ${SERV} ]] && SERV=${HOST}

  ${ECHO} "\t- Enter the name of the working area parent directory: \c"
  read PDIR
  c1=`${ECHO} ${PDIR} | cut -c 1`
  if [[ ${c1} != "/" ]]
  then
    ${ECHO} "\n\t\tThe specified parent directory [${PDIR}] is a relative path"
    PDIR="/${PDIR}"
    ${ECHO} "\t\tSetting it to absolute path [${PDIR}]\n"
  fi

  if [[ ! -d ${PDIR} ]]
  then
    ${ECHO} "\t\tThe parent directory [${PDIR}] does not exist - exiting!\n"
    exit
  fi

  WDIR=${PDIR}/${CHOST}
  if [[ ! -d ${WDIR} ]]
  then
    ${ECHO} "\t\tThe working directory [${WDIR}] does not exist - creating it"
    mkdir ${WDIR}
    [[ -d ${WDIR} ]] && ${ECHO} "\t\t${WDIR} now exists"
  fi
  H9=${WDIR}/var/opt/HP9000-Containers
  ${ECHO} "\n\tThe following environment varialbles have been set:\n"
  ${ECHO} "\t\tContainer\t${CHOST}"
  ${ECHO} "\t\tServer\t\t${SERV}"
  ${ECHO} "\t\tParent Dir\t${PDIR}"
  ${ECHO} "\t\tWorking Dir\t${WDIR}"
  ${ECHO} "\n\tIf these are correct, press <return/enter> to continue - or press CTRL-c to exit and rerun this script to redefine \c"
  read ans
}

shutdown_srp()
{
  if [[ ! -d ${SRP}/${CHOST} ]]
  then
    ${ECHO} "\t\t${CHOST} is not a valid container guest - exiting!\n"
    exit
  fi
  clear
  ${ECHO} "${CTITLE}"
  ${ECHO} "Optionally, shutting down the SRP container [${CHOST}]\n"
  if [[ "${OS}" != "HP-UX" ]]
  then
    ${ECHO} "\tYou are not running this tool on a HP-UX server - the SRP shutdown cannot be run!"
    ${ECHO} "\tExiting!\n"
    exit
  else
    if [[ ! -f /opt/hpsrp/bin/srp ]]
    then
      ${ECHO} "\tThis HP-UX server is not the SRP host for the container [${CHOST}], so this"
      ${ECHO} "\ttool cannot be started using option -b on this server - exiting!\n"
      exit
    fi
  fi
  ${ECHO} "\tDo you wish to shutdown the container [${CHOST}]? [y/n] \c"
  read shut
  if [[ "${shut}" = "Y" || "${shut}" = "y" ]]
  then
    if [[ "`/opt/hpsrp/bin/srp -status ${CHOST} | tail -1 | awk '{print $3}'`" = "started" ]]
    then
      ${ECHO} "\t- Shutting down the container [${CHOST}]"
      ${ECHO} "\t\tThis will take a couple of minutes..."
      srp -stop ${CHOST} > /dev/null 2>&1
      if [[ "`/opt/hpsrp/bin/srp -status ${CHOST} | tail -1 | awk '{print $3}'`" = "stopped" ]]
      then
        ${ECHO} "\t- The container [${CHOST}] has been shut down - press <return/enter> key to continue \c"
        read ans
      fi
    else
      ${ECHO} "\tThe container [${CHOST}] is not currently running - press <return/enter> key to continue\c"
      read ans
    fi
  else
    ${ECHO} "\tThe container [${CHOST}] will remain running - press <return/enter> key to continue\c"
    read ans
  fi
}

starting_srp()
{
  clear
  ${ECHO} "${CTITLE}"
  ${ECHO} "Optionally, starting up the SRP container [${CHOST}]\n"
  ${ECHO} "\tDo you wish to startup the container [${CHOST}]? [y/n] \c"
  read shut
  if [[ "${shut}" = "Y" || "${shut}" = "y" ]]
  then
    if [[ "`/opt/hpsrp/bin/srp -status ${CHOST} | tail -1 | awk '{print $3}'`" = "stopped" ]]
    then
      ${ECHO} "\t- Starting up the container [${CHOST}]"
      ${ECHO} "\t\tThis will take a couple of minutes..."
      srp -start ${CHOST} > /dev/null 2>&1
      if [[ "`/opt/hpsrp/bin/srp -status ${CHOST} | tail -1 | awk '{print $3}'`" = "started" ]]
      then
        ${ECHO} "\t- The container [${CHOST}] has been started - press <return/enter> key to continue \c"
        read ans
      else
        ${ECHO} "The container [${CHOST}] failed to start - exiting so you can investigate\n"
        exit
      fi
    else
      ${ECHO} "\tThe container [${CHOST}] is currently running - press <return/enter> key to continue\c"
      read ans
    fi
  else
    ${ECHO} "\tThe container [${CHOST}] will remain shut down - press <return/enter> key to continue\c"
    read ans
  fi
}

init_tar()
{
  clear
  ${ECHO} "${CTITLE}"
  ${ECHO} "Creating a tar file for the container environment of [${CHOST}]\n"
  create_tar
  if [[ -f "${PDIR}/${CHOST}.tar" ]]
  then
    ${ECHO} "\n\tThe tar file [${PDIR}/${CHOST}.tar] already exists"
    ${ECHO} "\n\t\t--> `ls -l ${PDIR}/${CHOST}.tar`"
    ${ECHO} "\n\tDo you want to delete this file and create a new tar file? [y/n] \c"
    read ans
    if [[ "${ans}" = "y" || "${ans}" = "Y" ]]
    then
      ${ECHO} "\n\t- Removing existing tar file [${PDIR}/${CHOST}.tar]"
      rm -r -f ${PDIR}/${CHOST}.tar
      if [[ ! -f ${PDIR}/${CHOST}.tar ]]
      then
        ${ECHO} "\t- ${PDIR}/${CHOST}.tar successfully removed"
      else
        ${ECHO} "\n\t\tCould not remove ${PDIR}/${CHOST}.tar - exiting so you can investigate\n"
        exit
      fi
      create_tar
    fi
  else
    create_tar
  fi
}

create_tar()
{
  ${ECHO} "\tDo you wish to proceed with the creation of the tar file [${PDIR}/${CHOST}.tar]? [y/n] \c"
  read extr
  if [[ "${extr}" = "y" || "${extr}" = "Y" ]]
  then
    ${ECHO} "\n\tThis step should take less than 10 minutes"
    ${ECHO} "\tProgress can be monitored by checking for ${PDIR}/${CHOST}.tar\n"
    ${ECHO} "\t- Changing directories to the container root directory [${SRP}/${CHOST}]"
    cd ${SRP}/${CHOST}
    ${ECHO} "\t- Creating the tar file [${PDIR}/${CHOST}.tar]"
    #tar -cvf ${PDIR}/${CHOST}.tar .
    ${ECHO} "\n\t- The tar creation process has completed"
    ${ECHO} "\t\t--> `ls -l ${PDIR}/${CHOST}.tar`\n"
    if [[ "${SERV}" != "${HOST}" ]]
    then
      ${ECHO} "\tYou have chosen to complete the creation of the Ignite archive image on [${SERV}]"
      ${ECHO} "\tPlease copy ${PDIR}/${CHOST}.tar to ${SERV}:${PDIR}/${CHOST} and rerun this script on [${SERV}]\n"
      ${ECHO} "\t\t--> /usr/local/bin/prep_container -e\n"
      ${ECHO} "\tExiting\n"
      exit
    else
      ${ECHO} "\tPress <return/enter> key to continue\c"
      read ans
      #starting_srp
    fi
  else
    ${ECHO} "\n\tYou have chosen to skip this step - nothing else to do"
    ${ECHO} "\tA tar file must be created in order to proceed with this tool!"
    ${ECHO} "\tExiting\n"
    exit
  fi
}

extract_tar()
{
  clear
  ${ECHO} "${CTITLE}"
  [[ "${RESUME}" != "" ]] && ${ECHO} "${RESUME}"
  ${ECHO} "Extracting the tar file for the container environment of [${CHOST}]\n"
  ${ECHO} "\tDo you wish to proceed with extracting the tar file [${PDIR}/${CHOST}.tar]? [y/n] \c"
  read extr
  if [[ "${extr}" = "y" || "${extr}" = "Y" ]]
  then
    ${ECHO} "\n\tThis step should take less than 10 minutes"
    ${ECHO} "\tProgress can be monitored by checking the parent directory ${PDIR}\n"
    ${ECHO} "\t- Changing directories to the container working directory ${WDIR}"
    cd ${WDIR}
    ${ECHO} "\t- Checking for tar file [${PDIR}/${CHOST}.tar]"
    if [[ -f ${PDIR}/${CHOST}.tar ]]
    then
      ${ECHO} "\n\t\tFile exists --> `ls -l ${PDIR}/${CHOST}.tar`"
      ${ECHO} "\n\t- Extracting contents from the tar file - press <return/enter> to continue \c"
      read ans
      tar -xvf ${PDIR}/${CHOST}.tar
      ${ECHO} "\n\t- The tar extraction process has completed"
      ${ECHO} "\n\tPress <return/enter> key to continue\c"
      read ans
    else
      ${ECHO} "\t\tThe tar file does not exist in [${PDIR}] - please place the tar file in [${PDIR}] and rerun this script\n"
      ${ECHO} "\tExiting\n"
      exit
    fi
  else
    ${ECHO} "\n\tYou have chosen to skip this step - nothing else to do"
    ${ECHO} "\tThe tar file must be extracted in order to proceed with this tool!"
    ${ECHO} "\tExiting\n"
    exit
  fi
}

move_dirs()
{
  clear
  ${ECHO} "${CTITLE}"
  [[ "${RESUME}" != "" ]] && ${ECHO} "${RESUME}"
  ${ECHO} "Moving certain preserved directories into their proper location\n"
  DEV=${WDIR}/dev
  D9=${DEV}-hp9000
  SBIN=${WDIR}/sbin
  S9=${SBIN}-hp9000
  ${ECHO} "\tAbout to move ${D9} to ${DEV} - do you wish to continue? [y/n] \c"
  read ans
  if [[ "${ans}" = "y" || "${ans}" = "Y" ]]
  then
    if [[ -d ${DEV} && -d ${D9} ]]
    then
      ${ECHO} "\n\t- Removing the old ${DEV} directory"
      rm -r ${DEV}
      if [[ ! -d ${DEV} ]]
      then
        ${ECHO} "\t- ${DEV} successfully removed"
      else
        ${ECHO} "\n\t\tCould not remove ${DEV} - exiting so you can investigate why ${DEV} could not be removed\n"
        exit
      fi
      ${ECHO} "\t- Moving the ${D9} directory to ${DEV}"
      mv ${D9} ${DEV}
      [[ -d ${DEV} && ! -d ${D9} ]] && ${ECHO} "\t- ${D9} successfully moved to ${DEV}"
    else
      ${ECHO} "\n\tThere is a problem with either ${DEV} or ${D9}"
      if [[ -d ${DEV} ]]
      then
        ${ECHO} "\t- ${DEV} exists"
      else
        ${ECHO} "\t- ${DEV} does not exist! - Exiting for you to investigate\n"
        exit
      fi
      if [[ -d ${D9} ]]
      then
        ${ECHO} "\t- ${D9} exists"
      else
        ${ECHO} "\t- ${D9} does not exist! - Exiting for you to investigate\n"
        exit
      fi
    fi 
  fi

  ${ECHO} "\n\tAbout to move ${S9} to ${SBIN} - do you wish to continue? [y/n] \c"
  read ans
  if [[ "${ans}" = "y" || "${ans}" = "Y" ]]
  then
    if [[ -d ${SBIN} && -d ${S9} ]]
    then
      ${ECHO} "\n\t- Removing the old ${SBIN} directory"
      rm -r ${SBIN}
      if [[ ! -d ${SBIN} ]]
      then
        ${ECHO} "\t- ${SBIN} successfully removed"
      else
        ${ECHO} "\n\t\tCould not remove ${SBIN} - exiting so you can investigate why ${SBIN} could not be removed\n"
        exit
      fi
      ${ECHO} "\t- Moving the ${S9} directory to ${SBIN}"
      mv ${S9} ${SBIN}
      [[ -d ${SBIN} && ! -d ${S9} ]] && ${ECHO} "\t- ${S9} successfully moved to ${SBIN}\n"
    else
      ${ECHO} "\n\tThere is a problem with either ${SBIN} or ${S9}"
      if [[ -d ${SBIN} ]]
      then
        ${ECHO} "\t- ${SBIN} exists"
      else
        ${ECHO} "\t- ${SBIN} does not exist! - Exiting so you can investigate\n"
        exit
      fi
      if [[ -d ${S9} ]]
      then
        ${ECHO} "\t- ${S9} exists"
      else
        ${ECHO} "\t- ${S9} does not exist! - Exiting so you can investigate\n"
        exit
      fi
    fi
  else
    ${ECHO} "\n\tYou have chosen to skip this step - nothing else to do"
    ${ECHO} "\tThe old directories must be replaced with the preserved directories in order to proceed with this tool!"
    ${ECHO} "\tExiting\n"
    exit
  fi
  ${ECHO} "\n\tPress <return/enter> key to continue\c"
  read ans
}

copy_files()
{
  clear
  ${ECHO} "${CTITLE}"
  [[ "${RESUME}" != "" ]] && ${ECHO} "${RESUME}"
  ${ECHO} "Copying certain preserved files into their proper location\n"
  ${ECHO} "\tAbout to copy certain files from ${H9} to ${WDIR}"
  ${ECHO} "\tDo you wish to continue? [y/n] \c"
  read ans
  if [[ "${ans}" = "y" || "${ans}" = "Y" ]]
  then
    ${ECHO} "\n\t- Copying files...\n"
    ${ECHO} "\t\t${H9}/etc/* --> ${WDIR}/etc"
    cp -p -r -f ${H9}/etc/* ${WDIR}/etc
    ${ECHO} "\t\t${H9}/opt/* --> ${WDIR}/opt"
    cp -p -r -f ${H9}/opt/* ${WDIR}/opt
    rm -r -f ${WDIR}/opt/hpsrp
    cp -p -r -f ${H9}/usr/* ${WDIR}/usr
    ${ECHO} "\t\t${H9}/var/* --> ${WDIR}/var"
    cp -p -r -f ${H9}/var/* ${WDIR}/var
    ${ECHO} "\t\t${H9}/sbin/fs/autofs/* --> ${WDIR}/sbin/fs/autofs"
    cp -p -r -f ${H9}/sbin/fs/autofs/* ${WDIR}/sbin/fs/autofs
    ${ECHO} "\t\t${H9}/sbin/fs/cachefs/* --> ${WDIR}/sbin/fs/cachefs"
    cp -p -r -f ${H9}/sbin/fs/cachefs/* ${WDIR}/sbin/fs/cachefs
    ${ECHO} "\t\t${H9}/sbin/fs/nfs/* --> ${WDIR}/sbin/fs/nfs" 
    cp -p -r -f ${H9}/sbin/fs/nfs/* ${WDIR}/sbin/fs/nfs
    ${ECHO} "\t\t${H9}/sbin/init.d/nfs* --> ${WDIR}/sbin/init.d"
    cp -p -r -f ${H9}/sbin/init.d/nfs* ${WDIR}/sbin/init.d
    ${ECHO} "\t\t${H9}/sbin/lib/mfsconfig.d/cachefs --> ${WDIR}/sbin/lib/mfsconfig.d"
    cp -p -r -f ${H9}/sbin/lib/mfsconfig.d/cachefs ${WDIR}/sbin/lib/mfsconfig.d
    ${ECHO} "\n\tDone!"
  fi
  ${ECHO} "\n\tPress <return/enter> key to continue\c"
  read ans
}

rem_files()
{
  clear
  ${ECHO} "${CTITLE}"
  [[ "${RESUME}" != "" ]] && ${ECHO} "${RESUME}"
  ${ECHO} "Removing certain unneeded files from several original locations\n"
  ${ECHO} "\tAbout to remove certain unneeded files from ${WDIR}"
  ${ECHO} "\tDo you wish to continue? [y/n] \c"
  read ans
  if [[ "${ans}" = "y" || "${ans}" = "Y" ]]
  then
    LIST="/.ariesrc /.aries64rc /.srp /srp.log /etc/opt/hpsrp /etc/srp_console.log /etc/srptags /opt/hpsrp /opt/perl_32 /opt/perl/perl_32 /sbin/init.d/*ipv6 /sbin/rc*.d/*ipv6 /sbin/rc_srpmode.utils /sbin/srp* /usr/lib/hpux32 /usr/lib/hpux64 /usr/lib/libsrp.1 /usr/lib/nls/loc/hpux32 /usr/lib/nls/loc/hpux64 /usr/lib/pa20_64/libsrp.1"
    ${ECHO} "\n\t- Removing files...\n"
    for FILE in `${ECHO} ${LIST}`
    do
      ${ECHO} "\t\t${WDIR}${FILE}"
      rm -r -f ${WDIR}/${FILE}
    done
    ${ECHO} "\n\t- Removing old preserved area ${H9}"
    rm -r ${H9}
    if [[ ! -d ${H9} ]]
    then
      ${ECHO} "\t- ${H9} successfully removed"
    else
      ${ECHO} "\n\t\tCould not remove ${H9} - exiting so you can investigate why ${H9} could not be removed\n"
      exit
    fi
    ${ECHO} "\n\tDone!"
  else
    ${ECHO} "You have chosen to not delete these unneeded files from ${WDIR}"
    ${ECHO} "and as part of the cleanup of ${WDIR} before creating the Ignite"
    ${ECHO} "archive image, these files and directories need to be removed before"
    ${ECHO} "continuing - exiting!\n"
    exit
  fi
  ${ECHO} "\n\tPress <return/enter> key to continue\c"
  read ans
}

check_ia()
{
  clear
  ${ECHO} "${CTITLE}"
  [[ "${RESUME}" != "" ]] && ${ECHO} "${RESUME}"
  ${ECHO} "Perfoming a validation check - looking for remaining Itanium executable (IA64) files\n"
  ${ECHO} "\tDo you wish to proceed with the validation check? [y/n] \c"
  read ans
  if [[ "${ans}" = "y" || "${ans}" = "Y" ]]
  then
    ${ECHO} "\n\t- Changing directories to the working directory [${WDIR}]"
    cd ${WDIR}
    ${ECHO} "\t- Looking for IA64 executables - this will take less than 10 minutes"
    [[ -f ${WDIR}/tmp/check_ia.out ]] && rm -f ${WDIR}/tmp/check_ia.out
    find . -type f -exec file {} \; > ${WDIR}/tmp/check_ia.out
    ${ECHO} "\t- Search complete!"
    IACNT=`egrep 'IA64|IA-64' ${WDIR}/tmp/check_ia.out | grep -iv ignite | wc -l`
    ${ECHO} "\t- There are ${IACNT} remaining IA64 files to be removed\n"
    for fn in `egrep 'IA64|IA-64' ${WDIR}/tmp/check_ia.out | grep -iv ignite | awk -F ":" '{print $1}'`
    do
      ${ECHO} "\t\t${fn}"
    done
    ${ECHO} "\n\t- Do you want to delete these files? [y/n] \c"
    read ans
    if [[ "${ans}" = "y" || "${ans}" = "Y" ]]
    then
      ${ECHO} "\n\t- Deleting discovered IA64 executables:\n"
      for fn in `egrep 'IA64|IA-64' ${WDIR}/tmp/check_ia.out | grep -iv ignite | awk -F ":" '{print $1}'`
      do
        ${ECHO} "\t\tDeleteing ${fn}"
        rm -r -f ${fn}
      done
      ${ECHO} "\n\tDone!"
    else
      ${ECHO} "\n\tYou have chosen to not delete these IA64 executables and while"
      ${ECHO} "\tthis poses not problem, they serve no value on a PA-RISC server"
      ${ECHO} "\tPlease refer to ${WDIR}/tmp/check_ia.out if you choose to delete"
      ${ECHO} "\tthese files in the future\n"
    fi
  else
    ${ECHO} "\n\tYou have chosen to not perform the validation check routing - this needs to be"
    ${ECHO} "\tperformed before continuing - exiting!\n"
    exit
  fi
  ${ECHO} "\n\tPress <return/enter> key to continue\c"
  read ans
}

init_image()
{
  clear
  ${ECHO} "${CTITLE}"
  [[ "${RESUME}" != "" ]] && ${ECHO} "${RESUME}"
  ${ECHO} "Creating a Ignite archive image for the container environment of [${CHOST}]\n"
  if [[ -f "${PDIR}/${CHOST}_archive" ]]
  then
    ${ECHO} "\n\tThe tar file [${PDIR}/${CHOST}_archive] already exists"
    ${ECHO} "\n\t\t--> `ls -l ${PDIR}/${CHOST}_archive`"
    ${ECHO} "\n\tDo you want to delete this file and create a new tar file? [y/n] \c"
    read ans
    if [[ "${ans}" = "y" || "${ans}" = "Y" ]]
    then
      ${ECHO} "\n\t- Removing existing tar file [${PDIR}/${CHOST}_archive]"
      rm -r -f ${PDIR}/${CHOST}_archive
      if [[ ! -f ${PDIR}/${CHOST}_archive ]]
      then
        ${ECHO} "\t- ${PDIR}/${CHOST}_archive successfully removed"
      else
        ${ECHO} "\n\t\tCould not remove ${PDIR}/${CHOST}_archive - exiting so you can investigate\n"
        exit
      fi
      create_image
    else
      ${ECHO} "\n\tYou have chosen not to create the Ignite archive image at this time"
      ${ECHO} "\tbut you will need this image to create an HP-UX client - exiting!\n"
      exit
    fi
  else
    create_image
  fi
}

create_image()
{
  ${ECHO} "\tDo you wish to proceed with the creation of the Ignite archive image [${PDIR}/${CHOST}_archive]? [y/n] \c"
  read ans
  if [[ "${ans}" = "y" || "${ans}" = "Y" ]]
  then
    ${ECHO} "\n\tThis step should take less than 10 minutes"
    ${ECHO} "\tProgress can be monitored by checking for ${PDIR}/${CHOST}_archive\n"
    ${ECHO} "\t- Changing directories to the container working directory [${WDIR}]"
    cd ${WDIR}
    ${ECHO} "\n\tSelect the items to be included in the Ignite archive image:\n"
    ls -ax ${WDIR}
    ${ECHO} "\n\tEnter each file/directory (separated by a space) to include: \c"
    read TFILES
    ${ECHO} "\n\t- Creating the Ignite archive image [${PDIR}/${CHOST}_archive] with the following:\n"
    ${ECHO} "\t${TFILES}"
    ${ECHO} "\n\tpress <return/enter> key to continue \c"
    read ans
    if [[ "${OS}" = "HP-UX" ]]
    then
      tar -cvf ${PDIR}/${CHOST}_archive `${ECHO} ${TFILES}`
    else
      tar -cvf ${PDIR}/${CHOST}_archive --format=ustar `${ECHO} ${TFILES}`
    fi
    ${ECHO} "\n\t- The Ignite archive image creation process has completed\n"
    ${ECHO} "\t\t--> `ls -l ${PDIR}/${CHOST}_archive`\n"
    ${ECHO} "\tPress <return/enter> key to continue\c"
    read ans
  else
    ${ECHO} "\n\tYou have chosen to skip this step - nothing else to do"
    ${ECHO} "\tthe Ignite archive image must be created in order to proceed with this tool!"
    ${ECHO} "\tExiting\n"
    exit
  fi
  return
}

compress_image()
{
  clear
  ${ECHO} "${CTITLE}"
  [[ "${RESUME}" != "" ]] && ${ECHO} "${RESUME}"
  ${ECHO} "Do you wish to proceed with compressing the Ignite archive image [${PDIR}/${CHOST}_archive]? [y/n] \c"
  read ans
  if [[ "${ans}" = "y" || "${ans}" = "Y" ]]
  then
    ${ECHO} "\n\tThis step should take less than 10 minutes"
    ${ECHO} "\tProgress can be monitored by checking for ${PDIR}/${CHOST}_archive.gz\n"
    ${ECHO} "\t- Changing directories to the working parent directory [${PDIR}]"
    cd ${PDIR}
    ${ECHO} "\t- Compressing the Ignite archive image [${PDIR}/${CHOST}_archive]"
    gzip ${CHOST}_archive
    [[ -f ${PDIR}/${CHOST}_archive.gz ]] && ${ECHO} "\t- The Ignite archive image has been compressed"
    ${ECHO} "\t- Renaming ${PDIR}/${CHOST}_archive.gz to ${PDIR}/${CHOST}_archive"
    mv ${PDIR}/${CHOST}_archive.gz ${PDIR}/${CHOST}_archive
    ${ECHO} "\n\t\t--> `ls -l ${PDIR}/${CHOST}_archive`"
    ${ECHO} "\n\tPress <return/enter> key to continue \c"
    read ans
  else
    ${ECHO} "\n\tYou have chosen to skip this step - nothing else to do"
    ${ECHO} "\tthe Ignite archive image must be compressed in order to be used by Ignite-UX!"
    ${ECHO} "\tExiting\n"
    exit
  fi
  ${ECHO} "\n\tNow that the Ignite archive image has been created and compressed, it can be used"
  ${ECHO} "\tvia Ignite-UX to build HP-UX clients.  Refer to the Ignite-UX Administration Guide"
  ${ECHO} "\tfor configuring the Ignite-UX server to make use of this image.\n\n"
}

########
# MAIN #
########
clear
if [ -z "$*" ]
then
  ${ECHO} "${CTITLE}"
  ${ECHO} "\nusage: prep_container [ -b | -e | -m | -c | -r | -v | -i | -z ]\n"
  ${ECHO} "Options are as follows:\n"
  ${ECHO} "\t- b: this will execute all steps from the beginning - can only be ran on the Itanium host"
  ${ECHO} "\t- e: this will begin execution with extracting the containerized environment"
  ${ECHO} "\t- m: this will begin execution with moving the dev-hp9000 and sbin-hp9000 directories"
  ${ECHO} "\t- c: this will begin execution with copying certain file from the HP9000-Containers area"
  ${ECHO} "\t- r: this will begin execution with the removal of unneeded IA64 executables"
  ${ECHO} "\t- v: this will begin execution with the validation process (no more IA64 executables)"
  ${ECHO} "\t- i: this will begin execution with the creation of the Ignite archive image"
  ${ECHO} "\t- z: this will begin execution with the compression (gzip) of the Ignite archive image\n"
  ${ECHO} "\tEnvironment variables will always be set before the execution of any of the above options\n"
  exit
fi

while getopts ":bemcrviz" opt
do
  case $opt in
    b ) RESUME=""
	envvars
	#[[ ${OS} != "Linux" ]] && shutdown_srp
        [[ ${OS} != "Linux" ]] && init_tar
        extract_tar
        move_dirs
        copy_files
        rem_files
	check_ia
        init_image
        compress_image
        ;;
    e ) RESUME="Resuming with the extraction of the tar file for the containerized area...\n"
	envvars
	extract_tar	# starting point begins with the extraction of the tar file for the contanerized environment
        move_dirs
	copy_files
	rem_files
	check_ia
	init_image
	compress_image
	;;
    m ) RESUME="Resuming with moving dev-hp9000 and sbin-hp9000...\n"
	envvars
	move_dirs	# starting point begins with moving [dev|sbin]-hp9000 to [dev|sbin]
        copy_files
        rem_files
	check_ia
        init_image
        compress_image
        ;;
    c ) RESUME="Resuming with copy certain files from the HP9000-Containers area...\n"
	envvars
	copy_files	# starting point begins with copying certain file from the HP9000-Containers area
        rem_files
	check_ia
        init_image
        compress_image
        ;;
    r ) RESUME="Resuming with the removal of unneeded IA64 executables...\n"
	envvars
	rem_files	# starting point begins with the removal of unneeded IA64 executables
	check_ia
        init_image
        compress_image
        ;;
    v ) RESUME="Resuming with the validation process (no more IA64 executables)...\n"
	envvars
	check_ia	# starting point begins with the validation process (no more IA64 executables)
	init_image
	compress_image
	;;
    i ) RESUME="Resuming with the creation of the Ignite archive image...\n"
	envvars
	init_image	# starting point begins with creating the Ignite archive image
	compress_image
	;;
    z ) RESUME="Resuming with the compression (gzip) of the Ignite archive image...\n"
	envvars
	compress_image	# starting point begins with the compression (gzip) of the Ignite archive image
	;;
    * ) ${ECHO} "\nusage: prep_container [ -b | -e | -m | -c | -r | -v | -i | -z ]\n"
  esac
done
