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