1#!/bin/sh 2 3set -e 4 5. /usr/share/debconf/confmodule 6 7#set -x 8#echo "bareos-database-common.config: $@" >&2 9 10if [ -r @scriptdir@/bareos-config-lib.sh ]; then 11 . @scriptdir@/bareos-config-lib.sh 12 if [ -f /usr/share/dbconfig-common/dpkg/config ]; then 13 . /usr/share/dbconfig-common/dpkg/config 14 15 dbc_debug=1 16 # prevent errors by using || true 17 dbc_dbname=`get_database_name bareos` || true 18 dbc_dbuser=`get_database_user bareos` || true 19 20 # only required for sqlite3 21 dbc_basepath=`get_working_dir` 22 23 # convert Bareos databases types into dbconfig_dbtypes 24 dbc_dbtypes="" 25 DB_INSTALLED=`get_databases_installed` 26 if echo "$DB_INSTALLED" | grep -q postgresql; then dbc_dbtypes="${dbc_dbtypes}pgsql, "; fi 27 if echo "$DB_INSTALLED" | grep -q mysql ; then dbc_dbtypes="${dbc_dbtypes}mysql, "; fi 28 if echo "$DB_INSTALLED" | grep -q sqlite3 ; then dbc_dbtypes="${dbc_dbtypes}sqlite3, "; fi 29 # remove trailing , 30 dbc_dbtypes=`echo ${dbc_dbtypes} | sed 's/, *$//'` 31 32 # action 33 if [ $# -gt 0 ]; then 34 param1="$1" 35 shift 36 fi 37 # $2: when action is "configure": most-recently-configured-version 38 if [ $# -gt 0 ]; then 39 param2="$1" 40 param2_orig=$param2 41 shift 42 fi 43 44 # When upgrading from an older version (param2), 45 # do not pass the version number of the old package. 46 # Instead we pass the database version number of the old package. 47 if [ "$param2" ]; then 48 case "$param1" in 49 configure|reconfigure) 50 param2=`get_database_version_by_release "$param2"` 51 52 # dbconfig is available since Bareos version >= 14.1.0. 53 if dpkg --compare-versions "$param2_orig" lt "14.1.0"; then 54 bareos_migrate_to_dbconfig="yes" 55 dbc_first_version="2003" 56 dbc_load_include="sh:/usr/lib/bareos/scripts/set_dbconfig_vars.sh" 57 # empty passwords require special treatment, see below 58 bareos_database_password=`get_database_password` || true 59 # if password is given, set authmethod to password, 60 # otherwise postgresql configuration will stay at default "ident" method. 61 if [ "${bareos_database_password}" ]; then 62 dbc_authmethod_user="password" 63 fi 64 fi 65 ;; 66 *) 67 ;; 68 esac 69 fi 70 71 dbc_go bareos-database-common $param1 $param2 $@ 72 73 if [ "$bareos_migrate_to_dbconfig" = "yes" ]; then 74 # TODO: check if settings app-pass to "" is really required. 75 # Or is it only required for "DEBIAN_FRONTEND=noninteractive" ? 76 case "`get_database_driver`" in 77 postgresql) 78 if [ -z "${bareos_database_password}" ]; then 79 #db_set bareos-database-common/pgsql/authmethod-user "ident" 80 # workaround: if an empty database password is defined, explicitly set it 81 db_set bareos-database-common/pgsql/app-pass "" 82 fi 83 ;; 84 mysql) 85 if [ -z "${bareos_database_password}" ]; then 86 # workaround: if an empty mysql password is defined, explicitly set it 87 db_set bareos-database-common/mysql/app-pass "" 88 fi 89 ;; 90 sqlite3) 91 # dbconfig expects sqlite files as "dbname.db" 92 # while Bareos expects them as "dbname". 93 # A link is created, so that both names matches. 94 if [ -e "${dbc_basepath}/${dbc_dbname}.db" ]; then 95 if ! [ -e "${dbc_basepath}/${dbc_dbname}" ]; then 96 ln -s "${dbc_basepath}/${dbc_dbname}.db" "${dbc_basepath}/${dbc_dbname}" 97 fi 98 fi 99 ;; 100 esac 101 fi 102 fi 103fi 104