]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/cats/update_bacula_tables.in
Big backport from Enterprise
[bacula/bacula] / bacula / src / cats / update_bacula_tables.in
index 8ce59a573b4f586456e43854c84cca2c53d6df99..cafeaa178fe672555c4ab04faf7e2936df988fde 100755 (executable)
@@ -1,17 +1,50 @@
 #!/bin/sh
 #
+# Copyright (C) 2000-2017 Kern Sibbald
+# License: BSD 2-Clause; see file LICENSE-FOSS
+#
 # This routine alters the appropriately configured
-#  Bacula tables for PostgreSQL, MySQL, or SQLite.
+# Bacula tables for PostgreSQL, Ingres, MySQL, or SQLite.
+#
+
+# can be used to change the current user with su
+pre_command="sh -c"
+
+default_db_type=@DEFAULT_DB_TYPE@
+
+#
+# See if the first argument is a valid backend name.
+# If so the user overrides the default database backend.
 #
-if test xsqlite3 = x@DB_TYPE@ ; then
-  echo "Altering SQLite tables"
-  @scriptdir@/update_@DB_TYPE@_tables $*
+if [ $# -gt 0 ]; then
+   case $1 in
+     sqlite3)
+       db_type=$1
+       shift
+       ;;
+     mysql)
+       db_type=$1
+       shift
+       ;;
+     postgresql)
+       db_type=$1
+       shift
+       ;;
+     *)
+       ;;
+   esac
 fi
-if test xmysql = x@DB_TYPE@ ; then
-  echo "Altering MySQL tables"
-  @scriptdir@/update_mysql_tables $*
+
+#
+# If no new db_type is gives use the default db_type.
+#
+if [ -z "${db_type}" ]; then
+   db_type="${default_db_type}"
 fi
-if test xpostgresql = x@DB_TYPE@ ; then
-  echo "Altering PostgreSQL tables"
-  @scriptdir@/update_postgresql_tables $*
+
+if [ $db_type = postgresql -a "$UID" = 0 ]; then
+    pre_command="su - postgres -c"
 fi
+
+echo "Altering ${db_type} tables"
+$pre_command "@scriptdir@/update_${db_type}_tables $*"