소스 검색

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 16 년 전
부모
커밋
174ea65d4c
3개의 변경된 파일41개의 추가작업 그리고 21개의 파일을 삭제
  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
   * 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
     the package that did not remove the obsolete conffile if this was not
     implemented at the time the file became obsolete. Closes: #582893
     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 ]
   [ Guillem Jover ]
   * Require gettext 0.18:
   * 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
 .SH COMMANDS AND PARAMETERS
 .P
 .P
-\fBrm_conffile\fP \fIconffile\fP \fIlastversion\fP [\fIpackage\fP]
+\fBrm_conffile\fP \fIconffile\fP [\fIlastversion\fP [\fIpackage\fP]]
 .P
 .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
 .SH DESCRIPTION
 .P
 .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
 \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
 conffile (or the last version of the package that did not take care to
 remove the obsolete conffile if this was not immediately implemented).
 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
 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
 name of the package acted upon). All the parameters of the maintainer
 scripts have to be forwarded to the program after "\-\-".
 scripts have to be forwarded to the program after "\-\-".
 .P
 .P
 Current implementation: in the \fBpreinst\fP, it checks if the conffile
 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
 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
 .SS RENAMING A CONFFILE
 .P
 .P
@@ -88,8 +90,10 @@ scripts:
 .P
 .P
 \fIoldconffile\fP and \fInewconffile\fP are the old and new name of the
 \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
 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
 $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
 package acted upon). All the parameters of the maintainer scripts have to
 be forwarded to the program after "\-\-".
 be forwarded to the program after "\-\-".

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

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