]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/cats/grant_postgresql_privileges.in
Backport from BEE
[bacula/bacula] / bacula / src / cats / grant_postgresql_privileges.in
index 21aa8858ffcf5763d3258e3ffb070b46e7b8c3de..1e49c0281f7f637039c4d55ce773d082f2cc064f 100644 (file)
@@ -2,42 +2,83 @@
 #
 # shell script to grant privileges to the bacula database
 #
-bindir=@SQL_BINDIR@
+#
+#  Bacula® - The Network Backup Solution
+#
+#  Copyright (C) 2000-2014 Free Software Foundation Europe e.V.
+#
+#  The main author of Bacula is Kern Sibbald, with contributions from many
+#  others, a complete list can be found in the file AUTHORS.
+#
+#  You may use this file and others of this release according to the
+#  license defined in the LICENSE file, which includes the Affero General
+#  Public License, v3.0 ("AGPLv3") and some additional permissions and
+#  terms pursuant to its AGPLv3 Section 7.
+#
+#  Bacula® is a registered trademark of Kern Sibbald.
+#
+db_user=${db_user:-@db_user@}
+bindir=@POSTGRESQL_BINDIR@
+db_name=${db_name:-@db_name@}
+db_password=@db_password@
+if [ "$db_password" != "" ]; then
+   pass="password '$db_password'"
+fi
 
-if $bindir/psql $* -f - <<END-OF-DATA
-\c bacula
 
--- for tables
-grant all on unsavedfiles to bacula;
-grant all on basefiles    to bacula;
-grant all on jobmedia     to bacula;
-grant all on file         to bacula;
-grant all on job          to bacula;
-grant all on media        to bacula;
-grant all on client       to bacula;
-grant all on pool         to bacula;
-grant all on fileset      to bacula;
-grant all on path         to bacula;
-grant all on filename     to bacula;
-grant all on counters     to bacula;
-grant all on version      to bacula;
+$bindir/psql -f - -d ${db_name} $* <<END-OF-DATA
 
--- for sequences on those tables
+create user ${db_user} ${pass};
 
-grant update on filename_filenameid_seq to bacula;
-grant update on path_pathid_seq         to bacula;
-grant update on fileset_filesetid_seq   to bacula;
-grant update on pool_poolid_seq         to bacula;
-grant update on client_clientid_seq     to bacula;
-grant update on media_mediaid_seq       to bacula;
-grant update on job_jobid_seq           to bacula;
-grant update on file_fileid_seq         to bacula;
-grant update on jobmedia_jobmediaid_seq to bacula;
-grant update on basefiles_baseid_seq    to bacula;
+-- for tables
+grant all on unsavedfiles to ${db_user};
+grant all on basefiles   to ${db_user};
+grant all on jobmedia    to ${db_user};
+grant all on file        to ${db_user};
+grant all on job         to ${db_user};
+grant all on media       to ${db_user};
+grant all on client      to ${db_user};
+grant all on pool        to ${db_user};
+grant all on fileset     to ${db_user};
+grant all on path        to ${db_user};
+grant all on filename    to ${db_user};
+grant all on counters    to ${db_user};
+grant all on version     to ${db_user};
+grant all on cdimages    to ${db_user};
+grant all on mediatype   to ${db_user};
+grant all on storage     to ${db_user};
+grant all on device      to ${db_user};
+grant all on status      to ${db_user};
+grant all on location    to ${db_user};
+grant all on locationlog  to ${db_user};
+grant all on log         to ${db_user};
+grant all on jobhisto    to ${db_user};
+grant all on PathHierarchy  to ${db_user};
+grant all on PathVisibility to ${db_user};
+grant all on RestoreObject to ${db_user};
+-- for sequences on those tables
 
+grant select, update on filename_filenameid_seq    to ${db_user};
+grant select, update on path_pathid_seq           to ${db_user};
+grant select, update on fileset_filesetid_seq     to ${db_user};
+grant select, update on pool_poolid_seq           to ${db_user};
+grant select, update on client_clientid_seq       to ${db_user};
+grant select, update on media_mediaid_seq         to ${db_user};
+grant select, update on job_jobid_seq             to ${db_user};
+grant select, update on file_fileid_seq           to ${db_user};
+grant select, update on jobmedia_jobmediaid_seq    to ${db_user};
+grant select, update on basefiles_baseid_seq      to ${db_user};
+grant select, update on storage_storageid_seq     to ${db_user};
+grant select, update on mediatype_mediatypeid_seq  to ${db_user};
+grant select, update on device_deviceid_seq       to ${db_user};
+grant select, update on location_locationid_seq    to ${db_user};
+grant select, update on locationlog_loclogid_seq   to ${db_user};
+grant select, update on log_logid_seq             to ${db_user};
+grant select, update on restoreobject_restoreobjectid_seq to ${db_user};
 END-OF-DATA
+if [ $? -eq 0 ]
 then
-   echo "Privileges for bacula granted."
+   echo "Privileges for user ${db_user} granted on database ${db_name}."
    exit 0
 else
    echo "Error creating privileges."