[pkg-bacula-commits] [bacula] 33/35: Use perl script to handle dbconfig installs

Carsten Leonhardt leo at moszumanska.debian.org
Wed Jul 20 10:21:41 UTC 2016


This is an automated email from the git hooks/post-receive script.

leo pushed a commit to tag development/2011-04-29
in repository bacula.

commit cba7b616366901f478d9cce3a5ff0d28811ade42
Author: Jan Hauke Rahm <jhr at debian.org>
Date:   Fri Apr 29 14:05:17 2011 +0200

    Use perl script to handle dbconfig installs
---
 debian/rules                    | 38 +++---------------
 debian/scripts/extract_here     |  8 ----
 debian/scripts/install-dbconfig | 86 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 91 insertions(+), 41 deletions(-)

diff --git a/debian/rules b/debian/rules
index d512e9b..53ef6a8 100755
--- a/debian/rules
+++ b/debian/rules
@@ -54,33 +54,6 @@ LONGNAME_sqlite3	= sqlite3
 
 ###########################################################################
 
-# Macro to extract a here document and put it in place
-# args: 1 -- db name, 2 -- file to extract, 3 -- version
-define ext-upgrade
-mkdir -p debian/bacula-director-$(1)/$(DBC)/bacula-director-$(1)/upgrade/$(1) && debian/scripts/extract_here < $(2) > debian/bacula-director-$(1)/$(DBC)/bacula-director-$(1)/upgrade/$(1)/$(3)
-endef
-
-# Macro to upgrade db
-# args: 1 -- db type
-#       2 -- db version path (e.g. 10_to_11)
-#       3 -- package version
-define ext-upgrade-db
-$(call ext-upgrade,$(1),$(CURDIR)/updatedb/update_$(LONGNAME_$(1))_tables_$(2).in,$(3))
-endef
-
-# Macro to process latest version upgrades for db
-# args: 1 -- db type
-#       2 -- package version
-define ext-upgrade-latest-db
-$(call ext-upgrade,$(1),$(CURDIR)/src/cats/update_$(LONGNAME_$(1))_tables.in,$(2))
-endef
-
-# Macro to extract a here document for install and put it in place
-# args: 1 -- db name
-define ext-install-db
-mkdir -p debian/bacula-director-$(1)/$(DBC)/bacula-director-$(1)/install && debian/scripts/extract_here < $(CURDIR)/src/cats/make_$(LONGNAME_$(1))_tables.in > debian/bacula-director-$(1)/$(DBC)/bacula-director-$(1)/install/$(1)
-endef
-
 %:
 	dh $@
 
@@ -112,18 +85,17 @@ override_dh_installinit:
 	dh_installinit --name=bacula-director -pbacula-director-sqlite3 --no-start -- defaults 92 8
 
 override_dh_install:
-	chmod 755 debian/scripts/extract_here
+	chmod 755 debian/scripts/install-dbconfig
 	dh_install
 	chmod 755 debian/bacula-common/usr/lib/bacula/btraceback
 	######### dbconfig-common stuff
 	# Sometimes the latest release doesn't have a copy of the data in updatedb.
-	# Manually install those.  CHECK THIS FOR EACH NEW RELEASE, and move older
-	# versions to an ext-upgrade-db line.
+	# Manually install those. CHECK THIS FOR EACH NEW RELEASE!
 	#
 	# lenny -> squeeze is 10 -> 12
-	$(foreach db,$(VARIANTS),$(call ext-upgrade-db,$(db),10_to_11,3.0.0))
-	$(foreach db,$(VARIANTS),$(call ext-upgrade-latest-db,$(db),5.0.0))   # 5.0.0 upgrade 11 to 12
-	$(foreach db,$(VARIANTS),$(call ext-install-db,$(db)))
+	$(foreach db,$(VARIANTS),$(shell debian/scripts/install-dbconfig $(db) 3.0.0 11)) # 3.0.0 upgrade 10 to 11
+	$(foreach db,$(VARIANTS),$(shell debian/scripts/install-dbconfig $(db) 5.0.0))    # 5.0.0 upgrade 11 to 12
+	$(foreach db,$(VARIANTS),$(shell debian/scripts/install-dbconfig $(db)))
 
 override_dh_installdocs:
 	dh_installdocs -pbacula --link-doc=bacula-common
