#!/bin/ksh 

PATH=/usr/bin:/usr/sbin:$PATH; export PATH
PKGCOND=/usr/bin/pkgcond
LOGIN_ENTRY_NON_RE="/dev/console    0600    /dev/usb/\[0-9a-f\]\+\[.\]\[0-9a-f\]\+/\[0-9\]\+/\*"
export LOGIN_ENTRY_NON_RE
EXIT=0
no_user_aliases() {
        driver=$1
        grep "^${driver} " $ROOTDIR/etc/driver_aliases > /dev/null 2>&1

        return $?
}

CheckZones()
{
        if [ "$ROOTDIR" = "/" -a -x /usr/bin/zonename ]; then
                ZONENAME=`/usr/bin/zonename`
                if [ ${ZONENAME} = "global" ]; then
                        GLOBAL_ZONE=true
                else
                        GLOBAL_ZONE=false
                fi
        else
                # Unable to determine zone
                GLOBAL_ZONE=true
        fi
}

Execute_commands() {
  ## if grep -w ugen ${ROOTDIR}/etc/name_to_major > /dev/null 2>&1
  ## then
        ## no_user_aliases ugen || /usr/sbin/rem_drv -b "${ROOTDIR}" ugen > /dev/null 2>&1
  ## fi

  egrep -v "$LOGIN_ENTRY_NON_RE" $ROOTDIR/etc/logindevperm > /tmp/logindevperm$$
  cp -p $ROOTDIR/etc/logindevperm $ROOTDIR/etc/logindevperm.backout-$PatchNum
  mv /tmp/logindevperm$$ $ROOTDIR/etc/logindevperm


   return $EXIT
}

LocalZones () {
# commands specific to non-gloabl zones
return 0

}

ExecuteInProperEnvironment () {
   if $PKGCOND is_whole_root_nonglobal_zone > /dev/null 2>&1 ; then
       # Execute non-global whole root zone commands.
       return 0
   fi

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

   if $PKGCOND is_netinstall_image > /dev/null 2>&1 ; then
       # Execute commands applicable to patching the mini-root.
       return 0
   fi

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

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

   if $PKGCOND is_alternative_root > /dev/null 2>&1 ; then
       # Execute commands specific to an alternate root
       Execute_commands
       return $?
   fi

   if $PKGCOND is_global_zone > /dev/null 2>&1 ; then
       # In a global zone and system is mounted on /.
       Execute_commands
       return $?
   fi
   return 1
} 

if [ -x "$PKGCOND" ] ; then
   ExecuteInProperEnvironment && exit 0 || exit 1
else
   CheckZones
   if [ "${GLOBAL_ZONE}" = "true" ]; then
        Execute_commands && exit 0 || exit 1
   else
        LocalZones
   fi
fi

exit 0
