[lxc-devel] [PATCH v2] use which instead of type

Dwight Engen dwight.engen at oracle.com
Tue Jan 22 20:55:28 UTC 2013


On Tue, 22 Jan 2013 13:15:38 -0600
Serge Hallyn <serge.hallyn at canonical.com> wrote:

> Quoting Dwight Engen (dwight.engen at oracle.com):
> ...
> > diff --git a/templates/lxc-ubuntu.in b/templates/lxc-ubuntu.in
> > index 0ed8808..f443c96 100644
> > --- a/templates/lxc-ubuntu.in
> > +++ b/templates/lxc-ubuntu.in
> > @@ -609,7 +609,7 @@ arch=$(arch)
> >  # Code taken from debootstrap
> >  if [ -x /usr/bin/dpkg ] && /usr/bin/dpkg --print-architecture
> > >/dev/null 2>&1; then arch=`/usr/bin/dpkg --print-architecture`
> > -elif type udpkg >/dev/null 2>&1 && udpkg --print-architecture
> > >/dev/null 2>&1; then +elif which udpkg >/dev/null 2>&1 && udpkg
> > >--print-architecture >/dev/null 2>&1; then
> >      arch=`/usr/bin/udpkg --print-architecture`
> >  else
> >      arch=$(arch)
> > @@ -666,7 +666,7 @@ if [ $hostarch = "i386" -a $arch = "amd64" ];
> > then exit 1
> >  fi
> >  
> > -type debootstrap
> > +which debootstrap 2>&1
> 
> Is there a reason for no > /dev/null?

Actually it was an oversight on my part, sorry, and good catch...
Looking into it further (and testing), there is a bit of a problem with
just redirecting to /dev/null: this script is set -e so as soon as
'which debootstrap' fails, the script exits without printing our error
message. Previously we would get the output from the failed "type
debootstrap" instead of the intended error message, so I think its best
to rework it to do like lxc-shutdown and lxc-clone (also set -e) do it:

which debootstrap >/dev/null 2>&1 || { echo "'debootstrap' command is missing" >&2; false; }

v3 patch follows :)




More information about the lxc-devel mailing list