]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/cats/drop_bacula_tables.in
Backport from Bacula Enterprise
[bacula/bacula] / bacula / src / cats / drop_bacula_tables.in
index 3707765cc92d8ee38f8cefd3b0582c2e0bb74f81..2209b97a79ebf8b12f81b3c23715b308b04df1dc 100755 (executable)
@@ -1,19 +1,50 @@
 #!/bin/sh
 #
+# Copyright (C) 2000-2015 Kern Sibbald
+# License: BSD 2-Clause; see file LICENSE-FOSS
+#
 #  Drop Bacula tables -- works for whatever is configured,
-#    MySQL, SQLite, or PostgreSQL
+#  MySQL, SQLite, Ingres, or PostgreSQL
+#
+
+# can be used to change the current user with su
+pre_command="sh -c"
+
+default_db_type=@DEFAULT_DB_TYPE@
+
 #
-if test xsqlite = x@DB_NAME@ -o xsqlite3 = x@DB_NAME@ ; then
-  @scriptdir@/drop_@DB_NAME@_tables $*
-  echo "Dropped SQLite tables"
-else
-  if test xmysql = x@DB_NAME@ ; then 
-    echo "Making MySQL tables"
-    @scriptdir@/drop_mysql_tables $*
-    echo "Dropped MySQL tables"
-  else
-    # hardcoded database name - should be a parameter
-    @scriptdir@/drop_postgresql_tables $*
-    echo "Dropped PostgreSQL tables"
-  fi
+# See if the first argument is a valid backend name.
+# If so the user overrides the default database backend.
+#
+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 no new db_type is gives use the default db_type.
+#
+if [ -z "${db_type}" ]; then
+   db_type="${default_db_type}"
+fi
+
+if [ $db_type = postgresql -a "$UID" = 0 ]; then
+    pre_command="su - postgres -c"
 fi
+
+$pre_command "@scriptdir@/drop_${db_type}_tables $*"
+echo "Dropped ${db_type} tables"