projects
/
etcdiff.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Check functions return values.
[etcdiff.git]
/
etcdiff.include
diff --git
a/etcdiff.include
b/etcdiff.include
index
e26498c
..
f25076b
100644
(file)
--- a/
etcdiff.include
+++ b/
etcdiff.include
@@
-3,12
+3,19
@@
_get_unpack_package()
{
PACKAGE=$1
_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."
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)
fi
ARCHIVE=$(basename $FILEPATH)
@@
-23,11
+30,17
@@
_do_etcdiff()
ETCBASEDIR=$1
PREFIX=$2
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
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
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
# 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
}
while read file;
do
stat -c '%N' $file >> $REPORTDIR/$REPORT_NAME.symlinks
done
}
-etc
h
diff_system()
+etcdiff_system()
{
PACKAGES=$(dpkg --get-selections | grep 'install$' | cut -f 1 -d ' ')
{
PACKAGES=$(dpkg --get-selections | grep 'install$' | cut -f 1 -d ' ')
@@
-58,10
+71,19
@@
etchdiff_system()
fi
echo "Getting package $p..."
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
# 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
done
_do_etcdiff $TEMPDIR/__debian_etc
@@
-73,6
+95,12
@@
etcdiff_by_package()
{
PACKAGE=$1
{
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"
if dpkg --status $PACKAGE | grep -q 'not-installed';
then
echo "Package '$PACKAGE' not installed"
@@
-86,9
+114,21
@@
etcdiff_by_package()
return 1
fi
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
}
return 0
}
@@
-97,6
+137,12
@@
etcdiff_by_file()
{
FILE=$1
{
FILE=$1
+ if [ "x$FILE" = "x" ];
+ then
+ echo "Argument missing."
+ return 1
+ fi
+
if [ ! -e $FILE ];
then
echo "ERROR, file $FILE does not exist."
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
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
diff -ruN $FILE $TEMPDIR/$PACKAGE/$FILE > $REPORTDIR/$REPORT_NAME.diff
fi