1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
#!/bin/bash
#
# This script "cleans" the UPPER directory tree for a subhost by
# comparing it with the LOWER tree and remove all files that are equal
# to content.
PROGRAMDIR="$(dirname $(realpath $0))"
. $PROGRAMDIR/functions
subhost_name $1
subhost_config
: ${LOWER:-/}
if [ ! -d "$UPPER" ] || [ ! -d "$LOWER" ] ; then
echo "*** needs a root path" >&2
exit 1
fi
if is_live $NAME ; then
echo "** Cannot clean running subhost **" >&2
exit 1
fi
UPPER="${UPPER%/}"
LOWER="${LOWER%/}"
if [ "$UPPER" = "$LOWER" ] ; then
echo "** UPER and LOWER are the same directory **" >&2
exit 1
fi
du -sh $UPPER
exit 0
DIFFS=/tmp/clean-$NAME.$$
rm -f $DIFFS
find $UPPER -type f -printf '%P\n'| while read X ; do
cmp "$UPPER/$X" "$LOWER/$X" >> $DIFFS 2>&1 && rm "$UPPER/$X"
done
du -sh $UPPER
echo "(See details in $DIFFS)"
|