5 # etcdiff (deb-etcdiff?) shows how your current /etc dir
6 # diverges from the debian distribution standard one.
8 # Copyright (C) 2008,2009 Antonio Ospite <ospite@studenti.unina.it>
9 # License: GPLv2 or later
13 # Add per package etcdiff, using dpkg -L
14 # Add per distro etcdiff using dpkg --get-selections
16 # Note that the first method can't consider files not in original packages,
17 # unless some smart trick is used (new files could be in same /etc subdir of
18 # the provided configuration files)
20 # The second one could even speedup the whole etcdiffing by recreating an etc
21 # dir as per packages defaults, and do one big diff.
27 DEBIANMIRROR="http://ftp.it.debian.org/debian"
29 rm $PROMPT_RM -rf temp && mkdir temp
30 rm $PROMPT_RM -rf archives && mkdir archives
31 rm $PROMPT_RM -rf conf && mkdir conf
33 # Examples of file query
36 #FILES="/etc/sysctl.conf /etc/init.d/procps /etc/passwd-"
39 FILES=$(find /etc/apache2 -type f $USERMODE | grep -v '.dpkg-')
41 # by command, public files, limited
42 #USERMODE="-perm /o+r"
43 #MAXDEPTH="-maxdepth 1"
44 #FILES=$(find /etc/ $MAXDEPTH -type f $USERMODE | grep -v '.dpkg-')
47 #FILES=$(dpkg -L apache2.2-common | grep '^/etc')
53 echo "ERROR, file $file does not exist."
58 # Find out which installed package provides the config file
59 PACKAGE=$(dpkg-query -S "$file" | cut -d ':' -f 1 | uniq 2> /dev/null)
61 # Copy the whole file if it is not provided by default
62 if [ "x$PACKAGE" == "x" ];
64 DESTDIR=`dirname $file`
65 # strip trailing slash
66 [ ${DESTDIR:0:1} == '/' ] && DESTDIR=${DESTDIR:1}
68 # RECREATE the destination dir
69 [ -d conf/$DESTDIR ] || mkdir -p conf/$DESTDIR
70 cp "$file" conf/$DESTDIR
75 # Get the package from the repository and diff
77 FILENAME=$(apt-cache show $PACKAGE | grep ^Filename | cut -d ' ' -f 2-)
78 ARCHIVE=$(basename $FILENAME)
80 if [ ! -f archives/$ARCHIVE ];
83 wget -q -nc -c $DEBIANMIRROR/$FILENAME &&
84 mkdir ../temp/$PACKAGE
85 dpkg -x $ARCHIVE ../temp/$PACKAGE
89 # Check for file existence before diffing, the file is not provided in
90 # package archive, but it could have been generated by package installation
92 if [ ! -f temp/$PACKAGE/$file ];
94 echo "Warning: '$file' can't be found in package!"
98 # TODO: diff only once and check filesize
99 TMPDIFF_FILE=`mktemp /tmp/etcdiff.XXXXXXXXXX`
100 diff -u temp/$PACKAGE/$file $file > $TMPDIFF_FILE
101 if [ `stat -c '%s' $TMPDIFF_FILE` -eq 0 ];
103 echo "$file: not changed"
106 DESTDIR=`dirname $file`
107 # strip trailing slash
108 [ ${DESTDIR:0:1} == '/' ] && DESTDIR=${DESTDIR:1}
110 # RECREATE the destination dir
111 [ -d conf/$DESTDIR ] || mkdir -p conf/$DESTDIR
112 cp $TMPDIFF_FILE conf/$DESTDIR/$(basename $file).patch