Drop unused condition check
[pcp.git] / qa / 517
blob43ee06d55a235887daa26d43f7229a4fbf57d845
1 #!/bin/sh
2 # PCP QA Test No. 517
3 # Test logic for config file migration, harvesting, cleanup as
4 # part of a packaged install.
6 # Copyright (c) 2012 Ken McDonell. All Rights Reserved.
9 seq=`basename $0`
10 echo "QA output created by $seq"
12 # get standard environment, filters and checks
13 . ./common.product
14 . ./common.filter
15 . ./common.check
17 status=1 # failure is the default!
18 $sudo rm -rf $tmp.* $seq.full
19 trap "rm -rf $tmp.*; exit \$status" 0 1 2 3 15
21 # ... copied directly from ../debian/cleanconfigs
24 # Function to do all of the configuration file migration work
26 _clean_configs()
29 # Usage: _clean_configs [-v] new_dir old_dir ...
31 # Across all the files in the new_dir and old_dir args, match
32 # names and pick the most recently modified version and leave
33 # this (same mode and modification date) in new_dir
35 # -v option is verbose mode for debugging
38 _verbose=false
39 if [ $# -gt 0 -a X"$1" = "X-v" ]
40 then
41 _verbose=true
42 shift
45 if [ $# -lt 2 ]
46 then
47 echo >&2 "Usage: _clean_configs [-v] new_dir old_dir ..."
48 return
51 _new="$1"
52 if [ ! -d "$_new" ]
53 then
54 $verbose && echo >&2 + mkdir -p "$_new"
55 mkdir -p "$_new"
58 shift
59 for _dir
61 [ "$_dir" = "$_new" ] && continue
62 if [ -d "$_dir" ]
63 then
64 ( cd "$_dir" ; find . -type f -print ) \
65 | sed -e 's/^\.\///' \
66 | while read _file
68 _want=false
69 if [ -f "$_new/$_file" ]
70 then
71 # file exists in both directories, pick the more
72 # recently modified one
74 _try=`find "$_dir/$_file" -newer "$_new/$_file" -print`
75 [ -n "$_try" ] && _want=true
76 else
77 _want=true
79 if $_want
80 then
81 _dest=`dirname $_new/$_file`
82 if [ ! -d "$_dest" ]
83 then
84 $verbose && >&2 echo + mkdir "$_dest"
85 mkdir "$_dest"
87 $_verbose && echo >&2 + cp -p "$_dir/$_file" "$_new/$_file"
88 cp -p "$_dir/$_file" "$_new/$_file"
90 done
92 done
96 _filter()
98 sed \
99 -e "s;$tmp;/TMP;g" \
100 | LC_COLLATE=POSIX sort
103 _show()
105 cd $1
106 find * -type f \
107 | while read x
109 $PCP_ECHO_PROG $PCP_ECHO_N "$x: ""$PCP_ECHO_C"
110 cat $x
111 done
112 cd $here
115 # real QA test starts here
116 echo "Usage cases ..."
117 _clean_configs
118 _clean_configs "one_arg"
119 _clean_configs -v "-v+one_arg"
121 echo; echo "No dirs exist"
122 _clean_configs -v $tmp.new old1 old2 2>&1 | _filter
124 echo; echo "Empty new dir, harvest all, no name matches"
125 mkdir $tmp.old1
126 mkdir $tmp.old2
127 echo foo >$tmp.old1/foo
128 echo bar >$tmp.old1/bar
129 echo mumble >$tmp.old2/mumble
130 echo fumble >$tmp.old2/fumble
131 echo stumble >$tmp.old2/stumble
132 _clean_configs -v $tmp.new $tmp.old1 $tmp.old2 2>&1 | _filter
133 _show $tmp.new
135 yesterday=`pmdate -1d %Y%m%d%H%M`
136 echo; echo "All names match, some older files"
137 touch -t $yesterday $tmp.new/mumble
138 echo "newer mumble" >$tmp.old2/mumble
139 touch -t $yesterday $tmp.old1/bar
140 echo "newer bar" >$tmp.new/bar
141 _clean_configs -v $tmp.new $tmp.old1 $tmp.old2 2>&1 | _filter
142 _show $tmp.new
144 echo; echo "Hybid cases"
145 echo "older bar" >$tmp.old2/bar
146 touch -t $yesterday $tmp.old2/bar
147 rm $tmp.new/foo
148 echo "older foo" >$tmp.old1/foo
149 touch -t $yesterday $tmp.old1/foo
150 echo foo >$tmp.old2/foo
151 rm $tmp.new/fumble
152 _clean_configs -v $tmp.new $tmp.old1 $tmp.old2 2>&1 | _filter
153 _show $tmp.new
155 status=0
156 exit