#!/bin/sh

DEFCONFIGDIR="/usr/share/bacula-common/defconfig"
DSTDIR="/etc/bacula"
CONFIG="bacula-dir.conf"

if [ -f $DSTDIR/$CONFIG.dpkg-tmp ]; then
    SOURCE=$DSTDIR/$CONFIG.dpkg-tmp
else
    SOURCE=$DSTDIR/$CONFIG
fi

if [ -f $DSTDIR/$CONFIG -a ! -f $SOURCE ]; then
    echo "Target $DSTDIR/$CONFIG already exists and $SOURCE doesn't"
    echo "Not modifying target."
else
    if [ ! -f $DSTDIR/$CONFIG ]; then
        TARGET=$DSTDIR/$CONFIG
    else
        TARGET=$DSTDIR/$CONFIG.dist
    fi

    # Final config fix
    sed -e "s/@hostname@/`hostname`/" < $SOURCE > $TARGET

    # get rid of now unnecessary file
    rm -f $SOURCE
    # Harden permissions, so that passwords can not be looked at
    # Fixed by Philipp M Hahn
    chown root:bacula $TARGET
    chmod 640 $TARGET

fi


exit 0
