blob: 43ee06d55a235887daa26d43f7229a4fbf57d845 (
plain)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
#!/bin/sh
# PCP QA Test No. 517
# Test logic for config file migration, harvesting, cleanup as
# part of a packaged install.
#
# Copyright (c) 2012 Ken McDonell. All Rights Reserved.
#
seq=`basename $0`
echo "QA output created by $seq"
# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check
status=1 # failure is the default!
$sudo rm -rf $tmp.* $seq.full
trap "rm -rf $tmp.*; exit \$status" 0 1 2 3 15
# ... copied directly from ../debian/cleanconfigs
#
# Function to do all of the configuration file migration work
#
_clean_configs()
{
#
# Usage: _clean_configs [-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
#
# -v option is verbose mode for debugging
#
_verbose=false
if [ $# -gt 0 -a X"$1" = "X-v" ]
then
_verbose=true
shift
fi
if [ $# -lt 2 ]
then
echo >&2 "Usage: _clean_configs [-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
}
_filter()
{
sed \
-e "s;$tmp;/TMP;g" \
| LC_COLLATE=POSIX sort
}
_show()
{
cd $1
find * -type f \
| while read x
do
$PCP_ECHO_PROG $PCP_ECHO_N "$x: ""$PCP_ECHO_C"
cat $x
done
cd $here
}
# real QA test starts here
echo "Usage cases ..."
_clean_configs
_clean_configs "one_arg"
_clean_configs -v "-v+one_arg"
echo; echo "No dirs exist"
_clean_configs -v $tmp.new old1 old2 2>&1 | _filter
echo; echo "Empty new dir, harvest all, no name matches"
mkdir $tmp.old1
mkdir $tmp.old2
echo foo >$tmp.old1/foo
echo bar >$tmp.old1/bar
echo mumble >$tmp.old2/mumble
echo fumble >$tmp.old2/fumble
echo stumble >$tmp.old2/stumble
_clean_configs -v $tmp.new $tmp.old1 $tmp.old2 2>&1 | _filter
_show $tmp.new
yesterday=`pmdate -1d %Y%m%d%H%M`
echo; echo "All names match, some older files"
touch -t $yesterday $tmp.new/mumble
echo "newer mumble" >$tmp.old2/mumble
touch -t $yesterday $tmp.old1/bar
echo "newer bar" >$tmp.new/bar
_clean_configs -v $tmp.new $tmp.old1 $tmp.old2 2>&1 | _filter
_show $tmp.new
echo; echo "Hybid cases"
echo "older bar" >$tmp.old2/bar
touch -t $yesterday $tmp.old2/bar
rm $tmp.new/foo
echo "older foo" >$tmp.old1/foo
touch -t $yesterday $tmp.old1/foo
echo foo >$tmp.old2/foo
rm $tmp.new/fumble
_clean_configs -v $tmp.new $tmp.old1 $tmp.old2 2>&1 | _filter
_show $tmp.new
status=0
exit
|