Parcourir la source

dpkg-maintscript-helper: make <lastversion> optional in rm_conffile and mv_conffile

Enhance dpkg-maintscript-helper rm_conffile and mv_conffile to work
properly when <lastversion> is not given (or is empty). This should
try the operation on every upgrade but do something only when the file to
act upon really exists.

Document this behaviour.
Raphaël Hertzog il y a 16 ans
Parent
commit
174ea65d4c
3 fichiers modifiés avec 41 ajouts et 21 suppressions
  1. 2 0
      debian/changelog
  2. 14 10
      man/dpkg-maintscript-helper.1
  3. 25 11
      scripts/dpkg-maintscript-helper.sh

+ 2 - 0
debian/changelog

@@ -24,6 +24,8 @@ dpkg (1.15.8) UNRELEASED; urgency=low
   * Clarify that dpkg-maintscript-helper rm_conffile needs the last version of
     the package that did not remove the obsolete conffile if this was not
     implemented at the time the file became obsolete. Closes: #582893
+  * Enhance dpkg-maintscript-helper rm_conffile and mv_conffile to work
+    properly when <lastversion> is not given (or is empty). Closes: #582819
 
   [ Guillem Jover ]
   * Require gettext 0.18:

+ 14 - 10
man/dpkg-maintscript-helper.1

@@ -8,9 +8,9 @@ dpkg\-maintscript\-helper \- works around known dpkg limitations in maintainer s
 .
 .SH COMMANDS AND PARAMETERS
 .P
-\fBrm_conffile\fP \fIconffile\fP \fIlastversion\fP [\fIpackage\fP]
+\fBrm_conffile\fP \fIconffile\fP [\fIlastversion\fP [\fIpackage\fP]]
 .P
-\fBmv_conffile\fP \fIoldconffile\fP \fInewconffile\fP \fIlastversion\fP [\fIpackage\fP]
+\fBmv_conffile\fP \fIoldconffile\fP \fInewconffile\fP [\fIlastversion\fP [\fIpackage\fP]]
 .
 .SH DESCRIPTION
 .P
@@ -58,18 +58,20 @@ All of this is implemented by putting the following shell snippet in the
 \fIlastversion\fP is the last version of the package that contained the
 conffile (or the last version of the package that did not take care to
 remove the obsolete conffile if this was not immediately implemented).
-\fIpackage\fP is the package name, it's optional as it will
+If \fIlastversion\fP is empty or omitted, then the operation is tried
+on every upgrade. \fIpackage\fP is the package name, it's optional as it will
 default to $DPKG_MAINTSCRIPT_PACKAGE (this variable is set by dpkg to the
 name of the package acted upon). All the parameters of the maintainer
 scripts have to be forwarded to the program after "\-\-".
 .P
 Current implementation: in the \fBpreinst\fP, it checks if the conffile
 was modified and renames it either to \fIconffile\fP\fB.dpkg\-remove\fP (if not
-modified) or to \fIconffile\fP\fB.dpkg\-bak\fP (if modified). The latter file is
-kept for reference as it contains user modifications but the former will
-be removed in the \fBpostinst\fP. If the package upgrade aborts, the
-\fBpostrm\fP reinstalls the original conffile. During purge, the
-\fBpostrm\fP will also delete the \fB.dpkg\-bak\fP file kept up to now.
+modified) or to \fIconffile\fP\fB.dpkg\-backup\fP (if modified). In the
+\fBpostinst\fP, the latter file is renamed to \fIconffile\fP\fB.dpkg\-bak\fP
+and kept for reference as it contains user modifications but the former will
+be removed. If the package upgrade aborts, the \fBpostrm\fP reinstalls the
+original conffile. During purge, the \fBpostrm\fP will also delete the
+\fB.dpkg\-bak\fP file kept up to now.
 .
 .SS RENAMING A CONFFILE
 .P
@@ -88,8 +90,10 @@ scripts:
 .P
 \fIoldconffile\fP and \fInewconffile\fP are the old and new name of the
 conffile to rename. \fIlastversion\fP is the last version of the package
-that contained the conffile with the old name. \fIpackage\fP is the
-package name, it's optional as it will default to
+that contained the conffile with the old name. If \fIlastversion\fP is
+empty or omitted, then the operation is tried on every upgrade (note: it's
+safer to give the version and have the operation tried only once). \fIpackage\fP
+is the package name, it's optional as it will default to
 $DPKG_MAINTSCRIPT_PACKAGE (this variable is set by dpkg to the name of the
 package acted upon). All the parameters of the maintainer scripts have to
 be forwarded to the program after "\-\-".

+ 25 - 11
scripts/dpkg-maintscript-helper.sh

@@ -30,6 +30,10 @@ rm_conffile() {
 	local CONFFILE="$1"
 	local LASTVERSION="$2"
 	local PACKAGE="$3"
+	if [ "$LASTVERSION" = "--" ]; then
+		LASTVERSION=""
+		PACKAGE="$DPKG_MAINTSCRIPT_PACKAGE"
+	fi
 	if [ "$PACKAGE" = "--" -o -z "$PACKAGE" ]; then
 		PACKAGE="$DPKG_MAINTSCRIPT_PACKAGE"
 	fi
@@ -49,22 +53,24 @@ rm_conffile() {
 	      "LASTVERSION=$LASTVERSION ACTION=$1 PARAM=$2"
 	case "$DPKG_MAINTSCRIPT_NAME" in
 	preinst)
-		if [ "$1" = "install" -o "$1" = "upgrade" ] &&
+		if [ "$1" = "install" -o "$1" = "upgrade" ] && [ -n "$2" ] &&
 		   dpkg --compare-versions "$2" le-nl "$LASTVERSION"; then
 			prepare_rm_conffile "$CONFFILE" "$PACKAGE"
 		fi
 		;;
 	postinst)
