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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
# Function to do all of the configuration file migration work
#
_clean_configs()
{
#
# Usage: _clean_configs [-n|-v] new_dir old_dir ...
#
# Across all the files in the new_dir and old_dir args, match
# names and pick the most recently modified version and leave
# this (same mode and modification date) in new_dir
#
# -n option is show-me for benign debugging
# -v option is verbose mode for active debugging
#
if [ $# -gt 0 -a X"$1" = "X-n" ]
then
MKDIR="echo + mkdir "
CP="echo + cp "
shift
else
MKDIR=mkdir
CP=cp
fi
_verbose=false
if [ $# -gt 0 -a X"$1" = "X-v" ]
then
_verbose=true
shift
fi
if [ $# -lt 2 ]
then
echo >&2 "Usage: _clean_configs [-n|-v] new_dir old_dir ..."
return
fi
_new="$1"
if [ ! -d "$_new" ]
then
$verbose && echo >&2 + mkdir -p "$_new"
$MKDIR -p "$_new"
fi
shift
for _dir
do
[ "$_dir" = "$_new" ] && continue
if [ -d "$_dir" ]
then
( cd "$_dir" ; find . -type f -print ) \
| sed -e 's/^\.\///' \
| while read _file
do
_want=false
if [ -f "$_new/$_file" ]
then
# file exists in both directories, pick the more
# recently modified one
#
_try=`find "$_dir/$_file" -newer "$_new/$_file" -print`
[ -n "$_try" ] && _want=true
else
_want=true
fi
if $_want
then
_dest=`dirname $_new/$_file`
if [ ! -d "$_dest" ]
then
$verbose && >&2 echo + mkdir "$_dest"
$MKDIR "$_dest"
fi
$_verbose && echo >&2 + cp -p "$_dir/$_file" "$_new/$_file"
$CP -p "$_dir/$_file" "$_new/$_file"
fi
done
fi
done
}
|