File: install-dbconfig

package info (click to toggle)
bacula 15.0.3-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 29,780 kB
  • sloc: ansic: 194,276; cpp: 41,177; sh: 28,258; python: 6,669; makefile: 5,275; perl: 3,666; sql: 1,371; java: 345; xml: 196; awk: 51; sed: 25
file content (149 lines) | stat: -rwxr-xr-x 4,595 bytes parent folder | download
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/sh

# This script creates the files needed by dbc for database creation
# and updates.

# This script needs to be augmented whenever there is a new database update,
# in particular "lastdbversion" and the case statements need to be reviewed.

# Due to upstream changes in Bacula 11, upgrade extractions for 7.2.0
# and later are now handled by hand with the help of
# extract-dbupgrade-v13 until someone can find a solution to automate
# them again. Relevant code is commented with #!#
# - leo@debian.org, 2022-03-24

# (C) 2016-2024 Carsten Leonhardt <leo@debian.org>

# License: expat

# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:

#     The above copyright notice and this permission notice shall be
#     included in all copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# first and last target database version covered by this script
dbtarget=11
lastdbversion=1026

variants="mysql pgsql sqlite3"

dbc="usr/share/dbconfig-common/data"
extractor="debian/scripts/extract-dbupgrade.awk"

set_longdb() {
    if [ $db = pgsql ] ; then
	longdb=postgresql
    else
	longdb=$db
    fi
}


# handle older db upgrades
while [ $dbtarget -le 12 ]; do
    for db in $variants; do
	set_longdb

	case $dbtarget in
	    11)	baculaversion="3.0.0"
		sourcefile="updatedb/update_"$longdb"_tables_10_to_11"
		;;
	    12)	baculaversion="5.0.0"
		sourcefile="updatedb/update_"$longdb"_tables_11_to_12"
		;;
	esac

	targetfile="debian/bacula-director-"$db"/"$dbc"/bacula-director-"$db"/upgrade/"$db"/"$baculaversion;

	mkdir -p `dirname $targetfile`
	awk -v version=ignore -f $extractor $sourcefile | sed 's/\\//g' >> $targetfile
    done

    dbtarget=$((dbtarget + 1))
done

# handle newer db upgrades
while [ $dbtarget -le $lastdbversion ]; do
    for db in $variants; do
	set_longdb

	case $dbtarget in
	    13)	baculaversion="5.2.0"
		;;
	    14)	baculaversion="5.2.0"
		;;
	    15)	baculaversion="7.2.0"
		;;
	    16)	baculaversion="9.0.0"
		;;
	    1017) baculaversion="11.0.0~1017"
		;;
	    1018 | 1019 | 1020 | 1021 | 1022) baculaversion="11.0.0"
					      ;;
	    1023 | 1024) baculaversion="13.0.0"
			 ;;
	    1025 | 1026) baculaversion="15.0.0"
			 ;;
	    *)	echo "$0: Unknown database target version"
		exit 1
		;;
	esac

	sourcefile="src/cats/update_"$longdb"_tables"
	targetfile="debian/bacula-director-"$db"/"$dbc"/bacula-director-"$db"/upgrade/"$db"/"$baculaversion;

	mkdir -p `dirname $targetfile`
	awk -v version=$dbtarget -f $extractor $sourcefile | sed 's/\\//g' >> $targetfile
    done

    if [ $dbtarget = 14 ]
    then
	# special case, we skip the updates this script can't handle
	dbtarget=1025
    # elif [ $dbtarget = 16 ] # never reached du to jumping from 14 to 1025
    # 	# special case, a jump from 16 to 1017
    # 	dbtarget=1017
    else
	dbtarget=$((dbtarget + 1))
    fi
done

# handle db creation
for db in $variants; do
    set_longdb

    sourcefile="src/cats/make_"$longdb"_tables"
    targetfile="debian/bacula-director-"$db"/"$dbc"/bacula-director-"$db"/install/"$db;

    mkdir -p `dirname $targetfile`
    awk -v version=ignore -f $extractor $sourcefile | sed 's/\\//g' >> $targetfile
done

# check if this script needs to be updated
# we check for all db types just to be on the safe side
for db in $variants; do
    set_longdb

    sourcefile="src/cats/make_"$longdb"_tables"
    # this looks where the current database version is inserted in the make_(db)_tables script and extracts it
    current_bacula_db_version=`sed -n 's/INSERT INTO Version (VersionId) VALUES (\([0-9]*\));/\1/ip' $sourcefile`
    if [  $current_bacula_db_version -ne $lastdbversion ]; then
	echo "error: unsupported database version $current_bacula_db_version, please update $0!"
	exit 1
    fi
done