[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Moving a config file



Hello all,

I have to move a config file, and I am not sure of the best way of
handling it, so I wanted to ask for opinions.

The problem is that I am currently shipping an /etc/default/$package,
which needs to now become /etc/$package.conf - it's not a shell script,
but more of a hacked together config file.  What I want to do is ensure
that any user changes to the old /etc/default/$package file get
seemlessly merged into /etc/$package.conf, but not mess up any user made
up $package.conf

Does the following postinst snippet do it, or should I let standard dpkg
config file handling take care of it, or does anyone have other
suggestions?

# HDPARM_OLD is the md5sum of the unmodified file
HDPARM_MD5=`md5sum /etc/default/hdparm | awk '{print $1}'`
HDPARM_CONF=`md5sum /etc/hdparm.conf | awk '{print $1}'`
HDPARM_OLD="9578464c1ae847fc33d58e049f8c08fc"

if [ -f /etc/hdparm.conf ]; then
  if [ ! $HDPARM_CONF = $HDPARM_OLD ]; then
    echo -n "Backing up old hdparm.conf . . "
    mv /etc/hdparm.conf /etc/hdparm.conf.dpkg-old
    echo "done"
  fi
fi

if [ -f /etc/default/hdparm ]; then
  if [ $HDPARM_MD5 = $HDPARM_OLD ]; then
    # New basic default config file already added, just remove cruft
    rm /etc/default/hdparm
  else
    echo -n "Moving /etc/default/hdparm to /etc/hdparm.conf . . "
    mv /etc/default/hdparm /etc/hdparm.conf
    echo "done"
  fi
fi

There is also a note in README.Debian that the config file location has 
changed.  The problem I see with the above is that by the time postinst 
runs, there will already be /etc/hdparm.conf, as it is shipped in the
package.  So I see the flow of logic as, if /etc/hdparm.conf exists, and
is changed (most likely the user has made their own), then back up
theirs - if it is the same as the shipped, do nothing.  If the old
config file exists, but is unchanged, remove it - they now have the new
config file.  If it is changed, mv it to the new location.

Thanks for any comments,

-- 
 -----------------------------------------------------------------
|   ,''`.					     Stephen Gran |
|  : :' :					 sgran@debian.org |
|  `. `'			Debian user, admin, and developer |
|    `-					    http://www.debian.org |
 -----------------------------------------------------------------

Attachment: pgpBXMOb0B0kO.pgp
Description: PGP signature


Reply to: