#!/bin/bash

. ${TOOLKIT}-functions.sh

get_apache_owner()
{
	if [ -f /etc/apache2/envvars ]
	then
		/bin/sh -c '. /etc/apache2/envvars; echo $APACHE_RUN_USER:$APACHE_RUN_GROUP'
	else
		echo "www-data:www-data"
	fi
	return 0
}

systems=$(jtconf backup.systems 2>/dev/null) && {
	kubackup-addsystem --strict $(echo $systems | tr ',' ' ') || exit $?
	kubackup-update-rsync || exit $?
}

cgibin=$(jtconf www.cgibin 2>/dev/null || :)
[ "X$cgibin" != "X" ] && {
	owner=$(get_apache_owner)
	noparse="false"

	sourcefile="/usr/share/doc/kubackup/backup-status.cgi"
	destfile="backup-status"
	installfile "$sourcefile" "$cgibin/$destfile" $owner 550 $noparse

	sourcefile="/usr/share/doc/kubackup/cgilib.pl"
	destfile="cgilib.pl"
	installfile "$sourcefile" "$cgibin/$destfile" $owner 550 $noparse

	# cleanup old/temp stuffs
	uninstallfiles $cgibin/${destfile}-*
	purgefiles $cgibin/${destfile}-*
}




# cleanup old/temp stuffs
#
purgefiles \
	/etc/kuwatcher/check-rsync-timeout \
	/etc/kuwatcher/conf.d/auto-check-rsync-timeout


$SOMETHING_CHANGED && {
	[ -f /etc/init.d/kuwatcher ] && sh /etc/init.d/kuwatcher restart || :
}

exit 0
