Package: sks
Severity: normal

Hi,

I have prepared patch for upgrade to Berkeley DB version 5.1 and I
have also written automagic upgrade of Berkeley DB database files
(based on script I have written for cyrus-imapd).

I have tested that in pbuilder environment, so it needs some more live
testing, but so far it looks good.

O.

-- System Information:
Debian Release: 6.0.1
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.32-5-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=cs_CZ.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
diff --git a/debian/NEWS b/debian/NEWS
index 428a9f7..a2e7ffd 100644
--- a/debian/NEWS
+++ b/debian/NEWS
@@ -1,3 +1,12 @@
+sks (1.1.1+dpkgv3-6.1) unstable; urgency=low
+
+  sks now uses a Berkeley DB version 5.1 without XA environment.
+  The postinst script should upgrade the database automatically.
+  There will be backup in /var/backups/sks in case something went
+  wrong.
+
+ -- Ondřej Surý <ond...@debian.org>  Fri, 13 May 2011 12:38:29 +0200
+
 sks (1.1.1+dpkgv3-1) unstable; urgency=high
 
    *** NOTE ***
diff --git a/debian/README.Debian b/debian/README.Debian
index 3793735..d263f14 100644
--- a/debian/README.Debian
+++ b/debian/README.Debian
@@ -21,20 +21,6 @@ To make the server start you have to edit the defaults file:
 
  vi /etc/default/sks
 
-If you have an old database from a Berkely DB Version (e.g 4.6) prior to the
-current version (at the moment 4.7) you have to do the following in
-/var/lib/sks/DB and /var/lib/sks/PTree:
-
- db4.6_checkpoint -1
- db4.6_recover
- db4.7_recover -e
- db4.7_checkpoint -1
- db4.7_archive | xargs --no-run-if-empty rm -f
-
- chown -R debian-sks:debian-sks /var/lib/sks /var/log/sks
-
-Then you can start the database with /etc/init.d/sks start.
-
 If you want to connect to the global sks-network, send a mail to
 pgp-keyserver-f...@flame.org or sks-de...@nongnu.org and ask for
 gossip partners. Include the partners in /etc/sks/membership.
@@ -44,4 +30,4 @@ gossip partners. Include the partners in /etc/sks/membership.
 Thanks to Peter Palfrader <wea...@debian.org> for building the
 original Debian package.
 
