Re: diffing from a tar file

"A. Pagaltzis" <[email protected]>
Newsgroups gmane.culture.people.kragen.discuss
Message-ID <20070422014646.GX15837@klangraum>
* Kragen Javier Sitaker <[email protected]> [2007-04-21 09:40]:
> #!/bin/sh
> set -e
> usage="Usage: $0 checkpoint.tar.gz"
> : ${1?$usage}
> mkdir old
> trap 'rm -rf old' 0
> (cd old; tar xzf ../"$1")
> dir="$(ls old | head -1)"
> diff -urN old/"$dir" "$dir"

You can use mktemp(1) to make this robust. Also note that the $()
syntax for command substitution is a bash innovation, so the
/bin/sh shebang is wrong. Lastly, GNU and BSD tar have a handy -C
switch.

    #!/bin/bash
    set -e
    usage="Usage: $0 checkpoint.tar.gz"
    : ${1?$usage}
    TMPDIR=`mktemp -d`
    mkdir "$TMPDIR"
    trap 'rm -rf "$TMPDIR"' 0
    tar xzf "$1" -C "$TMPDIR"
    dir="$(ls "$TMPDIR" | head -1)"
    diff -urN "$TMPDIR/$dir" "$dir"

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.