]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/grant_mysql_privileges.in
Big backport from Enterprise
[bacula/bacula] / bacula / src / cats / grant_mysql_privileges.in
1 #!/bin/sh
2 #
3 # shell script to grant privileges to the bacula database
4 #
5 # Copyright (C) 2000-2017 Kern Sibbald
6 # License: BSD 2-Clause; see file LICENSE-FOSS
7 #
8 db_user=${db_user:-@db_user@}
9 bindir=@MYSQL_BINDIR@
10 db_name=${db_name:-@db_name@}
11 db_password=@db_password@
12 if [ "$db_password" != "" ]; then
13    pass="identified by '$db_password'"
14 fi
15 db_ssl_options=@db_ssl_options@
16 if [ "$db_ssl_options" != "" ]; then
17    ssl_options="require $db_ssl_options"
18 fi
19  
20 if $bindir/mysql $* -u root -f 2>/dev/null 1>/dev/null  <<EOD
21 use mysql;
22 create user ${db_user} ${pass};
23 EOD
24 then
25   echo "Created MySQL database user: ${db_user}"
26 fi
27
28 if $bindir/mysql $* -u root -f <<END-OF-DATA
29 use mysql
30 grant all privileges on ${db_name}.* to ${db_user}@localhost ${pass} ${ssl_options};
31 grant all privileges on ${db_name}.* to ${db_user}@"%" ${pass} ${ssl_options};
32 select * from user;
33 flush privileges;
34 END-OF-DATA
35 then
36    echo "Privileges for user ${db_user} granted on database ${db_name}."
37    exit 0
38 else
39    echo "Error creating privileges."
40    exit 1
41 fi