Re: should a postinst script create config files?
>>"Brian" == Brian May <bam@debian.org> writes:
Brian> How does ucf work?
Very well ;-)
ucf is meant to be called from the postinst, with the format:
ucf [options] <New file> <Destination>
Now, since you control what the new file is called, you can
use diff3 to create a merged/massaged version of the configuration
file (Shipped in package: /usr/share/<pkg>/conf.old,
/usr/share/<pkg>/conf, and /etc/pkg.conf is the dest).
======================================================================
if [ -e /etc/pkg.conf ]; then
rm -f /etc/pkg.conf.dpkg-new
cp /etc/pkg.conf /etc/pkg.conf.dpkg-new
diff3 -A /etc/pkg.conf.dpkg-new /usr/share/<pkg>/conf.old \
/usr/share/<pkg>/conf >;
fi
ucf /etc/pkg.conf.dpkg-new /etc/pkg.conf
======================================================================
See? Quite simply done. However, the success of this maneuver
is predicated on you determining which version of the file is
installed on the machine, and being able to use that information to
use while generating the diff3. This rapidly gets complex.
Hmm. Heres how that'd work inside ucf (I am eliding how the
variables are set and all)
----------------------------------------------------------------------
if [ -e /etc/pkg.conf ]; then
if [ -e "$statedir/hashfile" ]; then
lastsum=$(grep "[[:space:]]${dest_file}$" "$statedir/hashfile" | \
awk '{print $1;}' )
fi
if [ "X$lastsum" = "X" ]; then
if [ -d "$old_conf_dir" ]; then
for file in ${old_mdsum_dir}/*; do
oldsum=$(md5sum "$file");
if [ "$oldsum" = "$lastsum" ]; then
# Bingo!
cp "$file" /usr/share/<pkg>/conf.old
break
fi
done
fi
fi
rm -f /etc/pkg.conf.dpkg-new
cp /etc/pkg.conf /etc/pkg.conf.dpkg-new
diff3 -A /etc/pkg.conf.dpkg-new /usr/share/<pkg>/conf.old \
/usr/share/<pkg>/conf >;
fi
----------------------------------------------------------------------
If this seems like a worthwhile addition, I'll see if I can
provide this functionality in the ucf package (namely, given a
destination file name, and a directory of historical versions, a
utility shall tell you which version corresponds to the last version
installed; you can then runn diff3 or whatever on your own)
manoj
--
System going down in 5 minutes.
Manoj Srivastava <srivasta@debian.org> <http://www.debian.org/%7Esrivasta/>
1024R/C7261095 print CB D9 F4 12 68 07 E4 05 CC 2D 27 12 1D F5 E8 6E
1024D/BF24424C print 4966 F272 D093 B493 410B 924B 21BA DABB BF24 424C
Reply to: