Last active
September 23, 2022 17:15
-
-
Save infojunkie/0699b082b55d12f1e9bd54016601c1e7 to your computer and use it in GitHub Desktop.
Create an archive out of the diff of two archives
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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