-		if [ "$1" = "configure" ] &&
+		if [ "$1" = "configure" ] && [ -n "$2" ] &&
 		   dpkg --compare-versions "$2" le-nl "$LASTVERSION"; then
 			finish_rm_conffile $CONFFILE
 		fi
 		;;
 	postrm)
 		if [ "$1" = "purge" ]; then
-			rm -f "$CONFFILE.dpkg-bak" "$CONFFILE.dpkg-remove"
+			rm -f "$CONFFILE.dpkg-bak" "$CONFFILE.dpkg-remove" \
+			      "$CONFFILE.dpkg-backup"
 		fi
 		if [ "$1" = "abort-install" -o "$1" = "abort-upgrade" ] &&
+		   [ -n "$2" ] &&
 		   dpkg --compare-versions "$2" le-nl "$LASTVERSION"; then
 			abort_rm_conffile "$CONFFILE"
 		fi
@@ -87,7 +93,7 @@ prepare_rm_conffile() {
 	if [ "$md5sum" != "$old_md5sum" ]; then
 		echo "Obsolete conffile $CONFFILE has been modified by you."
 		echo "Saving as $CONFFILE.dpkg-bak ..."
-		mv -f "$CONFFILE" "$CONFFILE.dpkg-bak"
+		mv -f "$CONFFILE" "$CONFFILE.dpkg-backup"
 	else
 		echo "Moving obsolete conffile $CONFFILE out of the way..."
 		mv -f "$CONFFILE" "$CONFFILE.dpkg-remove"
@@ -97,6 +103,9 @@ prepare_rm_conffile() {
 finish_rm_conffile() {
 	local CONFFILE="$1"
 
+	if [ -e "$CONFFILE.dpkg-backup" ]; then
+		mv -f "$CONFFILE.dpkg-backup" "$CONFFILE.dpkg-bak"
+	fi
 	if [ -e "$CONFFILE.dpkg-remove" ]; then
 		echo "Removing obsolete conffile $CONFFILE ..."
 		rm -f "$CONFFILE.dpkg-remove"
@@ -110,9 +119,9 @@ abort_rm_conffile() {
 		echo "Reinstalling $CONFFILE that was moved away"
 		mv "$CONFFILE.dpkg-remove" "$CONFFILE"
 	fi
-	if [ -e "$CONFFILE.dpkg-bak" ]; then
+	if [ -e "$CONFFILE.dpkg-backup" ]; then
 		echo "Reinstalling $CONFFILE that was backupped"
-		mv "$CONFFILE.dpkg-bak" "$CONFFILE"
+		mv "$CONFFILE.dpkg-backup" "$CONFFILE"
 	fi
 }
 
@@ -124,6 +133,10 @@ mv_conffile() {
 	local NEWCONFFILE="$2"
 	local LASTVERSION="$3"
 	local PACKAGE="$4"
+	if [ "$LASTVERSION" = "--" ]; then
+		LASTVERSION=""
+		PACKAGE="$DPKG_MAINTSCRIPT_PACKAGE"
+	fi
 	if [ "$PACKAGE" = "--" -o -z "$PACKAGE" ]; then
 		PACKAGE="$DPKG_MAINTSCRIPT_PACKAGE"
 	fi
@@ -143,19 +156,20 @@ mv_conffile() {
 	      "LASTVERSION=$LASTVERSION ACTION=$1 PARAM=$2"
 	case "$DPKG_MAINTSCRIPT_NAME" in
 	preinst)
-		if [ "$1" = "install" -o "$1" = "upgrade" ] &&
+		if [ "$1" = "install" -o "$1" = "upgrade" ] && [ -n "$2" ] &&
 		   dpkg --compare-versions "$2" le-nl "$LASTVERSION"; then
 			prepare_mv_conffile "$OLDCONFFILE" "$PACKAGE"
 		fi
 		;;
 	postinst)
-		if [ "$1" = "configure" ] &&
+		if [ "$1" = "configure" ] && [ -n "$2" ] &&
 		   dpkg --compare-versions "$2" le-nl "$LASTVERSION"; then
 			finish_mv_conffile "$OLDCONFFILE" "$NEWCONFFILE"
 		fi
 		;;
 	postrm)
 		if [ "$1" = "abort-install" -o "$1" = "abort-upgrade" ] &&
+		   [ -n "$2" ] &&
 		   dpkg --compare-versions "$2" le-nl "$LASTVERSION"; then
 			abort_mv_conffile "$OLDCONFFILE"
 		fi
@@ -220,7 +234,7 @@ warning() {
 
 usage() {
 	cat <<END
-Syntax: $0 <command> [<parameters>] -- <maintainer script parameters>
+Syntax: $0 <command> <parameters> -- <maintainer script parameters>
 
 Commands and parameters:
 
@@ -228,11 +242,11 @@ Commands and parameters:
 	Returns 0 (success) if the given command is supported, 1
 	otherwise.
 
-  rm_conffile <conffile> <last-version> [<package>]
+  rm_conffile <conffile> [<last-version> [<package>]]
 	Remove obsolete conffile.
 	Must be called in preinst, postinst and postrm.
 
-  mv_conffile <old-conf> <new-conf> <last-version> [<package>]
+  mv_conffile <old-conf> <new-conf> [<last-version> [<package>]]
 	Rename a conffile.
 	Must be called in preinst, postinst and postrm.