#!/bin/sh

PATH=/bin:/usr/bin:/usr/sbin

# Note how to delete UID/GID
USER=%%BAREOS_USER%%
GROUP=%%BAREOS_GROUP%%
UID=%%BAREOS_UID%%
GID=%%BAREOS_UID%%
BAREOS_DIR=%%BAREOS_DIR%%

TMPFILE=/tmp/services-$RANDOM-$$

case "$2" in
"DEINSTALL")
	# Delete entries in /etc/services
        sed -e '/# Bareos port start/,/# Bareos port end/{' \
            -e 'd' \
            -e '}' /etc/services > $TMPFILE
        mv -f $TMPFILE /etc/services

	if [ -d ${BAREOS_DIR} ]; then
	    echo "Check if ${BAREOS_DIR} is empty and delete it to permanently remove the bareos port."
	fi

	if pw groupshow "${USER}" 2>/dev/null 1>&2; then
	    echo "To delete Bareos group permanently, use 'pw groupdel ${GROUP}'"
	fi
        ;;
esac
