#!/usr/bin/perl

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

# ###########################################################################
#
# modifyKioskControl
#
# Modifies the existing kioskControl.dat file for the system.
# Removes the copy link and replaces it with the 'Close Kiosk'
# link for the menu.
#
# Usage: modifyKioskControl -i input-file
# Interface: Solaris 8 Kiosk
# /sbin/modifyKioskControl (in mini-root)
#
# ###########################################################################

#######################
#### Initialize    ####
#######################

### Includes
require "getopts.pl";

### Pull in the arg
&Getopts("i:");

### Variables
local($inputFile) = "";
local($tempFile)	= "/tmp/kioskControl.tmp";

### Test for input
if ($opt_i) {
	$inputFile = $opt_i;
	## open(INPUT, $inputFile) || die "$0: Can't open the file $inputFile: $!\n";
	open(INPUT, $inputFile) || die "$0: Can't open the file $inputFile: $!\n";
	open(OUT, ">" . $tempFile) || die "$0: Can't open the file $tempFile: $!\n";
} else {
	die "Usage: $0 -i <input-file>\n";
}


#######################
#### Header Info   ####
#######################
eval 'sub INSTALL_PATTERN {
	\'<MSG_installKiosk\'
}';

eval 'sub CLOSE_KIOSK_PATTERN {
        "<MSG_Close,function:closeKiosk,,no"
}';


#######################
#### Program Flow  ####
#######################
&ModifyFile();
&CleanUp();

### If we are here, return success
&ReturnSuccess();

################################
###     Program Functions    ###
################################

##############################################################################
###
###  ModifyFile
###    Modifies <OUT> and spits our to <OUTPUT>.
###
###  Parameters
###    None.
###
###  Returns
###    Nothing.
###
##############################################################################
sub ModifyFile() {
	### Set up vars
	local($inputText) = "";
	local($installPattern) = &INSTALL_PATTERN;
	local($closePattern) = &CLOSE_KIOSK_PATTERN;
	
	### Read in the file one line at a time
	### and look for the lines we need and
	### replace them.
	while (<INPUT>) {
		
		
		### If we see the line we are looking for
		### next out of here....
		if ($_ =~ /$installPattern/i) {
			next;
		} else {
			### We obviously are not the line
			### so send it to the temp file
			print(OUT $_);
		}
	}
	
	### Now add the CLOSE_KIOSK line we need 
	### at the eng....
	print(OUT $closePattern . "\n");

} ### ModifyFile()




##############################################################################
###
###  CleanUp
###    Closes the input and output files.
###
###  Parameters
###    None.
###
###  Returns
###    Nothing.
###
##############################################################################
sub CleanUp {
	### Closes up and cleans up files
	close(INPUT);
	close(OUT);
} ### CleanUp()   


sub ReturnSuccess {
	### Return a success number
	1;
} ### ReturnSuccess()











