mybin

my ~/bin
git clone https://a3nm.net/git/mybin/
Log | Files | Refs | README

commit 443b23e53a865ce25243b0b6d08a4f98d6be8465
parent 3187b038f40de07e9a39a92969ceba5fc5d4b71a
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Sun,  3 Aug 2014 13:56:12 +0200

+debdiffconf.sh

Diffstat:
debdiffconf.sh | 50++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+), 0 deletions(-)

diff --git a/debdiffconf.sh b/debdiffconf.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +# Compare current version of configuration file with pristine version from +# the corresponding Debian package. + +# http://stackoverflow.com/a/4785518 +command -v apt-get >/dev/null 2>&1 || { + echo "apt-get not found, this is probably not a Debian system. Aborting." >&2; + exit 4; } +command -v apt-file >/dev/null 2>&1 || { + echo "Please install apt-file: sudo apt-get install apt-file. Aborting." >&2; + exit 4; } + +FILE=$(readlink -f "$1") +while read PACKAGE +do + # verify from first installed package + if dpkg-query -W --showformat='${Status}\n' | grep installed > /dev/null + then + DIR=$(mktemp -d) + cd "$DIR" + 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 + if [ -f "contents$FILE" ] + then + # package contained required file + diff "contents$FILE" "$FILE" + RET=$? + # cleanup + cd + rm -Rf "$DIR" + # exit entire script as this is the main shell + # with the return code from diff + exit $RET + else + # cleanup + cd + rm -Rf "$DIR" + fi + 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 +