# check for root
user=`/bin/id | /usr/bin/grep root | /usr/bin/wc -l`
if [ $user -eq 0 ]; then
	echo "You must be root to execute this script."
	exit 1
fi

# stop TR if installed
/usr/bin/pkginfo -q SUNWnsmbj
if [ $? -eq 0 ]; then
    if [ -e /opt/SUNWnsm/bin/sstr_ctl ]; then
        /etc/init.d/sstrd stop
    fi
fi

# stop CS if installed
/usr/bin/pkginfo -q SUNWdm
if [ $? -eq 0 ]; then
    /etc/init.d/sscs stop
    /etc/init.d/sscs.wbem stop
    /etc/init.d/sshd stop
    os=`/sbin/uname -r`
    if [ "$os" = "5.8" ]; then
	/etc/init.d/prngd stop
    fi
fi

# stop DE if installed
/usr/bin/pkginfo -q SUNWsade
if [ $? -eq 0 ]; then
    /etc/init.d/init.ssde stop
fi

# workaround for bug 4786593 in pkgadd
pkgs="SUNWdm SUNWgre SUNWgrr SUNWgrui SUNWgrw SUNWgrwt3 SUNWnsmdb"
for apkg in $pkgs;
do
    spacefile=/var/sadm/pkg/$apkg/install/space
    if [ -f $spacefile ]; then
	/bin/rm $spacefile
    fi
done
