#!/bin/sh
#
# shell script to grant privileges to the bacula database
#
# Copyright (C) 2000-2015 Kern Sibbald
# License: BSD 2-Clause; see file LICENSE-FOSS
#
db_user=${db_user:-bacula}
bindir=/usr/local/bin
db_name=${db_name:-bacula}
db_password=
if [ "$db_password" != "" ]; then
   pass="identified by '$db_password'"
fi
db_ssl_options=
if [ "$db_ssl_options" != "" ]; then
   ssl_options="require $db_ssl_options"
fi
 
if $bindir/mysql $* -u root -f <<END-OF-DATA
use mysql
grant all privileges on ${db_name}.* to ${db_user}@localhost ${pass} ${ssl_options};
grant all privileges on ${db_name}.* to ${db_user}@"%" ${pass} ${ssl_options};
select * from user;
flush privileges;
END-OF-DATA
then
   echo "Privileges for user ${db_user} granted on database ${db_name}."
   exit 0
else
   echo "Error creating privileges."
   exit 1
fi
