#!/bin/bash
#
# Bacula storage maintenance scripts
# Create Bacula PostgreSQL database
#

. /etc/sysconfig/bacula

# Use SQL_ASCII to be able to put any filename into
# the database even those created with unusual character sets

if [ -z $BACULA_DB_ENCODING ]; then
    echo "Bacula database encoding not found."
    echo "See /etc/sysconfig/bacula."
    exit 1
fi

# Use UTF8 if you are using standard Unix/Linux LANG specifications
# that use UTF8 -- this is normally the default and *should* be
# your standard.  Bacula works correctly *only* with correct UTF8.
#
# Note, with this encoding, if you have any "weird" filenames on
# your system (names generated from Win32 or Mac OS), you may
# get Bacula batch insert failures.

# See /etc/sysconfig/bacula for encoding definition.
 
#
# KES: Note: the CREATE DATABASE, probably should be
#   CREATE DATABASE ${db_name} $ENCODING TEMPLATE template0
#

if /usr/bin/psql -f - -d template1 $* <<END-OF-DATA
CREATE DATABASE bacula ENCODING '$BACULA_DB_ENCODING';
ALTER DATABASE bacula SET datestyle TO 'ISO, YMD';
END-OF-DATA
then
   echo "Creation of bacula database succeeded."
   exit 0
else
   echo "Creation of bacula database failed."
   exit 1
fi

