# Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
#
# ident	"@(#)144500_prepatch.sh	1.1	11/09/16 SMI"
#
# Provide fixed definitions on patchadd execution.

### BEGIN: overlay 144500-19/prepatch
if [ "${PatchNum}" = "144500-19" -a `/usr/bin/basename $0` = "prepatch" ] ; then
prepatch()
{
check_pp_compatibility_sparc() {
    pp_pkginfo="$ROOTDIR/var/sadm/pkg/EMCpower/pkginfo"
    [ -s "$pp_pkginfo" ] || return 0
    sed -n '/^PKG=/{s/^PKG=//p;q;}' "$pp_pkginfo" | read val
    [ "$val" = EMCpower ] || return 0
    sed -n '/^ARCH=/{s/^ARCH=//p;q;}' "$pp_pkginfo" | read val
    [ "$val" = sparc ] || return 0
    sed -n '/^VERSION=/{s/^VERSION=//p;q;}' "$pp_pkginfo" | read val
    patches_incompat=
    case "$val" in
        5.0.2_b030)         patches_incompat="500-022" ;;
        5.1.0_b248)         patches_incompat="510-010 510-011" ;;
        5.2.0_b146)         patches_incompat="520-010 520-020 520-022 520-023" ;;
        5.2.SP1.HF02_b003)  ;;
        5.2.SP1.HF03_b001)  ;;
        5.3.HF01_b003)      patches_incompat="530-002" ;;
        5.3.HF03_b005)      ;;
        5.3.HF04_b003)      ;;
        5.3.P01_b009)       patches_incompat="530-011" ;;
        5.3_b473)           ;;
        *)                  val= ;;
    esac
    [ -z "$val" ] && return 0
    patches_applied=`sed -n '/^PATCHLIST=/{s/^PATCHLIST=//p;q;}' $pp_pkginfo`
    for patch in $patches_applied ; do
        [[ " $patches_incompat " == *" $patch "* ]] || return 0
    done

    echo "
An incompatible version of EMC PowerPath is installed on this system,
application of the kernel patch aborting.

A fix from EMC will be required first, before this kernel patch can be
applied. For the latest information, please refer to ETA emc275344 on

  https://powerlink.emc.com
"
    return 1
}

determine_pkgcond () {
    if /usr/bin/pkgcond is_whole_root_nonglobal_zone > /dev/null 2>&1 ; then
        # Execute non-global whole root zone commands.
        return 0
    fi

    if /usr/bin/pkgcond is_nonglobal_zone > /dev/null 2>&1 ; then
        # Execute non-global zone commands. Should be no action here
        return 0
    fi

    if /usr/bin/pkgcond is_netinstall_image > /dev/null 2>&1 ; then
        # Execute commands applicable to patching the mini-root.
        # There are usually no actions to take here since your patching
        # the mini-root on an install server.
        return 0
    fi

    if /usr/bin/pkgcond is_mounted_miniroot > /dev/null 2>&1 ; then
        # Execute commands specific to the mini-root
        return 0
    fi

    if /usr/bin/pkgcond is_diskless_client > /dev/null 2>&1 ; then
        # Execute commands specific to diskless client
        return 0
    fi

    if /usr/bin/pkgcond is_alternative_root > /dev/null 2>&1 ; then
        # Execute commands specific to an alternate root
        check_pp_compatibility_sparc
        return $?
    fi

    if /usr/bin/pkgcond is_global_zone > /dev/null 2>&1 ; then
        # In a global zone and system is mounted on /.
        # Execute all commands.
        check_pp_compatibility_sparc
        return $?
    fi
    return 1
}


# as we already require patches that require 119254-51 we already have pkgcond
determine_pkgcond || exit 1

}
fi
### END: overlay 144500-19/prepatch
