Skip to content

Instantly share code, notes, and snippets.

@pallinger
Last active August 28, 2018 08:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pallinger/cdb70d73cb922baa43d2 to your computer and use it in GitHub Desktop.
Save pallinger/cdb70d73cb922baa43d2 to your computer and use it in GitHub Desktop.
diff changed config files with the default ones on a debian system
#!/bin/bash
name=`basename $0`
tmp=/tmp/$name.tmp
missingPattern='^debsums: missing file'
# get differing files using debsums
debsums -e| awk '$2 !~ /OK/{print $1}' > $tmp.1
# print missing
cat $tmp.1 | grep "$missingPattern"
# get non-missing
cat $tmp.1 | grep -v "$missingPattern" > $tmp.2
# find the installed packages that contain the differing files
cat $tmp.2 | xargs dpkg -S | cut -d: -f1 | sort -u | xargs dpkg-query -W -f='${Package} ${Status}\n' | awk '$4 ~ /installed/{print $1}' > $tmp.3
# here we lose some information on which config files are in uninstalled packages... oh well
# download packages
cat $tmp.3 | xargs apt-get install -qdy --force-yes --reinstall
# extract packages to a temp dir
mkdir -p $tmp.4/
cat $tmp.3 | xargs -I%%% find /var/cache/apt/archives -name '%%%_*' | xargs -I%%% dpkg-deb --extract %%% $tmp.4/
# diff them!
cat $tmp.2 | xargs -I%%% diff %%% $tmp.4/%%% | less
# clean up
rm -rf $tmp.*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment