Piping stream into tar on FreeBSD

Posted by Casey Jordan on Server Fault See other posts from Server Fault or by Casey Jordan
Published on 2014-06-10T17:45:02Z Indexed on 2014/06/13 3:27 UTC
Read the original article Hit count: 446

Filed under:
|
|

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

© Server Fault or respective owner

Related posts about freebsd

Related posts about tar