#!/bin/sh

set -e

SRCDIR="/usr/share/bacula-common/defconfig"
DSTDIR="/etc/bacula"
CONFIG="bacula-fd.conf"
TARGET=$DSTDIR/$CONFIG

. /usr/share/bacula-common/common-functions.dpkg
readOrCreatePasswords
setup_etc_default bacula-fd $@

case "$1" in
    configure)
	if [ ! -f $TARGET ]; then
	    install -m 640 -o root -g bacula $SRCDIR/$CONFIG $TARGET
	    sed -e s~@debian_hostname@~`hostname`~ \
		-e s~XXX_FDPASSWORD_XXX~$FDPASSWD~ \
		-e s~XXX_MONFDPASSWORD_XXX~$FDMPASSWD~ \
		-i $TARGET
	fi
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

# Automatically added by dh_systemd_enable
# This will only remove masks created by d-s-h on package removal.
deb-systemd-helper unmask bacula-fd.service >/dev/null || true

# was-enabled defaults to true, so new installations run enable.
if deb-systemd-helper --quiet was-enabled bacula-fd.service; then
	# Enables the unit on first installation, creates new
	# symlinks on upgrades if the unit file has changed.
	deb-systemd-helper enable bacula-fd.service >/dev/null || true
else
	# Update the statefile to add new symlinks (if any), which need to be
	# cleaned up on purge. Also remove old symlinks.
	deb-systemd-helper update-state bacula-fd.service >/dev/null || true
fi
# End automatically added section
# Automatically added by dh_installinit
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ]; then
	if [ -x "/etc/init.d/bacula-fd" ]; then
		update-rc.d bacula-fd defaults >/dev/null
		if [ -n "$2" ]; then
			_dh_action=restart
		else
			_dh_action=start
		fi
		invoke-rc.d bacula-fd $_dh_action || exit $?
	fi
fi
# End automatically added section
# Automatically added by dh_installdeb
dpkg-maintscript-helper dir_to_symlink /usr/share/doc/bacula-fd bacula-common 7.0.5\+dfsg-4\~ -- "$@"
# End automatically added section


exit 0
