From 58dfafb85fc624cb93abad5bd5297a1e5194d5e3 Mon Sep 17 00:00:00 2001 From: Ralph Ronnquist Date: Sat, 16 Sep 2023 23:41:38 +1000 Subject: [PATCH] Added script for "cleaning" UPPER relative LOWER --- overlay-clean-root | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 overlay-clean-root 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)" -- 2.39.2