#!/bin/sh
# source debconf stuff
. /usr/share/debconf/confmodule
. /usr/share/univention-lib/all.sh

exec 3>/dev/null

# ... rest of your code ...
if [ "$1" = "configure" ]; then

    # on upgrade, set backup_myself to yes if it was not set
    filestorage=$(ucr get bareos/filestorage)
    backup_myself=$(ucr get bareos/backup_myself)
    if [ -n "$filestorage" -a -z "$backup_myself" ]; then
        ucr set bareos/backup_myself=yes
    fi

    # set defaults
    ucr set \
            bareos/filestorage?/var/lib/bareos/storage \
            bareos/max_full_volume_bytes?20 \
            bareos/max_full_volumes?1 \
            bareos/max_diff_volume_bytes?10 \
            bareos/max_diff_volumes?1 \
            bareos/max_incr_volume_bytes?1 \
            bareos/max_incr_volumes?1 \
            bareos/backup_myself?no \
            bareos/webui/console/user1/username?Administrator \
            bareos/webui/console/user1/password?

    # commit defaults
    ucr commit \
            /etc/bareos/bconsole.conf
            #/etc/bareos/bareos-dir.conf \
            #/etc/bareos/bareos-sd.conf \
            #/etc/bareos/bareos-fd.conf \

    touch /etc/bareos/autogenerated/clients.include

    # activate our listener plugin
    invoke-rc.d univention-directory-listener restart

    # restart bareos
    invoke-rc.d bareos-dir restart
    invoke-rc.d bareos-sd restart
    invoke-rc.d bareos-fd restart

    [ -x "/etc/init.d/univention-firewall" ] && invoke-rc.d univention-firewall restart

    # reload apache
    invoke-rc.d apache2 reload

    call_joinscript 62univention-bareos.inst
fi

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

#DEBHELPER#

exit 0
