tags 333460 patch
thanks

On Wed, Oct 12, 2005 at 02:55:31AM +0200, Jonas Meurer wrote:
> the latest upgrade of fonty has overwritten my local settings in
> /etc/console-tools/config.d/fonty. It would be better to handle this
> file as a configuration file as defined in the debian policy.
> 
> The upgrade did not even preserve a backup copy (for example a .dpkg-old
> file), it just erased my local settings.
> 
> There are several cases where local modifications are required in
> /etc/console-tools/config.d/fonty, especially as the debconf
> configuration dialog at install/upgrade does not list fonts from other
> packages (like fonty-rg). It would be great if that could be improved.

I've looked a bit into fixing this problem, and I think I've come up
with a solution.

Fonty manages /etc/console-tools/config.d/fonty itself using the
maintainer scripts, because it needs to set different values
depending on the answer of a debconf question. However in the
postinst step (configure) it overwrites the old config file without
checking for modifications. The relevant piece of code is this:

==================================================================
# install configuration file with debconf
if [ "$1" = "configure" ]; then
    CONFDIR=/etc/console-tools/config.d
    CONF=$CONFDIR/fonty
    RET=""
    db_get fonty/charset || true
    if [ -n "$RET" -a "$RET" != "none" ]; then
[...]
        test -d $CONFDIR || mkdir -p $CONFDIR
        cat > $CONF.dpkg-tmp << END
###DEBCONF###
# the configuration of this file was done by debconf and can be
# overwritten.
#
# you should use dpkg-reconfigure fonty to configure this file.
#
END
        echo "SCREEN_FONT=iso${CHARSET}graf-16" >> $CONF.dpkg-tmp
        echo "APP_CHARSET_MAP=iso$MAP" >> $CONF.dpkg-tmp
        echo "FALLBACK_TAB=fonty" >> $CONF.dpkg-tmp
[...]
        mv -f $CONF.dpkg-tmp $CONF
[...]
    fi
fi
==================================================================

So the config file is overwritten if the user has given an answer
other then "none" to the debconf question, which is pretty
standard.

I've come up with a patch that tries to solve this problem. The idea
is to only overwrite $CONF if the "###DEBCONF###" line is in there,
and to tell users to remove that line if they change anything. This
should work fine for all future versions AFAICS.

Now the problem is what happens when a user upgrades from <= 1.0-23
to a later version.

The format of the config file hasn't changed at all since at least
1.0-22 (the sarge/etch version). So I rebuild the file in exactly
the same way as previous versions did, and then compare $CONF to
that reference file. If they are the same, one can assume that the
user hasn't modified anything, so we can just overwrite it.

If the file is different, it is possible that the user modified the
file, so we remove the ###DEBCONF### line, so the file won't be
touched later.

This should make a smooth transition possible (hopefully).

The only problem that I see currently is the possibility of false
positives in the is-$CONF-different check. This could happen if the
user changed something in the setup of his VT's in the meantime.
I'm not sure how likely that is, but perhaps a debconf question
would be appropriate here.

The patch that does all this is reattached. I've tested all the
possible scenarios and it seemed to work well.

Cheers,
Christian Aichinger
diff -u fonty-1.0/debian/packages fonty-1.0/debian/packages
--- fonty-1.0/debian/packages
+++ fonty-1.0/debian/packages
@@ -112,10 +112,16 @@
      mv -f /etc/init.d/fonty.dpkg-tmp /etc/init.d/fonty && true
  fi
  .
- # install configuration file with debconf
- if [ "$1" = "configure" ]; then
-     CONFDIR=/etc/console-tools/config.d
-     CONF=$CONFDIR/fonty
+ CONFDIR=/etc/console-tools/config.d
+ CONF=$CONFDIR/fonty
+ .
+ # Avoid overwriting of /etc/console-tools/config.d/fonty
+ # if the user manually edited it (cf. #333460)
+ if [ "$1" = "configure" -a -f "$CONF" ] \
+     && dpkg --compare-versions "$2" le-nl "1.0-23"; then
+     # We create the file exactly the same way as with older versions, if the
+     # md5sum of the config file and the reference file match, we conclude that
+     # nothing changed and it's safe to overwrite the config file.
      RET=""
      db_get fonty/charset || true
      if [ -n "$RET" -a "$RET" != "none" ]; then
