#!/bin/sh

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

echo
echo "Uninstaller of webCDwriter"
echo "Warning: Use it at your own risk!"
echo

if [ "$BINDIR" = "" ]; then
	echo "Use the $0 from the webCDwriter root directory!"
	echo "Run ./configure to create it."
	echo
	exit 1
fi

if [ ! "`id -u`" = "0" ]; then
	echo "You need to be root to remove webCDwriter!"
	echo
	exit 1
fi

echo "Do you really want to remove webCDwriter? [y/N]"
read input
if [ ! "$input" = "y" ]; then
	echo "webCDwriter is still on your system :-)"
	echo
	exit 1
fi

$INITDIR/CDWserver stop 2> /dev/null || :
rpm -e webCDwriter 2> /dev/null || :

echo
echo "Do you really want to remove \"$EXPORTDIR/\"? [y/N]"
read input
if [ "$input" = "y" ]; then
	rm -rfv $EXPORTDIR/
fi

echo
echo "Do you really want to remove \"$HTTPDIR/\"? [y/N]"
read input
if [ "$input" = "y" ]; then
	rm -rfv $HTTPDIR/
fi

# remove directory trees
rm -rfv \
	$CONFIGDIR/ \
	$PROJECTSDIR/ \
	$LOGDIR/ \
	$SPOOLDIR/ \
	$TOOLSDIR/

rmdir /var/CDWserver/ 2> /dev/null || :

# remove single files
rm -fv \
	$BINDIR/cdrdao-dummy \
	$BINDIR/cdrecord-dummy \
	$BINDIR/CDWpasswd \
	$BINDIR/CDWuseradd \
	$BINDIR/CDWrootGate \
	$BINDIR/CDWverify \
	$BINDIR/dvd+rw-format-dummy \
	$BINDIR/files2cd \
	$BINDIR/growisofs-dummy \
	$BINDIR/rcdrecord \
	$BINDIR/setScheduler \
	$INITDIR/CDWserver \
	$SBINDIR/CDWserver \
	$SBINDIR/CDWserver-GPL

# remove the user "cdwserve" and the group "cdwserve"
USER=cdwserve
GROUP=cdwserve
echo
userdel $USER 2> /dev/null \
	|| pw deluser $USER 2> /dev/null || :
groupdel $GROUP 2> /dev/null \
	|| pw delgroup $GROUP 2> /dev/null || :
