#! /bin/sh

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

SAMBA_CONFIG="smb.conf"
SAMBA_CONFDIR="/usr/local/etc"
SAMBA_SPOOL="/var/spool/samba"
SAMBA_LOGDIR="/var/log/samba"
SAMBA_LOCKDIR="/var/db/samba"
SAMBA_PRIVATEDIR="/usr/local/etc/samba"
SAMBA_OWNER=root
SAMBA_GROUP=wheel
CMP="cmp"
RM="rm"
RMDIR="rmdir"
ECHO_CMD="echo"

post-deinstall() {
	if ${CMP} -s ${SAMBA_CONFDIR}/${SAMBA_CONFIG} ${SAMBA_CONFDIR}/${SAMBA_CONFIG}.sample; then
		${RM} -f ${SAMBA_CONFDIR}/${SAMBA_CONFIG}
	fi
	${RM} -f ${SAMBA_CONFDIR}/${SAMBA_CONFIG}.sample
	${RM} -rf ${SAMBA_SPOOL}
	${RMDIR} ${SAMBA_LOGDIR} 2>/dev/null || true
	for f in connections.tdb locking.tdb messages.tdb sessionid.tdb \
	    unexpected.tdb brlock.tdb namelist.debug
	do
		${RM} -f "${SAMBA_LOCKDIR}/${f}"
	done
	${RMDIR} ${SAMBA_LOCKDIR} 2>/dev/null || true
	${RMDIR} ${SAMBA_PRIVATEDIR} 2>/dev/null || true
	${ECHO_CMD} "WARNING: If you will *NOT* use this package anymore, please remove the"
	${ECHO_CMD} "  following directories manually:"
	${ECHO_CMD} "  ${SAMBA_PRIVATEDIR}"
	${ECHO_CMD} "  ${SAMBA_LOGDIR}"
	${ECHO_CMD} "  ${SAMBA_LOCKDIR}"
	${ECHO_CMD}
}

case $2 in
	POST-DEINSTALL)
		post-deinstall
		;;
esac
