#!/bin/sh
# this line will be changed by the install script
# this line will be changed by the install script

# ###############################################################
# Exceed Connection Server 2008
# Copyright (c) 1997-2008 Hummingbird Ltd. All Rights Reserved.
# ###############################################################
# ecsbootstop
# $Revision: 10408 $
# ###############################################################

# Removing scripts and links from init.d

if [ ${OSTYPE:="UNKNOWN"} = "Linux" \
	-o $OSTYPE = "linux-gnu" \
	-o $OSTYPE = "linux" \
	]; then
	ECHO="echo -e"
else
	ECHO="echo"
fi
export ECHO

cd "${Installpath}/bin"

. ./sys/msg.txt

${ECHO}
${ECHO} "${BOOTSTOP_BANNER}"
${ECHO}

logfile=${Installpath}/log/${BOOT_LOGFILE}
logtemp="${logfile}.tmp"
filelist="${logfile}.lst"

if [ ! -r "${logfile}" ] ; then
	${ECHO} "${BOOT_NO_LOGFILE}"
	${ECHO} "${BOOT_STOP_ABORTING}"
	exit 1	
fi

# #################################
# Should we remove startup script ?
# #################################
${ECHO} "${BOOT_DO_BOOTSTOP_Q1}"
${ECHO} "${BOOT_DO_BOOTSTOP_Q2}"
${ECHO} "${BOOT_CONFIRM}"

read answer

if [ ! "${answer}x" = "yx" -a ! "${answer}x" = "Yx" ] ; then
	exit 0
fi

sed "1,4 d" < "${logfile}" > "${logtemp}"

if [ ! -r "${logtemp}" ] ; then
	${ECHO} "${BOOT_CANT_ACCESS}"
	${ECHO} "${BOOT_STOP_ABORTING}"
	exit 1	
fi

${ECHO}
${ECHO} "${BOOT_REMOVE_Q}"
cat "${logtemp}"
${ECHO} "${BOOTSTOP_CONFIRM}"
${ECHO} "${BOOT_CONFIRM}"

read answer

if [ ! "${answer}x" = "yx" -a ! "${answer}x" = "Yx" ] ; then
	${ECHO} "${BOOT_STOP_ABORTING}"
	rm -f "${logtemp}"
	exit 1
fi

tr -d "\n" < "${logtemp}" > "${filelist}"

if [ ! -r "${filelist}" ] ; then
	${ECHO} "${BOOT_CANT_ACCESS}"
	${ECHO} "${BOOT_STOP_ABORTING}"
	rm -f "${logtemp}"
	exit 1	
fi

# remove script(s) and links from the system
for i in `cat "${filelist}"`;
do
	rm -f "${i}"
done
rm -f "${logtemp}"
rm -f "${filelist}"
rm -f "${logfile}"

${ECHO} "${BOOT_STOP_DONE}"

exit 0
