#!/sbin/sh
########
#  Product: Firefox
#  Fileset: All
#  preinstall
########
#
# (c) Copyright 2007, Hewlett-Packard Company
#
########

    typeset -i exitval
    SW_PATH=/usr/bin
    UTILS="/usr/lbin/sw/control_utils"
    if [[ ! -f $UTILS ]]; then
        echo "ERROR:   Cannot find $UTILS"
        exit 1
    fi
    . $UTILS
    exitval=$SUCCESS

################################################################################
# FUNCTIONS
########
# Remove_obsolete()
#
# Arg:  The argument should be the full software specification of a single
#       product or fileset to be removed.
#
Remove_obsolete()
{
    typeset sw=$1
    typeset swstatus
    typeset -i retval=0

    #swstatus=`get_install_state $sw`
    #if [[ $swstatus != 'not found' ]]

    swstatus=`swlist -l product "$sw" 2>/dev/null | grep -v '^#' | grep -v '^$' | awk '{print $1}'`
    if [[ "X$swstatus" != 'X' ]]
    then
        msg NOTE "Removing obsolete product $sw"
        swremove \
            -x autoselect_dependents=false  \
            -x enforce_dependencies=false  \
            $sw @ ${SW_ROOT_DIRECTORY} > /dev/null 2>&1
        retval=$?
        if [ $retval -ne 0 ]; then
	    msg error "Could not remove "$sw
        fi
    fi
    return $retval

}

##############################################################################
# MAIN
#    

    # Remove obsolete software structures that might be lingering on the system.
    Remove_obsolete 'Firefox,r<2.0.0.2'
    retval=$?
    [[ $exitval -ne $FAILURE && $retval -ne $SUCCESS ]] && exitval=$retval
	# Remove_obsolete has already reported an error if one occured

    # Now delete any files that may have been created at runtime by an
    # earlier release of Firefox
    rm -f \
	/opt/firefox/extensions/talkback@mozilla.org/chrome.manifest
    exit $exitval
