#!/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 [ "/usr/bin" = "" ]; 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

/etc/init.d/CDWserver stop 2> /dev/null || :
rpm -e webCDwriter 2> /dev/null || :

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

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

# remove directory trees
rm -rfv \
	/etc/CDWserver/ \
	/var/CDWserver/projects/ \
	/var/log/CDWserver/ \
	/var/spool/CDWserver/ \
	/var/CDWserver/bin/

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

# remove single files
rm -fv \
	/usr/bin/cdrdao-dummy \
	/usr/bin/cdrecord-dummy \
	/usr/bin/CDWpasswd \
	/usr/bin/CDWuseradd \
	/usr/bin/CDWrootGate \
	/usr/bin/CDWverify \
	/usr/bin/dvd+rw-format-dummy \
	/usr/bin/files2cd \
	/usr/bin/growisofs-dummy \
	/usr/bin/rcdrecord \
	/usr/bin/setScheduler \
	/etc/init.d/CDWserver \
	/usr/sbin/CDWserver \
	/usr/sbin/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 || :
