# start: $Id: rfpadminuninstall.app,v 1.5.6.1 2004/08/12 09:12:43 jeremyc Exp $

# start: $Id: rfpadminroutines.app,v 1.1.6.2 2004/08/12 15:26:59 jeremyc Exp $
test `uname -s` = Linux && echocmd="echo -e" || echocmd="echo"
trap '' 2
INDENT="   "  
yorn ()
{
   YN=b
   while [ "$YN" != "n" -a "$YN" != "no" -a \
           "$YN" != "N" -a "$YN" != "NO" -a \
           "$YN" != "y" -a "$YN" != "yes" -a \
           "$YN" != "Y" -a "$YN" != "YES" -a \
           "$YN" != "Yes" -a "$YN" != "No" ]; do
      $echocmd $1
      read YN
      if [ "$YN" = "y" -o "$YN" = "yes" -o "$YN" = "Yes" -o \
           "$YN" = "Y" -o "$YN" = "YES" ]; then
         return 1
      fi
      if [ "$YN" = "n" -o "$YN" = "no" -o "$YN" = "No" -o \
           "$YN" = "N" -o "$YN" = "NO" ]; then
         return 0
      fi
      $echocmd "Please enter y or n"
   done
}
log()
{
   DATE=`date`
   $echocmd "${DATE}: $1" >>$COBDIR/fixpacks/install.log
}
getallfpdetails()
{
   _FPS=`grep '^PTI=.*pack' $COBDIR/etc/cobver | sed -e 's/^PTI=//' -e 's/ committed$//' | tr '\n' ' '`
   COUNT=0
   COMMITTED_COUNT=0
   FPS_DETAILS=""
   for _FP in $_FPS ; do
      COUNT=`expr $COUNT + 1`
      grep "^PTI=$_FP committed" $COBDIR/etc/cobver > /dev/null
      if [ $? -eq 0 ]; then
         FPS_DETAILS="${FPS_DETAILS}:${COUNT}-${_FP}-committed"
         COMMITTED_COUNT=`expr $COMMITTED_COUNT + 1`
      else
	 FPS_DETAILS="${FPS_DETAILS}:${COUNT}-${_FP}-no"
      fi
   done
}
searchfpdetails()
{
   _ID=$1
   for _FP in `echo $FPS_DETAILS | sed 's/:/ /g'` ; do
      ID=`echo $_FP | cut -d'-' -f1`
      NAME=`echo $_FP | cut -d'-' -f2`
      COMMITTED=`echo $_FP | cut -d'-' -f3`
      [ "$ID" = "$_ID" ] && return 0 ;# success
   done
   return 1 ;# failure
}
MFADMIN=$1
exitmenu()
{
   if [ "x$MFADMIN" != "x" ]; then
      $echocmd "Press Return to continue."
      read _TMP
   else
      $echocmd "exiting ..."
   fi
   exit 0
}
contmenu()
{
   $echocmd "Press Return to continue."
   read _TMP
}
if [ ! -w /etc/passwd ]; then
   $echocmd "*** You must be root to run this script."
   $echocmd "exiting ..."
   exit 1
fi
if [ ".$COBDIR" = "." ] || [ ! -f $COBDIR/etc/cobver ]; then
   $echocmd "*** COBDIR must be set to point to a valid product."
   $echocmd "exiting ..."
   exit 1
fi
# end: $Id: rfpadminroutines.app,v 1.1.6.2 2004/08/12 15:26:59 jeremyc Exp $

uninstallfixpack()
{
   _NAME=$1
   _SCRIPT="$COBDIR/fixpacks/$_NAME/${_NAME}-uninstall"
   if [ -f $_SCRIPT ]; then
      clear
      sh $_SCRIPT
      return 0 ;# success
   else
      $echocmd "\n*** No such script: $_SCRIPT"
      return 1 ;# failure
   fi
}

displaycobdir()
{
   cat <<END

COBDIR is set to $COBDIR
END
}

while [ 1 ]; do
   clear
   cat <<END

           Uninstall a Pack

END
   getallfpdetails
   if [ $COUNT -eq 0 ]; then
      $echocmd "\n*** No Packs are currently installed."
      exitmenu
   fi
   $echocmd "The following Packs are currently installed:"
   I=0
   while [ $I -lt $COUNT ]
   do
      I=`expr $I + 1`
      searchfpdetails $I
      [ "$COMMITTED" = "no" ] && COMMITTED=""
      cat <<END
           ${NAME} ${COMMITTED}
END
   done
   $echocmd "\nOnly the last installed Pack can be uninstalled."
   searchfpdetails $COUNT
   if [ $COMMITTED = "committed" ]; then
      $echocmd "\n*** $NAME cannot be uninstalled because it has been committed."
   else
      yorn "Do you want to uninstall $NAME ? (y/n): \c"
      if [ $? -eq 1 ]; then
         uninstallfixpack $NAME
      else
	 exit 0
      fi
   fi
   exitmenu
done
# end: $Id: rfpadminuninstall.app,v 1.5.6.1 2004/08/12 09:12:43 jeremyc Exp $
