Debian Codegraph @

src/cats/grant_mysql_privileges.in

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 #!/bin/sh
2 #
3 # shell script to grant privileges to the bacula database
4 #
5 # Copyright (C) 2000-2023 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 create user ${db_user}@"%" ${pass};
24 create user ${db_user}@localhost ${pass};
25 EOD
26 then
27 echo "Created MySQL database user: ${db_user}"
28 fi
29
30 if $bindir/mysql $* -u root -f <<END-OF-DATA
31 use mysql
32 grant all privileges on ${db_name}.* to ${db_user}@"%" ${ssl_options};
33 grant process on *.* to ${db_user}@"%" ${ssl_options};
34 select * from user;
35 flush privileges;
36 END-OF-DATA
37 then
38 echo "Privileges for user ${db_user} granted on database ${db_name}."
39 exit 0
40 else
41 echo "Error creating privileges."
42 exit 1
43 fi