#!/bin/sh

#
# tools/CDWserver-installer.sh
#
# Copyright (C) 2002-2003 Jörg P. M. Haeger
#

# Thanks to Ramon Casha for the "Self-extracting Archive HOWTO"
# (see http://linux.org.mt/article/selfextract)

DEST=/usr/sbin
PRODUCT=CDWserver
VERSION=@VERSION@

echo
echo "$PRODUCT $VERSION"
echo

if [ ! "`id -u`" = "0" ]; then
	echo "This installer will replace $DEST/$PRODUCT."
	echo "Restart as root!"
	exit 1
fi

more << EOF
This version of CDWserver 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.

EOF

echo "Do you accept? (yes or no)"
read input
if [ ! "$input" = "yes" ]; then
	echo "Installation cancelled!"
	exit 1
fi

echo
echo "$PRODUCT $VERSION - starting installation... please wait"
echo

SKIP=`awk '/^__ARCHIVE_FOLLOWS__/ { print NR + 1; exit 0; }' $0`

/etc/init.d/CDWserver stop
echo -n "replacing $DEST/$PRODUCT..."
sleep 3
tail +$SKIP $0 | bzip2 -cd - > $DEST/$PRODUCT
chmod +x $DEST/$PRODUCT
echo " done"
/etc/init.d/CDWserver start

echo
echo "Now you may visit http://`hostname`:12411"
echo

exit 0

__ARCHIVE_FOLLOWS__
