debdiffconf (1574B)
1 #!/bin/bash 2 3 # Usage: debdiffconf.sh FILE 4 # Produce on stdout diff of FILE against the first installed Debian package 5 # found that provides it. 6 # Returns the exit code of diff if everything worked, 3 or 4 otherwise. 7 8 # https://stackoverflow.com/a/4785518 9 command -v apt >/dev/null 2>&1 || { 10 echo "apt not found, this is probably not a Debian system. Aborting." >&2; 11 exit 4; } 12 command -v apt-file >/dev/null 2>&1 || { 13 echo "Please install apt-file: sudo apt install apt-file. Aborting." >&2; 14 exit 4; } 15 command -v realpath >/dev/null 2>&1 || { 16 echo "Please install realpath: sudo apt install realpath. Aborting." >&2; 17 exit 4; } 18 19 FILE=$(realpath -m "$1") 20 while read PACKAGE 21 do 22 # verify from first installed package 23 if dpkg-query -W --showformat='${Status}\n' | grep installed > /dev/null 24 then 25 DIR=$(mktemp -d) 26 cd "$DIR" 27 echo "Trying $PACKAGE..." >&2 28 apt download "$PACKAGE" >&2 29 # downloaded archive is the only file present... 30 ARCHIVE=$(ls) 31 mkdir contents 32 # extract entire archive 33 dpkg-deb -x "$ARCHIVE" contents/ >&2 34 if [ -f "contents$FILE" ] 35 then 36 # package contained required file 37 diff "contents$FILE" "$FILE" 38 RET=$? 39 # cleanup 40 cd 41 rm -Rf "$DIR" 42 # exit entire script as this is the main shell 43 # with the return code from diff 44 exit $RET 45 else 46 # cleanup 47 cd 48 rm -Rf "$DIR" 49 fi 50 fi 51 done < <(apt-file -l search "$FILE") 52 # if we are here, it means we have found no suitable package 53 echo "Could not find original package for $FILE" >&2 54 exit 3 55