Re: RFS: jabber-querybot
On Wed, 23 Nov 2011 15:21:38 +0100, Marco Balmer wrote:
- d/preinst: Implemented according to your remarks.
Almost there! :->
== your code ==
if [ -L /etc/jabber-querybot/Querymodule.pm ] && \
[ "$1" = "upgrade" ] && \
[ "$2" = "0.0.4-1" ];
then
if ls -l /etc/jabber-querybot/Querymodule.pm | grep -q \
"/usr/share/doc/jabber-querybot/examples/Testbot.pm";
then
rm /etc/jabber-querybot/Querymodule.pm
fi
fi
== /your code ==
With your current code, the link type will be tested at each run of the
preinst. In fact, your "lazy evaluation" checks things in reverse order:
first the link, then the version, then "are we upgrading?"; where it's
probably more efficient to test things in the reverse order (as the lazy
evaluation will stop as soon as possible).
Furthermore, you take the output of ls as granted and check its content
with grep; that's not very efficient (and error prone; what if I had
setup that symlink to
/home/me/stuff/usr/share/doc/jabber-querybot/examples/Testbot.pm ?)
And the preinst will only work when upgraded from _exactly_ 0.0.4-1;
what if jabber-querybot exists (in derivatives, binary rebuilds, etc) in
versions bigger than that but still smaller than 0.0.5.1-1 ? For this,
dpkg --compare-versions is usually used, as it provides clean "> < >= <=
<>" operators, for this purpose.
What about that snippet? (which I wrote with inspiration from my local
/var/lib/dpkg/info/*.preinst e.g.)
== proposal ==
case "$1" in
upgrade)
if dpkg --compare-versions "$2" lt 0.0.5.1-1; then
if [ -L /etc/jabber-querybot/Querymodule.pm ] && [ `readlink
/etc/jabber-querybot/Querymodule.pm` =
"/usr/share/doc/jabber-querybot/examples/Testbot.pm" ];
then
rm /etc/jabber-querybot/Querymodule.pm
fi
fi
;;
esac
== /proposal ==
Cheers,
OdyX
Reply to: