X-Git-Url: https://git.ao2.it/etcdiff.git/blobdiff_plain/027b94126052f26966a0966d6790222fadea7e2f..329c34a9649727679faf13416d9aa5836aecd003:/etcdiff.include?ds=sidebyside diff --git a/etcdiff.include b/etcdiff.include index e26498c..f25076b 100644 --- a/etcdiff.include +++ b/etcdiff.include @@ -3,12 +3,19 @@ _get_unpack_package() { PACKAGE=$1 + + if [ "x$PACKAGE" = "x" ]; + then + echo "Argument missing." + return 1 + fi + FILEPATH=$(apt-cache show $PACKAGE | grep ^Filename | cut -d ' ' -f 2-) if [ "x$FILEPATH" = "x" ]; then echo "Package '$PACKAGE' does not exist." - exit 1 + return 1 fi ARCHIVE=$(basename $FILEPATH) @@ -23,11 +30,17 @@ _do_etcdiff() ETCBASEDIR=$1 PREFIX=$2 + if [ "x$ETCBASEDIR" = "x" ]; + then + echo "Argument missing." + return 1 + fi + REPORT_NAME=$(basename $ETCBASEDIR) # Report diff between debian conf and our local one rm -f $REPORTDIR/$REPORT_NAME.diff - find $PREFIX/etc -type f | \ + [ -d $PREFIX/etc ] && find $PREFIX/etc -type f | \ while read file; do diff -ruN $ETCBASEDIR/${file#$PREFIX/} ${file#$PREFIX} >> $REPORTDIR/$REPORT_NAME.diff @@ -35,14 +48,14 @@ _do_etcdiff() # Report symlinks in /etc rm -f $REPORTDIR/$REPORT_NAME.symlinks - find $PREFIX/etc -type l | \ + [ -d $PREFIX/etc ] && find $PREFIX/etc -type l | \ while read file; do stat -c '%N' $file >> $REPORTDIR/$REPORT_NAME.symlinks done } -etchdiff_system() +etcdiff_system() { PACKAGES=$(dpkg --get-selections | grep 'install$' | cut -f 1 -d ' ') @@ -58,10 +71,19 @@ etchdiff_system() fi echo "Getting package $p..." - _get_unpack_package $p + if ! _get_unpack_package $p; + then + continue + fi # save the original etc dir for later processing - cp -ir $TEMPDIR/$PACKAGE/etc $TEMPDIR/__debian_etc + if [ ! -d $TEMPDIR/$p/etc ]; + then + echo "Warning: package $p does not have any /etc, but 'dpkg -L' shows it" + continue + else + cp -ir $TEMPDIR/$p/etc $TEMPDIR/__debian_etc + fi done _do_etcdiff $TEMPDIR/__debian_etc @@ -73,6 +95,12 @@ etcdiff_by_package() { PACKAGE=$1 + if [ "x$PACKAGE" = "x" ]; + then + echo "Argument missing." + return 1 + fi + if dpkg --status $PACKAGE | grep -q 'not-installed'; then echo "Package '$PACKAGE' not installed" @@ -86,9 +114,21 @@ etcdiff_by_package() return 1 fi - _get_unpack_package $PACKAGE + if ! _get_unpack_package $PACKAGE; + then + return 1 + fi - _do_etcdiff $TEMPDIR/$PACKAGE $TEMPDIR/$PACKAGE + if [ ! -d $TEMPDIR/$PACKAGE/etc ]; + then + echo "Warning: package $p does not have any /etc, but 'dpkg -L' shows it" + return 1 + fi + + if ! _do_etcdiff $TEMPDIR/$PACKAGE $TEMPDIR/$PACKAGE; + then + return 1 + fi return 0 } @@ -97,6 +137,12 @@ etcdiff_by_file() { FILE=$1 + if [ "x$FILE" = "x" ]; + then + echo "Argument missing." + return 1 + fi + if [ ! -e $FILE ]; then echo "ERROR, file $FILE does not exist." @@ -124,7 +170,10 @@ etcdiff_by_file() then diff -ruN /dev/null $FILE > $REPORTDIR/$REPORT_NAME.diff else - _get_unpack_package $PACKAGE + if ! _get_unpack_package $PACKAGE; + then + return 1 + fi diff -ruN $FILE $TEMPDIR/$PACKAGE/$FILE > $REPORTDIR/$REPORT_NAME.diff fi