#!/bin/ksh
#
# ident "@(#)create_arrays.ksh	1.14 02/12/04 SMI"
#
# Copyright (c) 2001 Sun Microsystems, Inc.
# All rights reserved.
#


SCRIPTDIR=/var/opt/SUNWut/kiosk/config
CONFFILE=/var/opt/SUNWut/kiosk/kiosk.conf
TMPFILE=${CONFFILE}.tmp.$$

if [ ! -f $CONFFILE ]
then
	exit 0
fi

#
# First get rid of tmp file
#
if [ -f $TMPFILE ]
then
	rm -f $TMPFILE
	echo "Removing Temporary conf file"
fi

#
# create a new tmp file
#

touch $TMPFILE
chmod 775 $TMPFILE
if [ `/usr/bin/grep -sw utadmin /etc/group` ] ;
then
	chgrp utadmin $TMPFILE
fi
#chmod +w $TMPFILE
#chmod +x $TMPFILE

#
# Strip arrays out of kiosk.conf and write output to tmp file
#

sed '/BEGINARRAYS/,/ENDARRAYS/d' $CONFFILE >> $TMPFILE

#
# Write our BEGIN/END points to tmp file
#

echo "#BEGINARRAYS HERE" >> $TMPFILE


#
# Write new arrays to temporary kiosk.conf by sourcing the app files
#

L="["
R="]"

n=0
for FILE in $(ls $SCRIPTDIR)
do
    SCRIPT=$SCRIPTDIR/$FILE
    if [ -x $SCRIPT -a ! -d $SCRIPT ]
    then

                        . $SCRIPT

			echo "appName$L$n$R=\"$name\"" >> $TMPFILE
			echo "appPath$L$n$R=\"$pathapp\"" >> $TMPFILE
			echo "appLabel$L$n$R=\"$label\"" >> $TMPFILE
			echo "appEnable$L$n$R=\"$enable\"" >> $TMPFILE
			echo "appAttribute$L$n$R=\"$attribute\"" >> $TMPFILE
		
			n=$((n+1))

    fi
done
echo "numApps=$n" >> $TMPFILE
echo "#ENDARRAYS HERE" >> $TMPFILE

#
# atomically change conf file
#
mv $TMPFILE $CONFFILE