@@ -154,6 +160,64 @@
                  fi
              done
          fi
+     fi
+     MD5CONF=`md5sum < "$CONF"`
+     MD5REF=`md5sum < "$CONF.dpkg-tmp"`
+     if [ "$MD5CONF" = "$MD5REF" ]; then
+         # File hasn't changed, recreate it
+         rm -f $CONF $CONF.dpkg-tmp
+     else
+         # Remove the DEBCONF line, so the file won't be altered by the next 
step
+         sed -e '/^###DEBCONF###$/d' $CONF > $CONF.dpkg-tmp
+         mv -f $CONF.dpkg-tmp $CONF
+     fi
+ fi
+ .
+ # Install a new version of the configuration file
+ # Do it if $CONF doesn't exist, or if it exists and has the DEBCONF marker
+ if [ "$1" = "configure" ] && ( ! [ -e "$CONF" ] || \
+     grep '^###DEBCONF###$' -- $CONF >/dev/null 2>&1 ); then
+     RET=""
+     db_get fonty/charset || true
+     if [ -n "$RET" -a "$RET" != "none" ]; then
+         if [ -d /dev/vc ]; then
+             DEV="/dev/vc/"
+         else
+             DEV="/dev/tty"
+         fi
+         CHARSET=$(echo $RET | sed 's/^iso\([0-9]*\).*/\1/')
+         MAP=$(echo $CHARSET | sed 's/^\([0-9]\)$/0\1/')
+         test -d $CONFDIR || mkdir -p $CONFDIR
+         cat > $CONF.dpkg-tmp << END
+ ###DEBCONF###
+ # This configuration was automatically created from debconf answers.
+ #
+ # If you manually alter it, you HAVE TO REMOVE the "###DEBCONF###" header
+ # above. Otherwise this file will be overwritten the next time you upgrade the
+ # package.
+ #
+ # You should use dpkg-reconfigure fonty to configure this file.
+ #
+ END
+         echo "SCREEN_FONT=iso${CHARSET}graf-16" >> $CONF.dpkg-tmp
+         echo "APP_CHARSET_MAP=iso$MAP" >> $CONF.dpkg-tmp
+         echo "FALLBACK_TAB=fonty" >> $CONF.dpkg-tmp
+         nextvt=$(fgconsole -n || echo 0)
+         if [ -n "$nextvt" -a "$nextvt" -gt 0 -a "$nextvt" -le 63 ] 
2>/dev/null; then
+             vt=1
+             while [ "$vt" -lt "$nextvt" ]; do
+                 echo "SCREEN_FONT_vc$vt=iso${CHARSET}graf-16" >> 
$CONF.dpkg-tmp
+                 echo "APP_CHARSET_MAP_vc$vt=iso$MAP" >> $CONF.dpkg-tmp
+                 echo "FALLBACK_TAB_vc$vt=fonty" >> $CONF.dpkg-tmp
+                 vt=$((vt+1))
+                 sttyn=$(echo $(stty < ${DEV}$vt))
+                 speedn=${sttyn%%;*}
+                 if [ "$speedn" = "speed 0 baud" \
+                   -o "$sttyn" = "speed 38400 baud; line = 0; -brkint 
-imaxbel" ]; then
+                     break
+                 fi
+             done
+         fi
          mv -f $CONF.dpkg-tmp $CONF
          db_reset fonty/restart || true
          db_subst fonty/restart webserver "$webserver"

Attachment: signature.asc
Description: Digital signature

Reply via email to