#!/bin/sh

. bacula-sh-functions
. shell-config

default_system_backup_path="$(readlink -e /srv)"

# setup /srv as a local storage
bacula_storage_set_path "$default_system_backup_path"

# remove localhost's client
__director_include_del "$bacula_job_dir/bacula.conf" # client's job

# turn on bacula services
chkconfig bacula-dir on
chkconfig bacula-fd on
chkconfig bacula-sd on
chkconfig mysqld on

# sync director name with hostname
HOSTNAME="$(shell_config_get /etc/sysconfig/network HOSTNAME)"
[ -z "$HOSTNAME" ] && HOSTNAME="localhost.localdomain"
HOSTNAME="${HOSTNAME%%.*}"

pass=`/usr/bin/pwqgen|sed -e 's/[\"$\`\\]/\\&/g'`

bacula_director_set_catalog_password "$pass"

bacula_director_set_name "$HOSTNAME"
bacula_storage_set_director "$HOSTNAME"
bacula_file_set_director	"$HOSTNAME"
bacula_console_set_director	"$HOSTNAME"
mysql_create_database_bacula
