I have this so far: UNIQUE_LINES=$(/bin/tar -t -f $1 |sed 's@/.*@/@' | uniq | grep "/" |wc -l)
if [ $UNIQUE_LINES != "1" ] ; then
mkdir -p $(echo $1 | sed 's/.tar.*//')
tar -C $(echo $1 | sed 's/.tar.*//') -xf $1
else
tar -xf $1
fi
If you strip stuff after "/" from 'tar -t' and there are no unique lines, or
more than one unique lines, then the package is going to create more than 1
file or directory in ./
An alternative would be to override all archive root directory names, and use
the archive's name instead, but this would probably be a more complicated
script unless you want "archive-name/unpacked-to/" (ie: ./tar-1.18/tar-1.18/)
subdirectories for every package.
This should be a Tar option, like --create-dir (if one won't be created), but
this is probably easier to do in 'sh' than in C.
This mainly happens with Zip archives, but companies like Tripp-lite also
unpack archives into the current directory. It's maybe only 1 in 1000
packages that do this, but they're really annoying when they do. One of the
XML-Docbook packages do this too.
robert
On Monday August 6 2007 09:33:03 am Ken Moffat wrote:
> On Mon, Aug 06, 2007 at 05:25:07PM +1000, Petrus wrote:
> > What really gets me annoyed are people like the tcl devs who can't obey
> > the standard tarball naming conventions...it means that if you want to
> > write build scripts, you have to spend way more time than you should,
> > writing bad, hackish edge cases on how to process such files.
>
> I'm currently using
>
> DIRECTORY=`tar -tvf ${PACKAGES}/${CURRENT} | \
> head -n 1 | awk '{ print $6 }' | sed s'@^./@@' | \
> cut -d '/' -f 1`
>
> where PACKAGES points to the source code, typically /sources, and
> CURRENT contains the name of the tarball. The sed is because some
> tarballs have contained names beginning ./ (possibly an old version
> of util-linux). The fact is, there are loads of packages whose name
> doesn't match the directory name.
>
> ĸen
> --
> das eine Mal als Tragödie, das andere Mal als Farce
pgpSUqDpkENip.pgp
Description: PGP signature
-- http://linuxfromscratch.org/mailman/listinfo/lfs-chat FAQ: http://www.linuxfromscratch.org/faq/ Unsubscribe: See the above information page
