#!/bin/bash

# concept from Debian run-parts and similar from fedora crontabs

# keep going when something fails
set +e

if [ ! -d "@NOTIFYDDIR@" ]; then
	exit 0
fi

LOGFILE="@LOGDIR@/cman_notify.log"

if [ "$CMAN_NOTIFICATION_DEBUG" = "1" ]; then
	OUT="$LOGFILE"
fi

# Ignore *~ and *, scripts
for i in $(LC_ALL=C; echo @NOTIFYDDIR@/*[^~,]); do
	[ -d $i ] && continue
	# skip know scripts
	[ "${i%.cfsaved}" != "${i}" ] && continue
	[ "${i%.rpmsave}" != "${i}" ] && continue
        [ "${i%.rpmorig}" != "${i}" ] && continue
        [ "${i%.rpmnew}" != "${i}" ] && continue
        [ "${i%.swp}" != "${i}" ] && continue
	[ "${i%,v}" != "${i}" ] && continue
	[ "${i%.dpkg-old}" != "${i}" ] && continue
	[ "${i%.dpkg-dist}" != "${i}" ] && continue
	[ "${i%.dpkg-new}" != "${i}" ] && continue

	if [ -x $i ]; then
		echo "starting $(basename $i)" >> $LOGFILE
		[ -n "$OUT" ] && $i >> $OUT
		[ -z "$OUT" ] && $i > /dev/null 2>&1
		echo "finished $(basename $i)" >> $LOGFILE
	fi
done

exit 0
