Hi,
I am not a PostgreSQL specialist, but to become a DD I have been asked
to send patches to fix some RC bugs, so...
Anyway, I am currently working on these issues, and I have managed to
get this package installed correctly, and the database created. It would
need a few more tests, but is looks like the modifications to the
postinst script might close #272191 as well.
This patch also adds support for deleting the database if the DB server
is on localhost.
If someone could test this patch and give a report on it, it would be
nice.
J.L., as I am working the scripts for this package, would you like me to
continue and try to add support for remote database servers ?
Regards,
Regis
diff -urN bacula-1.36.1/debian/bacula-director-pgsql.postinst bacula-1.36.1_patched/debian/bacula-director-pgsql.postinst
--- bacula-1.36.1/debian/bacula-director-pgsql.postinst 2005-02-20 20:52:30.300692272 +
+++ bacula-1.36.1_patched/debian/bacula-director-pgsql.postinst 2005-02-20 22:24:45.865158560 +
@@ -46,42 +46,47 @@
db_get bacula-director-pgsql/db_host || true
PGSQL_HOST="$RET"
+
+ db_get bacula-director-pgsql/pgsql_root_username || true
+ DB_ADMIN="$RET"
# default: "localhost"
if [ "$PGSQL_HOST" != "localhost" ]; then
PGSQL_HOST_STRING="-h $PGSQL_HOST"
export PGUSER=$DB_ADMIN
- PGSQLCMD="/usr/bin/psql $PGSQL_HOST_STRING"
else # 'localhost' install
if ! getent passwd $DB_ADMIN >/dev/null ; then
echo -e "\nFATAL: the specified DB Administrator does not exist in 'passwd' databases"
exit 1
fi
- PGSQLCMD="su -s /bin/sh $dbadmin -c /usr/bin/psql"
+ SUPOSTGRES_CMD="su -s /bin/sh $DB_ADMIN -c"
fi
+
+PGSQLCMD="/usr/bin/psql $PGSQL_HOST_STRING"
# Non-local setups are not yet supported.
# Patches are welcome !!!
echo -n "Checking DB connectivity..."
-if ! $PGSQLCMD -l >/dev/null 2>&1; then
+if ! $SUPOSTGRES_CMD "$PGSQLCMD -l" >/dev/null 2>&1; then
echo -e "\nFATAL: Could not connect to PostgreSQL server at $PGSQL_HOST"
exit 1
fi
echo "Ok."
+ CREATE_DB=`$SUPOSTGRES_CMD "$PGSQLCMD -l" | grep bacula` || true
db_get bacula-director-pgsql/create_tables || true
- if [ "$RET" = "true" ]; then
+ if [ "$RET" = "true" -a -z "$CREATE_DB" ]; then
if [ "$PGSQL_HOST" = "localhost" ]; then
# localhost, so we can go the easy way :-)
# We are already ·DB_ADMIN -- no need to worry about privileges
echo -n "Creating Catalog \"$CATALOG\" at 'localhost'... "
- if ! eval $PGSQLCMD -d 'template1' -c "\"CREATE DATABASE bacula;\""; then
+ if ! $SUPOSTGRES_CMD "$PGSQLCMD template1 -c \"CREATE DATABASE $CATALOG;\"" > /dev/null 2>&1; then
echo -e "\nERROR: Database creation failed!";
exit 1;
fi
@@ -95,7 +100,7 @@
# Create tables
echo -n "Creating tables ..."
- if ! su -s /bin/sh $DB_ADMIN -c $MAKE_SQL_TABLES >/dev/null 2>&1
+ if ! $SUPOSTGRES_CMD "$MAKE_SQL_TABLES" > /dev/null 2>&1
then
echo -e "\nERROR: Table creation failed!"
exit 1
@@ -110,7 +115,7 @@
export DBUSER DBPASS
echo -n "Granting privileges ..."
- if ! $GRANT_SQL_TABLES >/dev/null 2>&1
+ if ! $GRANT_SQL_TABLES > /dev/null 2>&1
then
echo -e "\nERROR: Granting privileges failed!"
exit 1
@@ -161,7 +166,7 @@
DBUSER="bacula"
export DBUSER DBPASS
echo -n "Granting privileges ..."
- if ! $GRANT_SQL_PRIVS >/dev/null 2>&1
+ if ! $SUPOSTGRES_CMD "$GRANT_SQL_PRIVS" > /dev/null 2>&1
then
echo -e "\nERROR: Granting privileges failed!"
exit 1
@@ -170,7 +175,7 @@
#AUTHFILE=`getent passwd bacula | cut -d ':' -f 6`/.pgpass
AUTHFILE=/var/lib/bacula/.pgpass
- echo "localhost:*:bacula:$DB_USER:$DB_PASS" > $AUTHFILE
+ echo "localhost:*:bacula:$DBUSER:$DBPASS" > $AUTHFILE
chown bacula:root $AUTHFILE # reported by Shin-young Yune
chmod 0600 $AUTHFILE
@@ -183,7 +188,7 @@
echo -n "Processing configuration ..."
TARGET=$CFGFILE.dpkg-tmp
- sed -e "s/dbname = bacula;/dbname = bacula; DB Address = $PGHOST;/" \
+ sed -e "s/dbname = bacula;/dbname = bacula; DB Address = $PGSQL_HOST;/" \
-e "s/@db_user@/$DBUSER/" -e "s/@db_pswd@/$DBPASS/" \
$DEFCONFIG/bacula-dir.conf > $TARGET
diff -urN bacula-1.36.1/debian/bacula-director-pgsql.postrm bacula-1.36.1_patched/debian/bacula-director-pgsql.postrm
--- bacula-1.36.1/debian/bacula-director-pgsql.postrm 2005-02-20 20:52:30.289693944 +
+++ bacula-1.36.1_patched/debian/bacula-director-pgsql.postrm 2005-02-20 22:25:56.397436024 +
@@ -22,12 +22,28 @@
CONFFILE=/etc/bacula/bacula-dir.conf
+CATALOG="bacula"
case "$1" in
purge)
rm -f $CONFFILE $CONFFILE.dist
# Drop Bacula's user privileges? Can't do
- # Potentially, drop DB ... Can't do?
+ # Potentially, drop DB ... Works only for localhost so far
+
+ db_get bacula-director-pgsql/db_host || tru