1#!/bin/sh
2#
3# shell script to grant privileges to the bacula database
4#
5# Copyright (C) 2000-2020 Kern Sibbald
6# License: BSD 2-Clause; see file LICENSE-FOSS
7#
8db_user=${db_user:-@db_user@}
9bindir=@POSTGRESQL_BINDIR@
10PATH="$PATH:$bindir"
11db_name=${db_name:-@db_name@}
12db_password=@db_password@
13if [ "$db_password" != "" ]; then
14   pass="password '$db_password'"
15fi
16
17
18psql -f - -d ${db_name} $* <<END-OF-DATA
19
20create user ${db_user} ${pass};
21
22-- for the database
23alter database ${db_name} owner to ${db_user} ;
24
25-- for tables
26grant all on TagJob       to ${db_user};
27grant all on TagClient    to ${db_user};
28grant all on TagMedia     to ${db_user};
29grant all on TagObject    to ${db_user};
30grant all on Object       to ${db_user};
31grant all on Events       to ${db_user};
32grant all on unsavedfiles to ${db_user};
33grant all on basefiles	  to ${db_user};
34grant all on jobmedia	  to ${db_user};
35grant all on filemedia	  to ${db_user};
36grant all on file	  to ${db_user};
37grant all on job	  to ${db_user};
38grant all on media	  to ${db_user};
39grant all on client	  to ${db_user};
40grant all on pool	  to ${db_user};
41grant all on fileset	  to ${db_user};
42grant all on path	  to ${db_user};
43grant all on counters	  to ${db_user};
44grant all on version	  to ${db_user};
45grant all on cdimages	  to ${db_user};
46grant all on mediatype	  to ${db_user};
47grant all on storage	  to ${db_user};
48grant all on device	  to ${db_user};
49grant all on status	  to ${db_user};
50grant all on location	  to ${db_user};
51grant all on locationlog  to ${db_user};
52grant all on log	  to ${db_user};
53grant all on jobhisto	  to ${db_user};
54grant all on PathHierarchy  to ${db_user};
55grant all on PathVisibility to ${db_user};
56grant all on RestoreObject to ${db_user};
57grant all on Snapshot to ${db_user};
58-- for sequences on those tables
59
60grant select, update on events_eventsid_seq 	   to ${db_user};
61grant select, update on path_pathid_seq 	   to ${db_user};
62grant select, update on fileset_filesetid_seq	   to ${db_user};
63grant select, update on pool_poolid_seq 	   to ${db_user};
64grant select, update on client_clientid_seq	   to ${db_user};
65grant select, update on media_mediaid_seq	   to ${db_user};
66grant select, update on job_jobid_seq		   to ${db_user};
67grant select, update on file_fileid_seq 	   to ${db_user};
68grant select, update on jobmedia_jobmediaid_seq    to ${db_user};
69grant select, update on basefiles_baseid_seq	   to ${db_user};
70grant select, update on storage_storageid_seq	   to ${db_user};
71grant select, update on mediatype_mediatypeid_seq  to ${db_user};
72grant select, update on device_deviceid_seq	   to ${db_user};
73grant select, update on location_locationid_seq    to ${db_user};
74grant select, update on locationlog_loclogid_seq   to ${db_user};
75grant select, update on log_logid_seq		   to ${db_user};
76grant select, update on restoreobject_restoreobjectid_seq to ${db_user};
77grant select, update on object_objectid_seq to ${db_user};
78grant select, update on snapshot_snapshotid_seq to ${db_user};
79END-OF-DATA
80if [ $? -eq 0 ]
81then
82   echo "Privileges for user ${db_user} granted on database ${db_name}."
83   exit 0
84else
85   echo "Error creating privileges."
86   exit 1
87fi
88