- -- Christoph Martin <christoph.mar...@uni-mainz.de>, Mon, 27 Sep 2010 12:07:30 +0200
+ -- Ondřej Surý <ond...@debian.org>, Fri, 13 May 2011 13:15:18 +0200
diff --git a/debian/changelog b/debian/changelog
index 6ac97ae..7a2fd10 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,12 @@
+sks (1.1.1+dpkgv3-6.1) unstable; urgency=low
+
+  * Non-maintainer upload.
+  * Remove XA environment usage (patch from upstream) and use generic -ldb
+    library to link with (Closes: #621384)
+  * Add automagick upgrade of Berkeley DB databases (Closes: #606183)
+
+ -- Ondřej Surý <ond...@debian.org>  Fri, 13 May 2011 12:33:13 +0200
+
 sks (1.1.1+dpkgv3-6) unstable; urgency=high
 
   * fix to not really working fix for strip of bytecode (closes: 599029)
diff --git a/debian/control b/debian/control
index e12d147..f3d9af2 100644
--- a/debian/control
+++ b/debian/control
@@ -4,7 +4,7 @@ Priority: optional
 Standards-Version: 3.8.3
 Maintainer: Christoph Martin <christoph.mar...@uni-mainz.de>
 Uploaders: Fabio M. Di Nitto <fabbi...@fabbione.net>
-Build-Depends: ocaml (>= 3.08), camlp4, libdb4.7-dev, debhelper (>= 7.0.50~), zlib1g-dev, libcryptokit-ocaml-dev (>= 1.2-4), ocaml-nox (>= 1.3-4), perl, perl-doc
+Build-Depends: ocaml (>= 3.08), camlp4, libdb-dev, debhelper (>= 7.0.50~), zlib1g-dev, libcryptokit-ocaml-dev (>= 1.2-4), ocaml-nox (>= 1.3-4), perl, perl-doc
 
 Package: sks
 Architecture: any
diff --git a/debian/patches/203_db.patch b/debian/patches/203_db.patch
new file mode 100644
index 0000000..86e327e
--- /dev/null
+++ b/debian/patches/203_db.patch
@@ -0,0 +1,11 @@
+--- a/bdb/Makefile
++++ b/bdb/Makefile
+@@ -29,7 +29,7 @@
+ OCAMLOPTFLAGS=$(COMMONCAMLFLAGS) -inline 40 
+ 
+ ifndef LIBDB
+-LIBDB=-ldb-4.6
++LIBDB=-ldb
+ endif
+ 
+ COBJS = bdb_stubs.o
diff --git a/debian/patches/203_db47.patch b/debian/patches/203_db47.patch
deleted file mode 100644
index c914190..0000000
--- a/debian/patches/203_db47.patch
+++ /dev/null
@@ -1,11 +0,0 @@
---- a/bdb/Makefile
-+++ b/bdb/Makefile
-@@ -29,7 +29,7 @@
- OCAMLOPTFLAGS=$(COMMONCAMLFLAGS) -inline 40 
- 
- ifndef LIBDB
--LIBDB=-ldb-4.6
-+LIBDB=-ldb-4.7
- endif
- 
- COBJS = bdb_stubs.o
diff --git a/debian/patches/512_no_XA_berkeleydb.patch b/debian/patches/512_no_XA_berkeleydb.patch
new file mode 100644
index 0000000..303988b
--- /dev/null
+++ b/debian/patches/512_no_XA_berkeleydb.patch
@@ -0,0 +1,44 @@
+--- a/bdb/bdb.ml
++++ b/bdb/bdb.ml
+@@ -55,7 +55,7 @@ struct
+ 
+   type t = db
+ 
+-  type create_flag = XA_CREATE
++  type create_flag
+ 
+   type open_flag = 
+      CREATE | EXCL | NOMMAP | RDONLY | THREAD | TRUNCATE | AUTO_COMMIT
+--- a/bdb/bdb_stubs.c
++++ b/bdb/bdb_stubs.c
+@@ -371,11 +371,10 @@ value caml_dbenv_set_cachesize(value dbe
+ 
+ /**  DB Flags  ***********************************************/
+ static int db_create_flags[] = {
+-  DB_XA_CREATE
+ };
+ 
+ //+
+-//+   type create_flag = XA_CREATE
++//+   type create_flag
+ 
+ static int db_open_flags[] = {
+   DB_CREATE, DB_EXCL, DB_NOMMAP, DB_RDONLY, DB_THREAD, 
+@@ -424,11 +423,16 @@ static int db_set_flags[] = {
+ value caml_db_create(value dbenv_opt, value vflags){
+   CAMLparam2(dbenv_opt,vflags);
+   int err;
+-  int flags = convert_flag_list(vflags,db_create_flags);
++  int flags;
+   DB *db;
+   DB_ENV *dbenv;
+   CAMLlocal1(rval);
+ 
++  /* The flags parameter is currently unused, and must be set to 0. */
++  if (vflags != Val_emptylist)
++    invalid_argument("DB.create invalid create flag");
++  flags = convert_flag_list(vflags,db_create_flags);
++
+   if (Is_None(dbenv_opt)) { dbenv = NULL; }
+   else { 
+     test_dbenv_closed(Some_val(dbenv_opt));
diff --git a/debian/patches/series b/debian/patches/series
index 610aac0..5aed2c9 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1,5 +1,5 @@
 202_makefile_bytecode.patch 
-203_db47.patch 
+203_db.patch 
 500_debian_fhs.patch 
 501_makefile_cflags.patch 
 502_makefile_install.patch 
@@ -7,3 +7,4 @@
 509-content-types.patch 
 510-allowed-chars.patch 
 511_gcc44.patch 
+512_no_XA_berkeleydb.patch
diff --git a/debian/rules b/debian/rules
index c02bf8b..663eb49 100755
--- a/debian/rules
+++ b/debian/rules
@@ -12,6 +12,8 @@ OCAMLRUN = $(if $(BYTECODE),ocaml-base-nox-$(OCAMLABI))
 
 export DEB_BUILD_OPTIONS += $(if $(BYTECODE)," nostrip",)
 
+BDB_VERSION ?= $(shell LC_ALL=C dpkg-query -l 'libdb[45].[0-9]-dev' | grep ^ii | sed -e 's|.*\s\libdb\([45]\.[0-9]\)-dev\s.*|\1|')
+
 %:
 	dh  $@
 
@@ -23,6 +25,7 @@ override_dh_auto_install:
 	$(MAKE) PREFIX="$(TMP)/usr" MANDIR="$(TMP)/usr/share/man" $(install)
 #	Debian specific
 	cp -a debian/debcfg/* debian/sks/etc/sks
+	echo $(BDB_VERSION) > debian/sks/usr/lib/sks/berkeley_db.txt
 
 override_dh_gencontrol:
 	dh_gencontrol -- -VF:OCamlRun="$(OCAMLRUN)"
diff --git a/debian/sks.postinst b/debian/sks.postinst
index 78f05ea..854d2d1 100755
--- a/debian/sks.postinst
+++ b/debian/sks.postinst
@@ -68,6 +68,65 @@ else
 		fi
 	    done
 	fi
+
+	# Read the active Berkeley DB version, fall back to 4.7 if not found
+	if [ -r /var/lib/sks/berkeley_db.active ]; then
+	    OLD_BDB=$(cat /var/lib/sks/berkeley_db.active)
+	else
+	    if dpkg --compare-versions "$2" lt "1.1.1+dpkgv3-1"; then
+		OLD_BDB=4.6
+	    elif dpkg --compare-versions "$2" lt "1.1.1+dpkgv3-6.1"; then
+		OLD_BDB=4.7
+	    else
+		OLD_BDB=4.7
+	    fi
+	fi
+
+	# Read the compiled-in Berkeley DB version
+	NEW_BDB=$(cat /usr/lib/sks/berkeley_db.txt)
+
+	# Upgrade Berkeley DB in place
+	BACKUP_DIR=/var/backup/sks/$(date +%Y%m%d-%H%M%S)
+	SKS_DIR=/var/lib/sks
+	mkdir -p $BACKUP_DIR
+	chown debian-sks:debian-sks ${BACKUP_DIR}
+
+	for DBHOME in DB PTree; do
+	    # Create backup directory
+	    mkdir -p ${BACKUP_DIR}/${DBHOME}
+	    chown debian-sks:debian-sks ${BACKUP_DIR}/${DBHOME}
+
+	    # Make sure we own the files
+	    chown debian-sks:debian-sks -R ${SKS_DIR}/${DBHOME}
+
+	    if [ -x /usr/bin/db${OLD_BDB}_recover ]; then
+	        # Run recover with old tools
+		su debian-sks -c "db${OLD_BDB}_recover -h ${SKS_DIR}/${DBHOME}"
+	        # Backup log files
+		su debian-sks -c "db${OLD_BDB}_archive -h ${SKS_DIR}/${DBHOME} -l" | \
+		    while read log_file; do
+		    cp -a ${SKS_DIR}/${DBHOME}/$log_file ${BACKUP_DIR}/${DBHOME}/
+		done
+	    else
+		# If we don't have the Berkeley DB tools then copy everything to backup
+		su debian-sks -c "cp ${SKS_DIR}/${DBHOME}/log.* ${BACKUP_DIR}/${DBHOME}/"
+	    fi
+
+	    for db in $(cd ${SKS_DIR}/${DBHOME}; ls -1 | grep -Ev "^(__|log\.)"); do
+		# Backup database file
+		su debian-sks -c "cp ${SKS_DIR}/${DBHOME}/${db} ${BACKUP_DIR}/${DBHOME}/"
+		# Upgrade database file
+    		su debian-sks -c "db${NEW_BDB}_upgrade -h ${SKS_DIR}/${DBHOME} ${SKS_DIR}/${DBHOME}/$db";
+	    done
+    
+	    # Set checkpoint and delete old logfiles
+	    su debian-sks -c "db${NEW_BDB}_checkpoint -h ${SKS_DIR}/${DBHOME} -1"
+	    su debian-sks -c "db${NEW_BDB}_archive -h ${SKS_DIR}/${DBHOME} -d"
+	done
+
+	# Note the active Berkeley DB version
+	cp -f /usr/lib/sks/berkeley_db.txt /var/lib/sks/berkeley_db.active
+
     fi
 fi
 

Reply via email to