diff --git a/debian/scripts/extract_here b/debian/scripts/extract_here
deleted file mode 100644
index f431f46..0000000
--- a/debian/scripts/extract_here
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/usr/bin/perl
-# Extract a shell-style here-document from a script
-$found = 0;
-while (<>) {
-      if (m/END.OF.DATA/ && !$found) {$found = 1; next;};
-      last if (m/END.OF.DATA/);
-      print if $found;
-}
diff --git a/debian/scripts/install-dbconfig b/debian/scripts/install-dbconfig
new file mode 100755
index 0000000..44743d3
--- /dev/null
+++ b/debian/scripts/install-dbconfig
@@ -0,0 +1,86 @@
+#!/usr/bin/perl
+
+# Script to install files used by dbconfig-common to install and upgrade
+# databases
+# (c) 2011 Debian project, Jan Hauke Rahm <jhr at debian.org>
+# Based on make macros written by John Goerzen
+
+# Arguments needed:
+# 1: database type (sqlite3, mysql, pgsql)
+# 2: package version
+# 3: bacula database version to support
+#
+# There are three ways to call this script:
+# 1) ./script db-type
+# 2) ./script db-type version
+# 3) ./script db-type version bacula-db
+#
+# The first will install the SQL stuff needed to create the database during
+# package installations. The second will install the SQL stuff needed to
+# upgrade to the latest version of the bacula-db. The third will install
+# additional SQL upgrade stuff if we skipped a bacula db version in Debian.
+#
+# Example: lenny had package version 2.4.4 with bacula db version 10, squeeze has
+#          package version 5.0.0 with bacula db version 12.
+#          Always needed is the installation stuff:
+#    ./script db-type
+#          Then we need to migrate the db from 10 (2.4.4) to 11 (3.0.0)
+#    ./script db-type 3.0.0 11
+#          Finally we need to migrate from 11 to 12 (3.0.0 to 5.0.0) which
+#          upstream ships as "latest upgrade"
+#    ./script db-type 5.0.0
+
+use strict;
+use File::Path "make_path";
+
+my $DBC = "usr/share/dbconfig-common/data";
+
+my $db		= $ARGV[0];
+my $pkgver	= $ARGV[1];
+my $dbver	= $ARGV[2];
+
+my $longdb	= $db;
+$longdb = ($db == "pgsql") ? "postgresql" : $db;
+
+if (@ARGV == 1) {
+	install($db);
+} elsif (@ARGV == 2) {
+	latest($db, $pkgver);
+} elsif (@ARGV == 3) {
+	update($db, $pkgver, $dbver);
+} else {
+	exit 1;
+}
+
+sub install {
+	make_path("debian/bacula-director-$db/$DBC/bacula-director-$db/install");
+	extract_here("src/cats/make_".$longdb."_tables.in", "debian/bacula-director-$db/$DBC/bacula-director-$db/install/$db");
+}
+
+sub latest {
+	make_path("debian/bacula-director-$db/$DBC/bacula-director-$db/upgrade/$db");
+	extract_here("src/cats/update_".$longdb."_tables.in", "debian/bacula-director-$db/$DBC/bacula-director-$db/upgrade/$db/$pkgver");
+}
+
+sub update {
+	my $path = ($dbver - 1) . "_to_" . $dbver;
+
+	make_path("debian/bacula-director-$db/$DBC/bacula-director-$db/upgrade/$db");
+	extract_here("updatedb/update_".$longdb."_tables_$path.in", "debian/bacula-director-$db/$DBC/bacula-director-$db/upgrade/$db/$pkgver");
+}
+
+sub extract_here {
+	my $input = shift;
+	my $output = shift;
+
+	my $found = 0;
+
+	open (INPUT, '<', $input);
+	open (OUTPUT, '>', $output);
+	while (<INPUT>) {
+		if (m/END.OF.DATA/ && !$found) {$found = 1; next;};
+		last if (m/END.OF.DATA/);
+		print OUTPUT $_ if $found;
+	}
+	close (INPUT);
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-bacula/bacula.git



More information about the pkg-bacula-commits mailing list