#!/bin/sh

#
# tools/webCDcreatorRSA-installer.sh
#
# This file is part of webCDwriter - Network CD Writing.
#
# Copyright (C) 2002-2004 Jörg P. M. Haeger
#
# webCDwriter is free software. See CDWserver.cpp for details.
#

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

HTTPDIR=/var/CDWserver/http
MD5="@MD5@"
PRODUCT=webCDcreator.jar
PRODUCT2="(RSA signed version)"
VERSION=@VERSION@

echo
echo "$PRODUCT $VERSION $PRODUCT2 Installer"
echo

if [ ! "$1" = "" ]; then
	HTTPDIR="$1"
fi

if [ ! -e "$HTTPDIR" ]; then
	old=/etc/CDWserver/http
	if [ -e "$old" ]; then
		HTTPDIR="$old"
	else
		echo "The default HTTPDIR \"$HTTPDIR\" does not exist."
		echo "Retry"
		echo "   sh $0 HTTPDIR"
		echo "with the HTTPDIR you used in the configure script!"
		echo
		exit 1
	fi
fi

DEST="$HTTPDIR/webCDcreator/4pluginRSA"

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

echo -n "Verifying the checksum..."
if [ -x /sbin/md5 ]; then
	# FreeBSD
	MD5TOOL="/sbin/md5 -q"
else
	MD5TOOL=md5sum
fi
MD5test="`tail +$SKIP $0 | $MD5TOOL`"
if [ ! "$MD5test" = "$MD5" ]; then
	MD5test="$MD5test  -"
	if [ ! "$MD5test" = "$MD5" ]; then
		echo " does not match -> retry to download this installer!"
		echo
		exit 1
	fi
fi
echo " OK"

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

echo -n "Installing $PRODUCT to $DEST/..."

rm -f $DEST/$PRODUCT
rm -f $DEST/version-*
tail +$SKIP $0 | bzip2 -cd - > $DEST/$PRODUCT
touch $DEST/version-$VERSION

echo " done"
echo

exit 0

__ARCHIVE_FOLLOWS__
