#!/bin/ksh

#
# Copyright 2000 Sun Microsystems, Inc. All Rights Reserved
#

# ###########################################################################
#
# installKiosk
#
# Installs the Solaris 8 Kiosk onto the final system to be accessed
# by the user. Installs it to (/a/var/sadm/webstart/kiosk).
#
# This should be called last as to be sure that the system is done
# being installed and the right parent dirs have been created
#
# Usage: installKiosk [ $TARGET_DIR ]
# Interface: Solaris 8 Kiosk
# /sbin/installKiosk (in mini-root)
#
# ###########################################################################

### Vars
WEBSTART_DIR=/webstart
KIOSK_DIR=/webstart/kiosk
KIOSK_CONTROL_DIR=/webstart/kiosk/kioskControl
KIOSK_CONTROL_FILE=/webstart/kiosk/kioskControl/kioskControl.dat
TMP_KIOSK_CONTROL=/tmp/kioskControl.tmp
COPY_DIR=/a/var/sadm/webstart

# ##########################################################################
#
# Functions
#
# ##########################################################################
ScriptDie () {
	echo "installKiosk failed: $1\n"
	exit 1
} ### ScriptDie()


### First we need to check to see if we need to copy 
### the kiosk over or not
if [ ! -e /tmp/.copyKiosk ]; then
	echo "Not going to install the kiosk today!\n\n"
	exit 0
fi

### Where to copy it to (/a/var/sadm/webstart/kiosk)
if [ -z $1 ]; then
	copyDir=${COPY_DIR}
else
	copyDir=$1
fi

### Now make sure that the directory exists - if not, create it
if [ ! -d $copyDir ]; then
	/usr/bin/mkdir -p $copyDir
fi

### Adjust the kioskControl.dat to remove the copy information
### and add in the close kiosk message. 
### Run the perl script to adjust this file
/sbin/modifyKioskControl -i ${KIOSK_CONTROL_FILE} || ScriptDie "Could not find ${KIOSK_CONTROL_FILE}"

### Now move the temp file into the right location
if [ -f ${TMP_KIOSK_CONTROL} ]; then
	/bin/mv ${TMP_KIOSK_CONTROL} ${KIOSK_CONTROL_FILE} || ScriptDie "Could not move ${TMP_KIOSK_CONTROL} to ${KIOSK_CONTROL_FILE}"
fi


### CD into the webstart dir
cd ${WEBSTART_DIR}

### CPIO the whole thing over now...
echo "Copying kiosk into $copyDir"
/usr/bin/find kiosk -print | /usr/bin/cpio -pdum $copyDir || ScriptDie "Could not copy over the kiosk to the destination directory."





