sync-available has a syntax error and possibly a bashism

Bug #211470 reported by Andrew Pollock
6
Affects Status Importance Assigned to Milestone
dctrl-tools
Fix Released
Unknown
dctrl-tools (Ubuntu)
Fix Released
Medium
Unassigned
Nominated for Hardy by Andrew Pollock
Intrepid
Fix Released
Medium
Unassigned

Bug Description

Binary package hint: dctrl-tools

There's a syntax error in sync-available:

apollock@frustration:~$ sudo sync-available
[: 41: Illegal number:
Merging available database in /tmp/apt-available.WK6905...done.
Replacing available packages info, using /tmp/apt-available.WK6905.
Information about 24871 package(s) was updated.

apollock@frustration:~$ sudo sh -x /usr/sbin/sync-available
+ set -e
+ aptcache=/usr/bin/apt-cache
+ [ 0 -ge 1 ]
+ [ -ne 0 ]
[: 1: Illegal number:
+ [ ! -x /usr/bin/apt-cache ]
+ mktemp -t apt-available.XXXXXX
+ tf=/tmp/apt-available.Uh6930
+ echo -n Merging available database in /tmp/apt-available.Uh6930...
Merging available database in /tmp/apt-available.Uh6930...+ /usr/bin/apt-cache dumpavail
+ echo done.
done.
+ dpkg --update-avail /tmp/apt-available.Uh6930
Replacing available packages info, using /tmp/apt-available.Uh6930.
Information about 24871 package(s) was updated.
+ rm /tmp/apt-available.Uh6930

I think it's this part:

if [ "$EUID" -ne "0" ]
then
    echo "$0: root privileges are required"
    exit 1
fi

If you're going to compare these as strings, you should use the == string comparison operator, not the -ne numeric comparison operator.

So your choices are:

if [ -n "$EUID" ] && [ $EUID -ne 0 ]

or

if [ "$EUID" == "0" ]

That said, $EUID seems to be a bash-provided variable, according to the bash man page, but I can't see any mention of dash providing it. That'll be why this syntax error is being exposed in the first place.

Changed in grep-dctrl:
status: Unknown → Fix Committed
Changed in grep-dctrl:
status: Fix Committed → Fix Released
Revision history for this message
Max Bowsher (maxb) wrote :

Or, better, just replace $EUID with `id -u`

This rather silly bug has gone unfixed since Hardy. Does anyone feel like slipping a fix into Intrepid before final freeze?

Revision history for this message
Colin Watson (cjwatson) wrote :

Although it isn't relevant now, just for reference, [ foo == bar ] is a bashism too; the portable version is [ foo = bar ].

Changed in dctrl-tools:
importance: Undecided → Medium
status: New → Triaged
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package dctrl-tools - 2.12ubuntu1

---------------
dctrl-tools (2.12ubuntu1) intrepid; urgency=low

  * Backport from Debian (Antti-Juhani Kaijanaho, LP: #211470):
    - sync-available/sync-available.cp: Use id -u, not $EUID, which is a bashism
      closes: #457788 (error in sync-available when /bin/sh links to /bin/dash)
      Reported by arno renevier <email address hidden>

 -- Colin Watson <email address hidden> Wed, 15 Oct 2008 21:14:24 +0100

Changed in dctrl-tools:
status: Triaged → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.