Last active
November 29, 2019 10:21
-
-
Save schtobia/8f2d851c0353350e2c89b4ed2c11e75a to your computer and use it in GitHub Desktop.
debdiffconf, copy from https://a3nm.net/git/mybin/file/debdiffconf.html
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 | |
# Usage: debdiffconf.sh <filename> | |
# Produce on stdout, a diff of <filename> against the first installed Debian | |
# package found that provides it. | |
# Returns the exit code of diff if everything worked, 3 or 4 otherwise. | |
base_name=$(basename $0) | |
required=( apt-get apt-file diff dpkg-deb dpkg-query realpath) | |
for binary in "${required[@]}" | |
do | |
[ -x "$(command -v "$binary")" ] || | |
{ | |
echo -e "Error: Necessary program \'$binary\' is not installed. Aborting now.\n" >&2 | |
exit 4 | |
} | |
done | |
if [ $# -eq 0 ] | |
then | |
echo "No arguments supplied, please pass in a filename. Try something like:\n\n$base_name /etc/squid/squid.conf\n" >&2 | |
exit 4 | |
else | |
FILE=$(readlink -f "$1") | |
fi | |
while read -r PACKAGE | |
do | |
# verify from first installed package | |
if dpkg-query --showformat='${Status}\n' -W "$PACKAGE" > /dev/null | |
then | |
# create a unique tmpdir that is still recognizable in the system | |
DIR=$(mktemp --tmpdir -d "$base_name-$PACKAGE.XXXXXXXXXX") | |
if cd "$DIR" | |
then | |
# install cleanup trap | |
trap "{ cd -; rm -rf "$DIR"; exit $?; }" EXIT INT TERM HUP PIPE | |
else | |
echo -e "Cannot chdir to \'$DIR\'. Aborting now." >&2 | |
exit 1 | |
fi | |
echo "Trying $PACKAGE…" >&2 | |
apt-get download "$PACKAGE" >&2 | |
# downloaded archive is the only file present... | |
ARCHIVE=$(ls) | |
mkdir contents | |
# extract entire archive | |
dpkg-deb -x "$ARCHIVE" contents/ >&2 | |
[ -f "contents$FILE" ] && diff --unified --minimal "contents$FILE" "$FILE" | |
exit 0 | |
fi | |
done < <(apt-file -l search "$FILE") | |
# if we are here, it means we have found no suitable package | |
echo "Could not find original package for $FILE" >&2 | |
exit 3 |
Thanks, included in 0334afa .
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's a cleaned-up/updated version of the above: