Skip to content

Instantly share code, notes, and snippets.

@jhrcz
Last active March 19, 2016 20:10
Show Gist options
  • Save jhrcz/17fc2a001900882ddc59 to your computer and use it in GitHub Desktop.
Save jhrcz/17fc2a001900882ddc59 to your computer and use it in GitHub Desktop.
diff existing file with its original content from rpm
diff_file_with_rpm_content()
{
#
# EXAMPLES:
#
# diff_file_with_rpm_content /etc/sysconfig/somefile
# diff_file_with_rpm_content /etc/sysconfig/somefile.rpmsave /etc/sysconfig/somefile
#
local srcfile="$1"
[ -f "$srcfile" ] || exit 1
local TMPFILE=$(mktemp /tmp/diff_file_with_rpm_content.XXXX)
local PACKAGE
local PACKAGE_FILE
local file
if [ -n "$2" ]
then
file="$2"
else
file="$srcfile"
fi
###
echo "Getting package..."
PACKAGE=$(rpm -q -f "$file")
echo "$PACKAGE"
yumdownloader --destdir=/tmp "$PACKAGE"
###
echo "Unpacking rpm content and preparing for diff..."
PACKAGE_FILE=/tmp/${PACKAGE}.rpm
rpm2cpio "$PACKAGE_FILE" | cpio -i --to-stdout ".$file" > $TMPFILE
###
DIFF_TOOL=$"vimdiff --cmd \":colorscheme evening\""
eval "$DIFF_TOOL" "\$srcfile" "\$TMPFILE"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment