#!/bin/tcsh
#
#	vi: set autoindent tabstop=4 shiftwidth=4 :
#
#	target-reg-slp
#
#	Start slpd deamon if it not up. Use file "slp-target-reg"
#	as the registration file for target service. Restart slpd
#	if there is an command argument used to run this script.
#
#
#	Copyright (C) 2001-2003 InterOperability Lab (IOL)
#							University of New Hampshier (UNH)
#							Durham, NH 03824
#
#	This program is free software; you can redistribute it and/or modify
#	it under the terms of the GNU General Public License as published by
#	the Free Software Foundation; either version 2, or (at your option)
#	any later version.
#
#	This program is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU General Public License for more details.
#
#	You should have received a copy of the GNU General Public License
#	along with this program; if not, write to the Free Software
#	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
#	USA.
#
#	The name of IOL and/or UNH may not be used to endorse or promote products
#	derived from this software without specific prior written permission.
#

set regFile = "slp-target-reg"
cat <<end > $regFile
service:iscsi:target://`echo $HOSTNAME`:3260/iqn.2002-10.edu.unh.iol.iscsi.draft18-target:0,en,65535
iscsi-name=iqn.2002-10.edu.unh.iol.iscsi.draft18-target:0
alias=jaguar
auth-name=iqn.edu.unh.initiator.tweety,iqn.edu.unh.initiator.diana
auth-addr=192.1.1.5
auth-cred=chap/none
end

#check if /var/run/slpd.pid is there 
test -f /var/run/slpd.pid
if ( $status == 0 ) then 
	#check if the slpd is active or not 
	set pid = `cat /var/run/slpd.pid`
	set lines = `ps -p $pid | grep slpd | wc -l`
	if ( $lines == 1 ) then
		#check if there is an option to restart the slpd
		if ( $# != 0 ) then 
			kill $pid
			echo "stop slpd $pid"
			echo 
			/usr/sbin/slpd -r $regFile
			echo "restart slpd with the register file '$regFile' "  
		endif
	else
		/usr/sbin/slpd -r $regFile
		echo "start slpd with the register file '$regFile' "
	endif
else
#start the slpd with the register file
	/usr/sbin/slpd -r $regFile
	echo "start slpd with the register file '$regFile' "
endif
