0

I am trying to pipe a tar/gzip archive into tar to decompress it. The script I have is part of a self extracting installer, where my archive is appended to the script. This works fine on linux, and the script looks like this:

export TMPDIR=`mktemp -d /tmp/selfextract.XXXXXX`

echo "TEMP: $TMPDIR"

ARCHIVE=`awk '/^__ARCHIVE_BELOW__/ {print NR + 1; exit 0; }' $0`


tail -n+$ARCHIVE $0 | tar xz -C $TMPDIR


exit 0

__ARCHIVE_BELOW__

The tar archive as a string is after the ARCHIVE_BELOW but I omitted it from here since it's huge.

However, when I do this on FreeBSD I get the following error:

tar: Failed to open '/dev/sa0'

I read that this is because free BSD expects to read from that device by default and you can tell it to read from stdin by passing -f - like so:

tail -n+$ARCHIVE $0 | tar zxf - -C $TMPDIR

However, when I do this I just get the error:

tar: Damaged tar archive
tar: Retrying...

Can anyone point out what I am doing wrong here? I need to do it this way (Via piping) for efficiency reasons.

Thanks

Casey Jordan
  • 215
  • 4
  • 11
  • Adding -v should at least tell you where it the process. You can also try to use -j instead of -z but it might be irrelevant with newer version. – Alex Jun 10 '14 at 17:57
  • Unfortunately that does not give me any more information or help resolve the issue. Thanks for the advice though. – Casey Jordan Jun 10 '14 at 18:42

1 Answers1

0

In the first command:

echo $ARCHIVE | tar xz -C $TMPDIR

This is piping the file name into tar, not the contents of the file. How this is working is beyond me.

In the final command you list:

tail -n+$ARCHIVE $0 | tar zxf - -C $TMPDIR

I think this is specifying the file name as the argument to "tail", which probably isn't going to work either. Even if ${ARCHIVE} is a number, you still can't pipe the tail of an archive to tar, you need to give it the whole archive. Why are you calling tail here at all? A better solution might be:

tar xzvf ${ARCHIVE} -C ${TMPDIR}

Steve Wills
  • 685
  • 3
  • 6