#!/bin/ksh
#
#*******************************************************************************
#
# Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
#*******************************************************************************
#

#
## WARNING: This file must not be altered in any way.
##          Please consult your Kiosk Session Service documentation for details
##          on building your own Kiosk Sessions.
#

#
## CAM compatibility session script
#
## param session autostart file
##   a script file that can autostart the auto or critical processes when 
#
theModule=kiosk:cam-compat-session

#
## Main
##
## - Run all apps in the auto start file
## - Wait for all the apps in the autostart file to terminate
## 
## Compatibility: 
## - In CAM, at least one of the apps must be critical, 
##   so if they all have exited, at least one critical app must be gone.
## - This script, being a session, is started as a critical app. If any 
##   critical app exits, kioskcritd will kill us (and all others)
## - An invalid user/auto-only CAM applist would have terminated right away.
##   Here we differ and live on until all auto apps are gone.
##   (This does seem slightly more sensible, but we try to warn about this)
#

logger -p user.debug -t $theModule \
   "Starting CAM-Compatibility (with no dtsession) session on display '$DISPLAY'"

# Get parameters 
inAutoStartFile=$1

# This is matched in the autostart file, when looking for entries
KIOSKAPPLAUNCH_MATCH="/lib/kioskapplaunch "
# This is matched in the autostart file when looking for critical apps
KIOSKAPPLAUNCH_CRIT="${KIOSKAPPLAUNCH_MATCH}-c"

if [ ! -x "$inAutoStartFile" ] ; then
    logger -p user.error -t $theModule \
       "Auto application list file '$inAutoStartFile' not available."
    return 1   
fi

grep "$KIOSKAPPLAUNCH_MATCH" "$inAutoStartFile" > /dev/null 
if [ $? != 0 ] ; then
    logger -p user.error -t $theModule \
       "Auto application list file '$inAutoStartFile' contains no kiosk applications."
    return 1   
fi

grep "$KIOSKAPPLAUNCH_CRIT" "$inAutoStartFile" > /dev/null 
if [ $? != 0 ] ; then
    logger -p user.warn -t $theModule \
       "Unspecified behavior: Auto application list file '$inAutoStartFile' contains no critical applications!"
fi

# Run the applications
. "$inAutoStartFile"

# Wait for them
wait

