On 11 October 2015 at 13:45, Felipe Sateler <fsate...@gmail.com> wrote:
> Please implement this helper in dpkg-maintscript-helper;

Please find attached a patch to kickstart the discussion.
Documentation is missing. accept_conffile will move a .dpkg-bak file
left from rm_conffile if upgrading from a version older than the
passed version (or only on first install if empy is passed as
version).

-- 

Saludos,
Felipe Sateler
diff --git a/scripts/dpkg-maintscript-helper.sh 
b/scripts/dpkg-maintscript-helper.sh
index 176920e..438d527 100755
--- a/scripts/dpkg-maintscript-helper.sh
+++ b/scripts/dpkg-maintscript-helper.sh
@@ -229,6 +229,64 @@ abort_mv_conffile() {
 }
 
 ##
+## Functions to accept a conffile removed with rm_conffile in another package
+##
+accept_conffile() {
+       local CONFFILE="$1"
+       local LASTVERSION="$2"
+       local PACKAGE="$3"
+       if [ "$LASTVERSION" = "--" ]; then
+               LASTVERSION=""
+               
PACKAGE="$DPKG_MAINTSCRIPT_PACKAGE${DPKG_MAINTSCRIPT_ARCH:+:$DPKG_MAINTSCRIPT_ARCH}"
+       fi
+       if [ "$PACKAGE" = "--" -o -z "$PACKAGE" ]; then
+               
PACKAGE="$DPKG_MAINTSCRIPT_PACKAGE${DPKG_MAINTSCRIPT_ARCH:+:$DPKG_MAINTSCRIPT_ARCH}"
+       fi
+       # Skip remaining parameters up to --
+       while [ "$1" != "--" -a $# -gt 0 ]; do shift; done
+       [ $# -gt 0 ] || badusage "missing arguments after --"
+       shift
+
+       [ -n "$PACKAGE" ] || error "couldn't identify the package"
+       [ -n "$1" ] || error "maintainer script parameters are missing"
+       [ -n "$DPKG_MAINTSCRIPT_NAME" ] || \
+               error "environment variable DPKG_MAINTSCRIPT_NAME is required"
+
+       debug "Executing $0 mv_conffile in $DPKG_MAINTSCRIPT_NAME" \
+             "of $DPKG_MAINTSCRIPT_PACKAGE"
+       debug "CONFFILE=$CONFFILE PACKAGE=$PACKAGE" \
+             "LASTVERSION=$LASTVERSION ACTION=$1 PARAM=$2"
+       case "$DPKG_MAINTSCRIPT_NAME" in
+       postinst)
+               if [ "$1" = "configure" ] &&
+                  dpkg --compare-versions -- "$2" le-nl "$LASTVERSION"; then
+                       finish_accept_conffile "$CONFFILE" "$PACKAGE"
+               fi
+               ;;
+       *)
+               debug "$0 accept_conffile not required in 
$DPKG_MAINTSCRIPT_NAME"
+               ;;
+       esac
+}
+
+
+finish_accept_conffile() {
+       local CONFFILE="$1"
+       local PACKAGE="$2"
+
+       if [ -e "$CONFFILE.dpkg-bak" ]; then
+               local md5sum="$(md5sum $CONFFILE | sed -e 's/ .*//')"
+               local old_md5sum="$(dpkg-query -W -f='${Conffiles}' $PACKAGE | \
+                       sed -n -e "\' $CONFFILE ' { s/obsolete$//; s/.* //; p 
}")"
+               # Only move if target file has not been modified yet
+               if [ "$md5sum" = "$old_md5sum" ] ; then
+                       mv -f "$CONFFILE.dpkg-bak" "$CONFFILE"
+               fi
+       fi
+}
+
+
+##
 ## Functions to replace a symlink with a directory
 ##
 symlink_to_dir() {
@@ -531,6 +589,9 @@ Commands:
   dir_to_symlink <pathname> <new-symlink-target> [<last-version> [<package>]]
        Replace a directory with a symlink. Must be called in preinst,
        postinst and postrm.
+  accept_conffile <conffile> [<last-version> [<package>]]
+       Accept changes from a conffile that was removed in anothe package.
+       Must be called in postinst.
   help
        Display this usage information.
 END
@@ -555,7 +616,7 @@ shift
 case "$command" in
 supports)
        case "$1" in
-       rm_conffile|mv_conffile|symlink_to_dir|dir_to_symlink)
+       rm_conffile|mv_conffile|symlink_to_dir|dir_to_symlink|accept_conffile)
                code=0
                ;;
        *)
@@ -575,6 +636,9 @@ supports)
 rm_conffile)
        rm_conffile "$@"
        ;;
+accept_conffile)
+       accept_conffile "$@"
+       ;;
 mv_conffile)
        mv_conffile "$@"
        ;;

Reply via email to