File: //usr/openv/pdde/pdag/scripts/pddeuninstall.sh
#!/bin/sh
###########################################################
# This script removes the PDDE server and agent packages
###########################################################
# Copyright (C) 2012 Symantec
# All Rights Reserved
#
# THIS SOURCE CODE IS AN UNPUBLISHED PROPRIETARY TRADE SECRET OF
# Symantec
#
# The copyright notice above does not evidence any actual or intendent
# publication of such source code.
#
#########################################################################
PDE_FULL_NAME="Veritas NetBackup PureDisk Deduplication Engine"
OS=`uname -s`
# Remove group and world writable permissions
umask 0022
TIMESTAMP=`date +%F_%H:%M`
LOGDIR="/var/log/puredisk"
if [ ! -d "${LOGDIR}" ] ; then
mkdir -p ${LOGDIR}
fi
LOGFILE=${LOGDIR}/${TIMESTAMP}-pdde-uninstall.log
INSTALL_PATH="/usr/openv/pdde"
OSTPLUGINS_PATH="/usr/openv/lib/ost-plugins"
forceclean=0
noscripts=0
verbose=0
TIMESTAMP=`date +%F_%H:%M`
mkdir -p `dirname ${LOGFILE}`
cd `dirname $0`
helptext () {
echo "Usage: $0 [-forceclean]"
echo
echo " -forceclean : Clean everything. Do not save config files for upgrades"
exit 1
}
################################################################################
# die - Print error message and exit immediately. Second optional parameter is
# a custom return code.
################################################################################
die () {
echo
if [ "${1}" != "" ]; then
echo "ERROR: ${1}" | tee -a ${LOGFILE}
echo
fi
echo "!! PDDE-uninstallation aborted ... " | tee -a ${LOGFILE}
echo "Full PDDE uninstallation log saved to: ${LOGFILE}" | tee -a ${LOGFILE}
echo
exit 1
}
################################################################################
# queryPackage - Check if the native package is already installed on the system
################################################################################
queryPackage () {
package_name=$1
if [ "X${package_name}" = "X" ] ; then
echo "ERROR: Missing package name in queryPackage function!" | tee -a ${LOGFILE}
return 1
fi
# Build the command for the right platform
case "${OS}" in
HP*) query_cmd="swlist ${package_name}" ;;
Linux*) query_cmd="rpm -q ${package_name}" ;;
AIX) query_cmd="lslpp -l ${package_name}" ;;
SunOS) query_cmd="pkginfo ${package_name}" ;;
esac
# Query for the package!
echo >> ${LOGFILE}
echo "Checking for ${package_name} package..." | tee -a ${LOGFILE}
echo ${query_cmd} >> ${LOGFILE}
${query_cmd} >> ${LOGFILE} 2>&1
if [ $? -eq 0 ] ; then
echo " Package ${package_name} found." | tee -a ${LOGFILE}
return 0
fi
return 1
}
################################################################################
# removePackage - Uninstall the native package from the system
################################################################################
removePackage () {
package_name=$1
if [ "X${package_name}" = "X" ] ; then
echo "ERROR: Missing package name in removePackage function!" | tee -a ${LOGFILE}
return 1
fi
# Use existing or create an admin file for removal
if [ "${OS}" = "SunOS" ] ; then
if [ -f ${INSTALL_PATH}/pdag/scripts/admin ] ; then
admin_file=${INSTALL_PATH}/pdag/scripts/admin
else
cat > /tmp/pdde_$$_admin << __EOF__
nstance=overwrite
partial=nocheck
runlevel=nocheck
idepend=nocheck
rdepend=nocheck
space=nocheck
setuid=nocheck
conflict=nocheck
action=nocheck
basedir=default
__EOF__
admin_file=/tmp/pdde_$$_admin
fi
fi
# Build the command for the right platform
case "${OS}" in
HP*)
x_parameters="-x mount_all_filesystems=false -x enforce_dependencies=false"
check_for_HP_container
if [ $? -eq 1 ] ; then
x_parameters="${x_parameters} -x global_srp=true"
fi
rm_cmd="swremove ${x_parameters} ${package_name}"
;;
Linux*) rm_cmd="rpm -vv -e --nodeps ${package_name}" ;;
AIX) rm_cmd="installp -u ${package_name}" ;;
SunOS) rm_cmd="pkgrm -n -a ${admin_file} ${package_name}" ;;
esac
# Remove the package!
echo >> ${LOGFILE}
echo "Removing ${package_name} package..." | tee -a ${LOGFILE}
echo ${rm_cmd} >> ${LOGFILE}
${rm_cmd} >> ${LOGFILE} 2>&1
if [ $? -eq 0 ] ; then
echo " Package ${package_name} removed." | tee -a ${LOGFILE}
else
echo "ERROR: Removal of package ${package_name} was unsuccessful!" | tee -a ${LOGFILE}
return 1
fi
# Clean up created admin file
if [ "${OS}" = "SunOS" -a -f /tmp/pdde_$$_admin ] ; then
rm -f /tmp/pdde_$$_admin
fi
return 0
}
################################################################################
# check_for_HP_container is used to figure out if
# the host is a container on an HP Itanium machine.
# We will not install unless it is the global
# container. The caller will issue an abort message
# if necessary or add the required parameter
# to swinstall or swremove if it is global.
#
# This should only be called for HP Itanium machines.
#
# return 0 if no HP containers configured (normal)
# return 1 if in an HP container and it is global
# return 2 if in an HP container but it is not global
################################################################################
check_for_HP_container ()
{
# Only applies to HP Itanium machines
if [ `echo ${OS} | cut -c -2` != "HP" -o `uname -m` != "ia64" ] ; then
return 0;
fi
# Figure out if there are containers and
# if so, is this the global container.
# If getprocxsec fails, there are no containers
# set up on this machine. If it passes and
# the container name is init, it is the
# global one, else it is some type of
# SRP or workload container.
container=`getprocxsec -c 2>/dev/null`
if [ $? -ne 0 ] ; then
return 0
else
cname=`echo ${container} | cut -f2- -d" "`
if [ "${cname}" = "init" ] ; then
return 1
else
return 2
fi
fi
}
################################################################################
# main - Time to start uninstalling!
################################################################################
main () {
if [ -f /etc/debian_version ]; then
exit 0
fi
echo "Uninstalling PDDE..." >> ${LOGFILE}
echo " Force clean: ${forceclean}" >> ${LOGFILE}
echo " Install path: ${INSTALL_PATH}" >> ${LOGFILE}
echo " OST-Plugins path: ${OSTPLUGINS_PATH}" >> ${LOGFILE}
echo " NoScripts: ${noscripts}" >> ${LOGFILE}
if [ -f ${INSTALL_PATH}/pdag/version.txt ] ; then
OLD_VERSION=`cat ${INSTALL_PATH}/pdag/version.txt`
fi
rm -rf /tmp/PDDE_SKIP_PACKAGE_SCRIPTS
if [ ${noscripts} -eq 1 ] ; then
echo "Disabling native package scripts" | tee -a ${LOGFILE}
touch /tmp/PDDE_SKIP_PACKAGE_SCRIPTS
fi
queryPackage SYMCpddes
if [ $? -eq 0 ] ; then
removePackage SYMCpddes
if [ $? -ne 0 ] ; then
rm -rf /tmp/PDDE_SKIP_PACKAGE_SCRIPTS
die "Failed to remove SYMCpddes!"
fi
fi
queryPackage VRTSpddes
if [ $? -eq 0 ] ; then
removePackage VRTSpddes
if [ $? -ne 0 ] ; then
rm -rf /tmp/PDDE_SKIP_PACKAGE_SCRIPTS
die "Failed to remove VRTSpddes!"
fi
fi
queryPackage SYMCpddea
if [ $? -eq 0 ] ; then
removePackage SYMCpddea
if [ $? -ne 0 ] ; then
rm -rf /tmp/PDDE_SKIP_PACKAGE_SCRIPTS
die "Failed to remove SYMCpddea!"
fi
fi
queryPackage VRTSpddea
if [ $? -eq 0 ] ; then
removePackage VRTSpddea
if [ $? -ne 0 ] ; then
rm -rf /tmp/PDDE_SKIP_PACKAGE_SCRIPTS
die "Failed to remove VRTSpddea!"
fi
fi
rm -rf /tmp/PDDE_SKIP_PACKAGE_SCRIPTS
if [ ${forceclean} -eq 0 ] ; then
if [ -f /etc/pdregistry.cfg ]; then
echo "Moving /etc/pdregistry.cfg to /etc/pdregistry.cfg.${TIMESTAMP}" | tee -a ${LOGFILE}
mv -f /etc/pdregistry.cfg /etc/pdregistry.cfg.${TIMESTAMP}
fi
else
if [ -f /etc/pdregistry.cfg ]; then
echo "Removing /etc/pdregistry.cfg" | tee -a ${LOGFILE}
rm -f /etc/pdregistry.cfg
fi
if [ -f ${OSTPLUGINS_PATH}/pd.conf ]; then
echo "Removing ${OSTPLUGINS_PATH}/pd.conf." | tee -a ${LOGFILE}
rm -f ${OSTPLUGINS_PATH}/pd.conf
fi
fi
echo "PDDE uninstall finished successfully." | tee -a ${LOGFILE}
echo "Full PDDE uninstallation log saved to: ${LOGFILE}" | tee -a ${LOGFILE}
echo
}
while [ $# -gt 0 ]; do
case ${1} in
-forceclean) forceclean=1; shift ;;
-noscripts) noscripts=1; shift ;;
-verbose) verbose=1; shift ;;
-basedir) echo "basedir no longer needed. Ignoring..." ; shift ; shift ;;
-ostdir) echo "ostdir no longer needed. Ignoring..." ; shift ; shift ;;
*) helptext;
esac
done
main