summaryrefslogtreecommitdiff
path: root/debian/dbapps-lib
diff options
context:
space:
mode:
Diffstat (limited to 'debian/dbapps-lib')
-rw-r--r--debian/dbapps-lib101
1 files changed, 101 insertions, 0 deletions
diff --git a/debian/dbapps-lib b/debian/dbapps-lib
new file mode 100644
index 0000000..16aba10
--- /dev/null
+++ b/debian/dbapps-lib
@@ -0,0 +1,101 @@
+# some library functions for phpbb3 maintainer scripts
+# copyright 2010 J.M. Roth <jmroth@iip.lu>
+
+run_sql () {
+ if [ -f /etc/dbconfig-common/phpbb3.conf ] ; then
+ . /etc/dbconfig-common/phpbb3.conf
+ else
+ echo "$0 $@: run_sql: cannot load db metadata" 1>&2
+ return 1
+ fi
+
+ local sql="$1"
+
+ ERR=
+ case $dbc_dbtype in
+ mysql )
+ l_dbc_dbserver=${dbc_dbserver:- localhost}
+ echo $sql | mysql -h ${l_dbc_dbserver} ${dbc_dbport:+--port $dbc_dbport} -u $dbc_dbuser -p$dbc_dbpass $dbc_dbname -s || run_sql_fail $dbc_dbtype
+ ;;
+ pgsql )
+ if [ -z "${dbc_dbserver}" ]; then
+ echo $sql | su - postgres -c "psql ${dbc_dbport:+-p $dbc_dbport} -d \"dbname=$dbc_dbname ${dbc_ssl:+sslmode=require}\" -q" || run_sql_fail $dbc_dbtype
+ else
+ echo $sql | psql -h $dbc_dbserver ${dbc_dbport:+-p $dbc_dbport} -d \"dbname=$dbc_dbname ${dbc_ssl:+sslmode=require}\" -q || run_sql_fail $dbc_dbtype
+ fi
+ ;;
+ sqlite )
+ echo $sql | sqlite $dbc_basepath/$dbc_dbname || run_sql_fail $dbc_dbtype
+ ;;
+ * )
+ echo "run_sql: $dbc_dbtype not supported" >&2
+ ;;
+ esac
+
+ return 0
+}
+
+run_sql_fail () {
+ echo "run_sql $@ fail" >&2
+ ERR=fail
+}
+
+postgres_update_seqs () {
+# repair pgsql sequences, this has always been a source of trouble
+# on prepopulated DBs
+ if db_get phpbb3/dbconfig-install && [ "$RET" = "true" ] ; then
+ db_get phpbb3/database-type
+ if [ "$RET" = "pgsql" ]; then
+ db_get phpbb3/db/dbname
+ local dbname="$RET"
+ db_get phpbb3/remote/host
+ local dbhost="$RET"
+ db_get phpbb3/remote/port
+ local dbport="$RET"
+ if [ -z "${dbc_dbserver}" ]; then
+ /usr/share/phpbb3/postgres_update_seqs.sh /usr/share/dbconfig-common/data/phpbb3/install/pgsql | su - postgres -c "psql ${dbhost:+-h $dbhost} ${dbport:+-p $dbport} -d $dbname -q >/dev/null"
+ else
+ /usr/share/phpbb3/postgres_update_seqs.sh /usr/share/dbconfig-common/data/phpbb3/install/pgsql | psql ${dbhost:+-h $dbhost} ${dbport:+-p $dbport} -d $dbname -q >/dev/null
+ fi
+ fi
+ fi
+}
+
+_md5 () {
+ echo -n $1 | md5sum | cut -c-32
+}
+
+dc_true () {
+ db_get $1
+ [ "$RET" = "true" ]
+ return $?
+}
+
+dc_forget () {
+ db_reset $1
+ db_fset $1 seen false
+}
+
+dc_get () {
+ db_get $1
+ echo -n $RET
+}
+
+dc_copy () {
+ db_set $2 "$(dc_get $1)"
+}
+
+dc_out () {
+ db_get $1
+ echo $1: $RET # -- "$(debconf-show phpbb3 | grep $1)"
+}
+
+dc_dbg () {
+ [ "$PB3DEBUG" != "maint" ] && return
+ set +e
+ echo $0:$LINENO $@
+ for d in install upgrade reinstall remove; do
+ db_get phpbb3/dbconfig-$d && echo [dbc] phpbb3/dbconfig-$d "$RET"
+ done
+ set -e
+}