From: Ralph Ronnquist Date: Sat, 16 Sep 2023 13:41:38 +0000 (+1000) Subject: Added script for "cleaning" UPPER relative LOWER X-Git-Tag: 1.1~4 X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=58dfafb85fc624cb93abad5bd5297a1e5194d5e3;p=rrq%2Foverlay-boot.git Added script for "cleaning" UPPER relative LOWER --- diff --git a/overlay-clean-root b/overlay-clean-root new file mode 100755 index 0000000..06c997d --- /dev/null +++ b/overlay-clean-root @@ -0,0 +1,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)"