#! /usr/bin/sh # # ident "%Z%%M% %I% %E% SMI" # # Copyright 2005 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # #DEBUG=1 # ### # There are 2 command line options that can be used when running this # script: # -debug - Prints out debug text from this script and the java application # -delay XX - Set the sleep or delay time in the java application. This # is the amount of time that the notification app waits before # determining if their are new updates available and that the # icon needs to change. The value (XX) is in seconds ### ### # Determining if running in the global zone. If not exit, ### CheckZones() { ZONENAME=/usr/bin/zonename if [ -f ${ZONENAME} ] ; then if [ `${ZONENAME}` != "global" ]; then echo "Update Manager Notification is only supported in the global zone. Exiting..." logger -tswupnot -p2 "Non global zone not supported. zone: $ZONENAME. Exiting" exit 1 fi fi } # Update Manager Notification app will only run in the global zone CheckZones ### # setup LD_LIBRARY_PATH ### if [ $LD_LIBRARY_PATH ] ; then LD_LIBRARY_PATH=/usr/lib/patch/jdic:${LD_LIBRARY_PATH} else LD_LIBRARY_PATH=/usr/lib/patch/jdic fi export LD_LIBRARY_PATH # # The following env variable is set in response to CR 6321362 # NO_J2D_DGA=true export NO_J2D_DGA if [ $DEBUG ] ; then echo LD_LIBRARY_PATH=${LD_LIBRARY_PATH} fi DISABLE_NOTIFICATION=disableNotification SOFTWARE_UPDATE=.softwareupdate DELAY=delay PID_FILE=pid JAVA_EXEC="/usr/jdk/latest/bin/java -version:1.5+" CCR_EXEC=/usr/lib/cc-ccr/bin/ccr MKDIR_EXEC="/usr/bin/mkdir -p" PS_EXEC=/usr/bin/ps GREP_EXEC=/usr/bin/grep AWK_EXEC=/usr/bin/awk CAT_EXEC=/usr/bin/cat WHOAMI=/usr/ucb/whoami MV_EXEC=/usr/bin/mv ### # ---- find any running process that matches the input # parameter, and that is a notification app. ### findNotAppProc() { pid=`$PS_EXEC -ef | $GREP_EXEC -w $1 | $GREP_EXEC -v grep | $GREP_EXEC -w swupna.jar` echo $pid } ### # ---- find the named process(es) ### findProc() { pid=`$PS_EXEC -ef | $GREP_EXEC -w $1 | $GREP_EXEC -v grep | $AWK_EXEC '{print $2}'` echo $pid } ### # ---- find any running process that matches the input # parameter, and that is owned by this userid. ### findUserIdProc() { who=`$WHOAMI` pid=`$PS_EXEC -ef | $GREP_EXEC -w $1 | $GREP_EXEC -v grep | $GREP_EXEC -w $who` echo $pid } ### # ---- check for already running notification app process for this user ---- # return 0 - 'running swupnot process found' # 1 - 'NO running swupnot process found' ### checkRunningNotApp() { if [ -f ${HOMEDIR}/${PID_FILE} ]; then if [ $DEBUG ] ; then echo "checkRunningNotApp: HOMEDIR=$HOMEDIR" fi ### # get the process id saved in the 'pid' file. if 'pid' file # does not exist than no need to check any further, return 1 # to indicate 'not found' ### SAVE_PID=`$CAT_EXEC $HOMEDIR/$PID_FILE` if [ $? != 0 ] then echo "cannot find $HOMEDIR/$PID_FILE file" >> $TRC_FILE rc=1 return fi if [ $DEBUG ] ; then echo "SAVE_PID=$SAVE_PID" fi ### # get the process id of any running notification app process, # if no process id is found, than no need to check any further, # return 1 to indicate 'NO running swupnot process found' ### found_pid=`findNotAppProc $SAVE_PID` echo "search and found swupnot pid=$found_pid" >> $TRC_FILE if [ "$found_pid" != "" ] ; then echo "found swupnot process" >> $TRC_FILE rc=0 # found the running process else echo "does not find any swupnot process" >> $TRC_FILE rc=1 fi ### # there is no pid file found, return 1 (no swupnot found). ### else echo "pid file does not exist" >> $TRC_FILE rc=1 fi } ### # ---- Check for negative assetid, if it is, replace leading "-" with "N". ### checkNegAssetId() { GDIR=`echo $ASSETID | sed -e "s/^-/N/"` if [ $DEBUG ] ; then echo "here is the fixed name: $GDIR" fi } ### # ---- Check for the existence of an X Atom (GNOME_SM_DESKTOP) which # indicates that the user is running JDS. If they are, then # start the notification application. If no such atom # exists, we could be in the CDE window environment so quit. ### checkPreReq() { ### # ---- check for GNOME environment ### gnome_atom="" if [ -x /usr/openwin/bin/xlsatoms ]; then gnome_atom=`/usr/openwin/bin/xlsatoms | grep GNOME_SM_DESKTOP` fi if [ "$gnome_atom" = "" ] ; then echo "Notification Application cannot run: User is not running " >> $TRC_FILE echo " in the GNOME environment." >> $TRC_FILE echo "Notification Application cannot run: User is not running " echo " in the GNOME environment." exit 1 fi ### # Now make sure notification-area-applet is running ### timeout=1 while [ $timeout -le 60 ]; do gpid=`findUserIdProc notification-area-applet` if [ $DEBUG ] ; then echo "gpid=$gpid" fi if [ "$gpid" = "" ] ; then sleep 1 timeout=`(expr $timeout + 1)` else timeout=71 fi done if [ $timeout -eq 61 ]; then echo "Notification Application cannot run: User is not running " >> $TRC_FILE echo " the notification-area-applet." >> $TRC_FILE echo "Notification Application cannot run: User is not running " echo " the notification-area-applet." exit 0 fi ### # If started with the -wait option (which is used when swupnot # is launched when the user logs in to their gnome desktop), # wait and additional time to make sure that the notification-area-applet # is initialized and ready to run. This is done so that when the # notification icon is added to the system tray (in the java code), # the notification-area-applet is fully initialized and ready to # handle the request. ### if [ "$1" = "-wait" ] || [ "$2" = "-wait" ] || [ "$3" = "-wait" ]; then sleep 20 fi } ### # If started with the -wait option (which is used when swupnot is launched # when the user logs in to their gnome desktop), wait to make sure that # gnome session is started. This is done to give the desktop initialization # time to set the GNOME X atom so that the xlsatoms done in this script # will find that GNOME X atom set. ### if [ "$1" = "-wait" ] || [ "$2" = "-wait" ] || [ "$3" = "-wait" ]; then sleep 20 fi if [ "$1" = "-debug" ] || [ "$2" = "-debug" ] || [ "$3" = "-debug" ]; then DEBUG=1 fi if [ $DEBUG ] ; then echo "home = $HOME" fi # # CR 6431846 - don't proceed with starting notification icon if UM # auto analysis is disabled UMAUTOANAL=`$CCR_EXEC -g cns.swup.autoAnalysis.enabled` if [ "$UMAUTOANAL" = "false" ]; then if [ $DEBUG ]; then echo "cns.swup.autoAnalysis.enabled is false, Notification exiting..." fi exit 0; fi who=`$WHOAMI` TRC_FILE="/tmp/${who}swup.trc" if [ $DEBUG ] ; then echo "tracefile=$TRC_FILE" fi ##### # ---- read the assetId and use it to build the softwareupdate path ##### ## # TODO need to check for CCR package installed? ## rm -f $TRC_FILE HOSTID=`/usr/bin/hostid` ASSETID=`$CCR_EXEC -g cns.assetid` HOSTIDHOMEDIR="" if [ $DEBUG ] ; then echo "$ASSETID" fi ### # build the home directory for this user. ### if test $ASSETID ; then # if negative, replace '-' with 'N' GDIR="" checkNegAssetId if [ $DEBUG ] ; then echo "after checkNegAssetId(), gdir=$GDIR" fi HOMEDIR=${HOME}/${SOFTWARE_UPDATE}/${GDIR} HOSTIDHOMEDIR=${HOME}/${SOFTWARE_UPDATE}/${HOSTID} echo "user is registered" >> $TRC_FILE else HOMEDIR=${HOME}/${SOFTWARE_UPDATE}/${HOSTID} echo "user is not registered" >> $TRC_FILE fi echo "HOMEDIR=$HOMEDIR" >> $TRC_FILE ### # ----- if this user's home directory does not exists, create it # If the directory is based on the assetid, move any files # that are in the hostid based subdirectory into this new directory ### if [ ! -d ${HOMEDIR} ]; then $MKDIR_EXEC $HOMEDIR echo "HOMEDIR=$HOMEDIR did not exist" >> $TRC_FILE if [ "$HOSTIDHOMEDIR" != "" ] ; then if [ -d ${HOSTIDHOMEDIR} ]; then $MV_EXEC $HOSTIDHOMEDIR/* $HOMEDIR echo "Moved files from $HOSTIDHOMEDIR to $HOMEDIR directory" >> $TRC_FILE fi fi fi ### # ----- check for disable not app file # if present but empty, don't run app # if present but not empty (contains false), run app # if not present check $DISPLAY, run if local # in this case, create the disableNotification file and write "false" # into it ### if [ -s ${HOMEDIR}/${DISABLE_NOTIFICATION} ]; then runapp=true elif [ -f ${HOMEDIR}/${DISABLE_NOTIFICATION} ]; then runapp=false else case "$DISPLAY" in :0*) runapp=true ; echo "false" > "$HOMEDIR/$DISABLE_NOTIFICATION" ;; *) runapp=false ; echo "The Notification Application cannot run." >> $TRC_FILE ; echo "User is not running on the primary display" >> $TRC_FILE ; echo "or is running remotely." >> $TRC_FILE ; echo "The Notification Application cannot run." ; echo "User is not running on the primary display" ; echo "or is running remotely." ; exit 0 ;; esac fi if $runapp; then echo "disable notification flag is off" >> $TRC_FILE ### # ---- check for any already running notification apps for # this user. ### rc=0 checkRunningNotApp echo "checkRunningNotApp return $rc" >> $TRC_FILE if [ $rc -eq 1 ] ; then echo "NO running NotApp process found" >> $TRC_FILE ### # ---- check for gnome desktop and notification-area-applet ### checkPreReq echo "gnome is ready" >> $TRC_FILE ### # ---- start Notification Application ### if [ -f ${HOMEDIR}/${DELAY} ]; then $JAVA_EXEC -jar /usr/lib/patch/swupna.jar -delay 6 "$@" & else $JAVA_EXEC -jar /usr/lib/patch/swupna.jar "$@" & fi echo "NotApp is started" >> $TRC_FILE ### # --- save the process id into the 'pid' file. ### echo $! > "$HOMEDIR/$PID_FILE" echo "saved pid" >> $TRC_FILE else echo "The Sun Notification Application is already running on " >> $TRC_FILE echo "the system for this user." >> $TRC_FILE echo "The Sun Notification Application is already running on " echo "the system for this user." fi ### # ----- if 'disable notification app' flag is on, cannot start Not Apps. ### else echo "disable notification flag on, cannot start NotApp" >> $TRC_FILE echo "don't start NotApp and quits now" >> $TRC_FILE echo "The Sun Notification Application is disabled, To enable it," echo " use the Preferences menu in the Sun Update Manager." fi exit 0