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