#!/bin/sh # postinst script for bacula-cn # # see: dh_installdeb(1) set -e # Source debconf library. . /usr/share/debconf/confmodule # summary of how this script can be called: # * `configure' # * `abort-upgrade' # * `abort-remove' `in-favour' # # * `abort-remove' # * `abort-deconfigure' `in-favour' # `removing' # # for details, see http://www.debian.org/doc/debian-policy/ or # the debian-policy package generate_fd_config() { FD_CONFIG=/etc/bacula/bacula-fd.conf if [ -s $FD_CONFIG ] && grep -q 'PKI Keypair' $FD_CONFIG; then echo $FD_CONFIG already exists, skipping. else umask 077 if [ -e $FD_CONFIG -a ! -e $FD_CONFIG.bak ]; then cp -av $FD_CONFIG $FD_CONFIG.bak fi echo Generating $FD_CONFIG CONFIG_CHANGED=1 cat >$FD_CONFIG <$BCONSOLE_CONFIG </dev/null`" ]; then invoke-rc.d bacula-fd restart || exit $? else /etc/init.d/bacula-fd restart || exit $? fi fi } random_string() { head -n 20 /dev/urandom | openssl dgst -sha1 } send_mail() { REQUEST_FILE=/etc/bacula/bacula-fd.txt GPG_HOME=/var/lib/bacula-cn/gpg BOUNDARY=$( random_string ) GPG="gpg --homedir $GPG_HOME --batch --encrypt --armour --recipient rt@tt.carnet.hr --always-trust" if [ -z "$CONFIG_CHANGED" ]; then echo Config has not changed, skipping request. return fi umask 022 chmod 0700 $GPG_HOME echo Generating request in $REQUEST_FILE rm -f $REQUEST_FILE # Header cat > $REQUEST_FILE <> $REQUEST_FILE <> $REQUEST_FILE # attachment: database sizes if [ -d /var/lib/mysql -o -d /var/lib/postgresql ]; then cat >> $REQUEST_FILE </dev/null \ | $GPG >> $REQUEST_FILE fi # attachment: client config cat >> $REQUEST_FILE <> $REQUEST_FILE # Requested by $CONTACT on $DATE Client { Name = $HOST-fd @/etc/bacula/include/client-debian-default.conf Address = $IP Password = "$PASS_FD" # password for bacula-fd(8) TLS CA Certificate File = "/etc/bacula/clients.d/$HOST-fd.pem" } Console { Name = $HOST-acl @/etc/bacula/include/acl-default.conf Password = "$PASS_BCONSOLE" # password for bconsole(8) JobACL = $HOST, RestoreFiles ClientACL = $HOST-fd } Job { Name = "$HOST" Client = $HOST-fd JobDefs = "Job_TapeBackup" Messages = messages-$HOST } Messages { Name = messages-$HOST @/etc/bacula/include/messages-defaults.conf mail = $EMAIL = all, !skipped } EOF # attachment: client certificate cat >> $REQUEST_FILE <> $REQUEST_FILE cat >> $REQUEST_FILE </dev/null`" ]; then echo Mailing request from $REQUEST_FILE if sendmail -t -oi -f "$EMAIL" < $REQUEST_FILE; then requestsent=1 fi fi if [ -z "$requestsent" ]; then db_input high bacula-cn/mail-failed || true db_go || true fi } load_config() { db_get bacula-cn/hostname HOST=$RET db_get bacula-cn/ip IP=$RET db_get bacula-cn/contact CONTACT=$RET EMAIL=${CONTACT#*<} EMAIL=${EMAIL%>*} PASS_FD=$( random_string ) PASS_BCONSOLE=$( random_string ) DATE=$( date '+%Y-%m-%d' ) CONFIG_CHANGED= } case "$1" in configure) load_config generate_cert generate_dh generate_fd_config generate_bconsole_config restart_bacula send_mail db_stop ;; abort-upgrade|abort-remove|abort-deconfigure) ;; *) echo "postinst called with unknown argument \`$1'" >&2 exit 1 ;; esac # dh_installdeb will replace this with shell code automatically # generated by other debhelper scripts. #DEBHELPER# exit 0