Skip to content

Instantly share code, notes, and snippets.

@infojunkie
Last active September 23, 2022 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save infojunkie/0699b082b55d12f1e9bd54016601c1e7 to your computer and use it in GitHub Desktop.
Save infojunkie/0699b082b55d12f1e9bd54016601c1e7 to your computer and use it in GitHub Desktop.
Create an archive out of the diff of two archives
#! /bin/bash
set -e
die () {
echo >&2 "$@"
exit 1
}
[ "$#" -eq 2 ] || die "Usage: $(basename -- "$0") /path/to/original.tar.gz /path/to/modified.tar.gz"
[ -f "$1" ] || die "File $1 does not exist"
[ -f "$2" ] || die "File $2 does not exist"
old=$(mktemp -d -t tar-diff-old-XXXXXXXX)
tar xf "$1" -C "$old"
new=$(mktemp -d -t tar-diff-new-XXXXXXXX)
tar xf "$2" -C "$new"
dif=$(mktemp -d -t tar-diff-XXXXXXXX)
out="$(pwd)/$(basename -- "$dif").tar.gz"
rsync -rvcmq --compare-dest="$old/" "$new/" "$dif"
cd "$dif" && tar zcf "$out" * && cd - > /dev/null
echo "Diff archive output at $out"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment