#!/bin/sh
# initqx: initialize queuing system 
# (this does not load the software, but it does
#  make QX 2.0 start up and shut down automatically)
# kh	version 2.0	9 September 1993
# kh	version 2.1	9 November 1993 	postpone execution of qx startup

LINE1="qx		1886/tcp			# QX 2.0 QUEUING SYSTEM"
LINE2="grunt		1887/tcp			# QX 2.0 QUEUING SYSTEM, TEST PURPOSES"
QX="/bg/gen/local/com/qx"

# must be root

id | cut -d' ' -f1 | grep root >/dev/null
if [ $? -ne 0 ]
    then    echo "initqx: must be super-user"; exit 1
fi

# how to append a line to the end of a file,
# if it is not yet there
append() {
	grep "$1" $2 >/dev/null
	if [ $? -ne 0 ]
	then 	if [ ! -f $2.ORG ]
		then	cp $2 $2.ORG
		fi
		echo "$1" | cat - >>$2
	fi
}

# edit /etc/services
append "$LINE1" /etc/services
append "$LINE2" /etc/services

# put qx in its place 

cp $QX /etc/init.d
chmod 755 /etc/init.d/qx

# remove old (pre-version 2.1) link
test -l /etc/rc2.d/S00qx && rm /etc/rc2.d/S00qx

# (if links were already laid,
#  hush up the complaints)
ln -s /etc/init.d/qx /etc/rc0.d/K00qx >/dev/null 2>&1
ln -s /etc/init.d/qx /etc/rc2.d/S47qx >/dev/null 2>&1
if [ -x v-land ]; then if v-land
	then ln -s /etc/init.d/qx /etc/rc1.d/K00qx >/dev/null 2>&1
fi; fi
