]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/grant_postgresql_privileges.in
Backport from BEE
[bacula/bacula] / bacula / src / cats / grant_postgresql_privileges.in
1 #!/bin/sh
2 #
3 # shell script to grant privileges to the bacula database
4 #
5 #
6 #  Bacula® - The Network Backup Solution
7 #
8 #  Copyright (C) 2000-2014 Free Software Foundation Europe e.V.
9 #
10 #  The main author of Bacula is Kern Sibbald, with contributions from many
11 #  others, a complete list can be found in the file AUTHORS.
12 #
13 #  You may use this file and others of this release according to the
14 #  license defined in the LICENSE file, which includes the Affero General
15 #  Public License, v3.0 ("AGPLv3") and some additional permissions and
16 #  terms pursuant to its AGPLv3 Section 7.
17 #
18 #  Bacula® is a registered trademark of Kern Sibbald.
19 #
20 db_user=${db_user:-@db_user@}
21 bindir=@POSTGRESQL_BINDIR@
22 db_name=${db_name:-@db_name@}
23 db_password=@db_password@
24 if [ "$db_password" != "" ]; then
25    pass="password '$db_password'"
26 fi
27
28
29 $bindir/psql -f - -d ${db_name} $* <<END-OF-DATA
30
31 create user ${db_user} ${pass};
32
33 -- for tables
34 grant all on unsavedfiles to ${db_user};
35 grant all on basefiles    to ${db_user};
36 grant all on jobmedia     to ${db_user};
37 grant all on file         to ${db_user};
38 grant all on job          to ${db_user};
39 grant all on media        to ${db_user};
40 grant all on client       to ${db_user};
41 grant all on pool         to ${db_user};
42 grant all on fileset      to ${db_user};
43 grant all on path         to ${db_user};
44 grant all on filename     to ${db_user};
45 grant all on counters     to ${db_user};
46 grant all on version      to ${db_user};
47 grant all on cdimages     to ${db_user};
48 grant all on mediatype    to ${db_user};
49 grant all on storage      to ${db_user};
50 grant all on device       to ${db_user};
51 grant all on status       to ${db_user};
52 grant all on location     to ${db_user};
53 grant all on locationlog  to ${db_user};
54 grant all on log          to ${db_user};
55 grant all on jobhisto     to ${db_user};
56 grant all on PathHierarchy  to ${db_user};
57 grant all on PathVisibility to ${db_user};
58 grant all on RestoreObject to ${db_user};
59 -- for sequences on those tables
60
61 grant select, update on filename_filenameid_seq    to ${db_user};
62 grant select, update on path_pathid_seq            to ${db_user};
63 grant select, update on fileset_filesetid_seq      to ${db_user};
64 grant select, update on pool_poolid_seq            to ${db_user};
65 grant select, update on client_clientid_seq        to ${db_user};
66 grant select, update on media_mediaid_seq          to ${db_user};
67 grant select, update on job_jobid_seq              to ${db_user};
68 grant select, update on file_fileid_seq            to ${db_user};
69 grant select, update on jobmedia_jobmediaid_seq    to ${db_user};
70 grant select, update on basefiles_baseid_seq       to ${db_user};
71 grant select, update on storage_storageid_seq      to ${db_user};
72 grant select, update on mediatype_mediatypeid_seq  to ${db_user};
73 grant select, update on device_deviceid_seq        to ${db_user};
74 grant select, update on location_locationid_seq    to ${db_user};
75 grant select, update on locationlog_loclogid_seq   to ${db_user};
76 grant select, update on log_logid_seq              to ${db_user};
77 grant select, update on restoreobject_restoreobjectid_seq to ${db_user};
78 END-OF-DATA
79 if [ $? -eq 0 ]
80 then
81    echo "Privileges for user ${db_user} granted on database ${db_name}."
82    exit 0
83 else
84    echo "Error creating privileges."
85    exit 1
86 fi