#!/bin/ksh -p
#
# ident "@(#)M38KioskBB.ksh	1.17 02/09/18 SMI"
#
# Copyright 2001-2002 Sun Microsystems, Inc.  All rights reserved.
#

# MODULE NAME: KioskBB
# AUTHOR     : Bob Doolittle
# DESCRIPTION: To install the kiosk bundled packages
#
# The following exported variables (initialized by the master task) are 
# available (read-only) for the module:
#
# G_PROGRAM_ID    : program name
# G_MEDIA_DIR     : pathname of the install directory on the media (CD,...)
# G_PRODUCT_DIR   : pathname of the bundles directory on the media (CD,...)
# G_ADMIN_FILE    : pathname of the admin file used by pkgadd. default provided.
# G_DEBUG         : debug on/off. Possible values "yes", "no"
# G_QUICK_INSTALL : used to force a quick install (no user inputs).
#                   possible values "yes", "no"
# G_TMP_DIR       : pathname of the temporary directory 
# G_UT_PROD_NAME  : product name
# G_UT_VERSION    : product version
# G_DAEMON_LOC    : location of OS daemon scripts
# G_LOGFILE       : pathname of the log file.
#

#
# Module developers to provide the following functions:
# Module_Init, Module_Preserve, Module_Remove, Module_Install, Module_Restore
# Module_Abort, Module_Exit
#

#
# BB_Preinstall()
#
# Description:
#    Pre-install procedure: check whether BlackBox Packages are to be installed
#
# Parameters:
#    (none)
#
# Globals used:
#    (none)

BB_Preinstall(){

   ProductMsg -n "$BB_PROD_NAME $BB_VERSION"

   if [[ $_SW_INSTALLED = "yes" ]]; then
      print installed
#
# remove old instance of BlackBox
# XXX possible future optimization - check versions to see if what is installed
# XXX is the same as what is in the package and if so skip remove/install.
#
      _DO_REMOVE="yes"
   else
      print "not installed"
   fi

   _DO_INSTALL="yes"

   if [[ $_SW_INSTALLED = "yes" ]]; then
	AddPostInitMessage \
            "Upgrade\t [ $BB_PROD_NAME $INSTALLED_VERSION to $BB_VERSION  ]"
   else
      AddPostInitMessage "Install\t [ $BB_PROD_NAME $BB_VERSION ]"
   fi

   return 0
}

#
# BB_Preremove()
#
# Description:
#    Pre-install procedure: check whether BlackBox Packages have to be removed
#
# Parameters:
#    (none)
#
# Globals used:
#    (none)

BB_Preremove(){ 
     if [[ $_SW_INSTALLED = "yes" && $_SW_COMPATIBLE = "yes" ]]; then
         _DO_REMOVE="yes"
         AddPostInitMessage "Remove\t [ $BB_PROD_NAME $INSTALLED_VERSION ]"
         return 0
     fi
     Note "No $BB_PROD_NAME packages installed." 
}

#
# Module_Init()
#
# Description:
#   initialization of the module for installation, uninstallation
#
# Parameters:
#   (none)
#
# Globals used:
#

Module_Init() {
  typeset exit_no="0"

  _SW_INSTALLED="no"

  if AnyPackageInstalled $BB_PKG_LIST; then
     _SW_INSTALLED="yes"
     _SW_COMPATIBLE="yes"

     if pkginfo -q SUNWutkio; then
        INSTALLED_VERSION=$(pkgparam SUNWutkio VERSION | cut -d_ -f1)
     fi
  fi
 
  if IsInstallRequired; then
     BB_Preinstall
     exit_no=$?

  elif IsUninstallRequired; then
     BB_Preremove
     exit_no=$?
  fi

  return $exit_no
}

#
# Module_Preserve()
#
# Description:
#   
#
# Parameters:
#   (none)
#
# Globals used:
#

Module_Preserve() {

   return 0
}

#
# Module_Remove()
#
# Description:
#    Remove Controlled Access Mode Packages
#
# Parameters:
#   (none)
#
# Globals used:
#

Module_Remove() {

  RemoveMsg "$BB_PROD_NAME" "$INSTALLED_VERSION"

  if ! RemoveProduct $G_ADMIN_FILE $BB_PKG_RLIST; then
     Note "$BB_PROD_NAME not successfully removed"
     return 1
  fi

  return 0

}

#
# Module_Install()
#
# Description:
#    To install Controlled Access Mode Packages
#
# Parameters:
#   (none)
#
# Globals used:
#

Module_Install() {

  typeset vflag=""

  if [[ $G_DEBUG = "yes" ]]; then
     vflag="-v"
  fi

  InstallMsg "$BB_PROD_NAME" "$BB_VERSION"

  # cleanup old instances
  RemoveProduct $G_ADMIN_FILE $BB_PKG_RLIST || \
    Error "failed to completely remove $BB_PROD_NAME"

  pkgadd $vflag -a $G_ADMIN_FILE -d ${BB_DIR}/Packages $BB_PKG_LIST

  if ! ProductInstalled $BB_PKG_LIST || \
       ProductPartiallyInstalled $BB_PKG_LIST; then
      Error "$BB_PROD_NAME not successfully installed"
   fi

   return 0
}

#
# Module_Restore()
#
# Description:
#    Restore saved configuration data
#
# Parameters:
#   (none)
#
# Globals used:
#

Module_Restore() {

   return 0
}

#
# Module_Abort()
#
# Description:
#    Abort procedure
#
# Parameters:
#   (none)
#
# Globals used:
#

Module_Abort() {

   return 0
}

#
# Module_Exit()
#
# Description:
#    Exit procedure (normal termination)
#
# Parameters:
#   (none)
#
# Globals used:
#

Module_Exit() {

   return 0

}

#
# END
#

#
# MAIN STARTS HERE
#

trap "exit 2" HUP INT QUIT TERM

#
# include libraries
#

. ${G_MEDIA_DIR}/support_lib/iu_lib
. ${G_MEDIA_DIR}/support_lib/module_lib
. ${G_MEDIA_DIR}/support_lib/upgrade_lib

export _EVENT=$1
export _MODULE_NAME=$(basename $0)
export _VARS_LIST=""
export _EXIT_CODE=0
export _RETURN_VAL=0
export _VAR_STORAGE_FILE="${G_TMP_DIR}/.${G_PROGRAM_ID}.${_MODULE_NAME#???}"

DeclareModuleVar _DO_INSTALL="no"
DeclareModuleVar _DO_REMOVE="no"
DeclareModuleVar _SW_INSTALLED="no"
DeclareModuleVar _SW_COMPATIBLE="yes"

#
# BEGIN: Developers module variables definition here
#

typeset -r BB_PROD_NAME="Controlled Access Mode"
typeset -r BB_DIR="${G_PRODUCT_DIR}/Controlled_Access_Mode_2.0/Solaris_8+"

typeset -r BB_PKG_LIST="SUNWbbchr"
typeset -r BB_PKG_RLIST="SUNWbbchr"
typeset -r BB_VERSION="2.0"

DeclareModuleVar INSTALLED_VERSION=""

#
# END
#

#
# FRAMEWORK CODE 
#

. ${G_MEDIA_DIR}/support_lib/framework_lib
