#! /sbin/sh
# PGP e-ppliance 2.0 Upgrade
#  
# restore
#
# PGP Security, A Network Associates Business
# Copyright (c) 1993 - 2001, Network Associates Technology, Inc.

################################################################################
# the upgrade package must reside in /var/virtmp partition
################################################################################
UPGRADEROOT=`dirname $0` 
BASENAME=`basename $0`
PWD=`pwd`
VAR_VIRTMPDEV="/dev/dsk/c0t0d0s5"

################################################################################
# change directory to upgrade source directory
################################################################################
cd ${UPGRADEROOT} > /dev/null 2>&1
if [ $? -ne 0 ]; then
	 echo "UPGRADE::ERR Failed to change directory ${UPGRADEROOT}"
	 exit 3
fi

. ./Utils.sh

mount -a > /dev/null 2>&1
TMP_DISK_PART_INFO=`df -k ${UPGRADEROOT} | grep ${VAR_VIRTMPDEV}`
TMP_DSK_DEV=`echo ${TMP_DISK_PART_INFO} | awk '{ print $1 }'`
if [ "${TMP_DSK_DEV}" != "${VAR_VIRTMPDEV}" ]; then
	 Log "UPGRADE::ERR The upgrade package must reside in ${VAR_VIRTMPDEV} partition"
	 exit 2
fi

################################################################################
# check the user permission
################################################################################
# must be the root user
USER=`/usr/ucb/whoami`
if [ "$USER" != "root" ]; then
	 Log "UPGRADE::ERR User $USER does not have the sufficient privileges"
	 Log "UPGRADE::ERR Please login as a root user"
	 exit 1
fi

################################################################################
# comfirm with the user
################################################################################
Log ""
Log "The restore will bring your previous PGP e-ppliance back"
Log "into your system. The backup and upgrade source will still"
Log "reside in /var/virtmp partition. You may issue a command "
Log "`pwd`/clean "
Log "to clean up the partition once the system boots up."
Log ""
echo "Would you like to continue? [y/n] : \c"
read foo
if [ "$foo" != "y" -a "$foo" != "Y" ]; then
	 exit 0
fi

################################################################################
# restore previous e-ppliance
################################################################################
sh ./Restore.sh

################################################################################
# finish
################################################################################
cd ${PWD}
exit 0
