From: Antonio Ospite Date: Sun, 1 Mar 2009 17:18:24 +0000 (+0100) Subject: First etcdiff import, proof of concept X-Git-Url: https://git.ao2.it/etcdiff.git/commitdiff_plain/500297c0ab004d9ea817855cb49c1d26eb6d5d03 First etcdiff import, proof of concept --- 500297c0ab004d9ea817855cb49c1d26eb6d5d03 diff --git a/etcdiff.sh b/etcdiff.sh new file mode 100755 index 0000000..b8a3be6 --- /dev/null +++ b/etcdiff.sh @@ -0,0 +1,55 @@ +#!/bin/sh +# +# etcdiff (deb-etcdiff?) shows how your current /etc dir +# diverges from the debian distribution standard one. +# +# Copyright (C) 2008 Antonio Ospite +# License: GPLv2 or later + +set -ex + +PROMPT_RM=-i + +DEBIANMIRROR="http://ftp.it.debian.org/debian" + +rm $PROMPT_RM -r temp && mkdir temp +rm $PROMPT_RM -r archives && mkdir archives +rm $PROMPT_RM -r conf && mkdir -p conf/patches + +USERMODE="-perm /o+r" +MAXDEPTH="-maxdepth 1" + +#FILES="/etc/sysctl.conf /etc/init.d/procps /etc/passwd-" +FILES=$(find /etc/ $MAXDEPTH -type f $USERMODE | grep -v '.dpkg-') + +for file in ${FILES}; +do + echo "-> $file" + + # Find out what installed package provides the config file + PACKAGE=$(dpkg-query -S "$file" | cut -d ':' -f 1 | uniq 2> /dev/null) + + # Copy the whole file if it is not provided by default + if [ "x$PACKAGE" == "x" ]; + then + cp "$file" conf/ + continue + fi + + # Get the package from the repository and diff + + FILENAME=$(apt-cache show $PACKAGE | grep ^Filename | cut -d ' ' -f 2-) + ARCHIVE=$(basename $FILENAME) + + (cd archives && wget -q -nc -c $DEBIANMIRROR/$FILENAME) + dpkg -x archives/$ARCHIVE temp/ + + diff -q temp/$file $file > /dev/null + if [ $? -eq 1 ]; + then + diff -u temp/$file $file > conf/patches/$(basename $file).patch + else + echo "$file: not changed" + fi + +done