#! /bin/sh -x
#
# Copyright (c) 2003-2004 Silicon Graphics, Inc.  All Rights Reserved.
# 
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
# 
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
# 
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
# 
# Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane,
# Mountain View, CA 94043, USA, or: http://www.sgi.com
#
# Post installation/upgrade script for pcp-gui
#

prog=`basename $0`
status=1
trap "exit \$status" 0 1 2 15

echo "$prog: PCP GUI for MacOSX Upgrade"

echo "$prog: Writing install log to /var/log/pcp-gui-inst.log"

if [ ! -d $2 ]
then
    echo "$prog: Unable to open directory of new files ($2)"
    exit 1
fi

cd $2

# TODO: Remove -v flag once stable
if [ -f /usr/share/pcp/bin/idb-pcp-gui ]
then
    if ./install-pcp-gui -v -u /usr/share/pcp/bin/idb-pcp-gui -l /var/log/pcp-gui-inst.log idb-pcp-gui
    then
	:
    else
	echo "$prog: Upgrade Failed"
	exit 1
    fi
else
    echo "$prog: Package detected previous install of pcp-gui but /usr/share/pcp/bin/idb-pcp-gui does not exist."
    echo "$prog: Attempting to remove existing files using new idb."
    if ./install-pcp-gui -v -r -l /var/log/pcp-gui-inst.log idb-pcp-gui
    then
	if ./install-pcp-gui -v -i -l /var/log/pcp-gui-inst.log idb-pcp-gui
	then
	    :
	else
	    echo "$prog: Install Failed"
	    exit 1
	fi
    else
	echo "$prog: Remove Failed"
	exit 1
    fi
fi

status=0
