1#    rpmvercmp.at: rpm config file behavior tests
2
3AT_BANNER([RPM config file behavior])
4
5AT_SETUP([config file install/upgrade/erase])
6AT_KEYWORDS([install])
7RPMDB_INIT
8for v in "1.0" "2.0"; do
9    runroot rpmbuild --quiet -bb \
10        --define "ver $v" \
11	--define "filedata foo" \
12          /data/SPECS/configtest.spec
13done
14
15# Install over existing config file
16AT_CHECK([
17RPMDB_INIT
18cf="${RPMTEST}"/etc/my.conf
19rm -rf "${cf}"*
20
21echo "otherstuff" > "${cf}"
22runroot rpm -U /build/RPMS/noarch/configtest-1.0-1.noarch.rpm
23cat "${cf}"
24runroot rpm -e configtest
25cat "${cf}.rpmorig"
26],
27[0],
28[foo
29otherstuff
30],
31[warning: /etc/my.conf saved as /etc/my.conf.rpmorig]
32)
33
34# Install over existing identical config file, no backup needed
35AT_CHECK([
36RPMDB_INIT
37cf="${RPMTEST}"/etc/my.conf
38rm -rf "${cf}"*
39
40echo "foo" > "${cf}"
41runroot rpm -U /build/RPMS/noarch/configtest-1.0-1.noarch.rpm
42cat "${cf}"
43runroot rpm -e configtest
44test ! -f "${cf}"
45],
46[0],
47[foo
48],
49[])
50
51# Erase unmodified config file, no backup here
52AT_CHECK([
53RPMDB_INIT
54cf="${RPMTEST}"/etc/my.conf
55rm -rf "${cf}"*
56
57runroot rpm -U /build/RPMS/noarch/configtest-1.0-1.noarch.rpm
58cat "${cf}"
59runroot rpm -e configtest
60test ! -f "${cf}"
61],
62[0],
63[foo
64],
65[])
66
67# Erase modified config file
68AT_CHECK([
69RPMDB_INIT
70cf="${RPMTEST}"/etc/my.conf
71rm -rf "${cf}"*
72
73runroot rpm -U /build/RPMS/noarch/configtest-1.0-1.noarch.rpm
74cat "${cf}"
75echo "otherstuff" > "${cf}"
76runroot rpm -e configtest
77cat "${cf}.rpmsave"
78test ! -f "${cf}"
79],
80[0],
81[foo
82otherstuff
83],
84[warning: /etc/my.conf saved as /etc/my.conf.rpmsave]
85)
86
87# Upgrade package with config file, no backup here
88AT_CHECK([
89RPMDB_INIT
90cf="${RPMTEST}"/etc/my.conf
91rm -rf "${cf}"*
92
93runroot rpm -U /build/RPMS/noarch/configtest-1.0-1.noarch.rpm
94cat "${cf}"
95runroot rpm -U /build/RPMS/noarch/configtest-2.0-1.noarch.rpm
96cat "${cf}"
97],
98[0],
99[foo
100foo
101],
102[])
103
104# Upgrade package with config file, no backup here
105AT_CHECK([
106RPMDB_INIT
107cf="${RPMTEST}"/etc/my.conf
108rm -rf "${cf}"*
109
110runroot rpm -U /build/RPMS/noarch/configtest-1.0-1.noarch.rpm
111runroot rpm -Uvv --fsmdebug /build/RPMS/noarch/configtest-2.0-1.noarch.rpm > output.txt 2>&1
112grep -c  "touch" output.txt
113],
114[0],
115[1
116],
117[])
118
119# Upgrade package with locally modified config file, unchanged in pkg
120AT_CHECK([
121RPMDB_INIT
122cf="${RPMTEST}"/etc/my.conf
123rm -rf "${cf}"*
124
125runroot rpm -U /build/RPMS/noarch/configtest-1.0-1.noarch.rpm
126cat "${cf}"
127echo "otherstuff" > "${cf}"
128cat "${cf}"
129runroot rpm -U /build/RPMS/noarch/configtest-2.0-1.noarch.rpm
130cat "${cf}"
131],
132[0],
133[foo
134otherstuff
135otherstuff
136],
137[])
138AT_CLEANUP
139
140# ------------------------------
141AT_SETUP([config(noreplace) file install/upgrade/erase])
142AT_KEYWORDS([install])
143RPMDB_INIT
144
145runroot rpmbuild --quiet -bb \
146        --define "ver 1.0" \
147	--define "filedata foo" \
148	--define "noreplace 1" \
149          /data/SPECS/configtest.spec
150
151# Install over existing config file
152AT_CHECK([
153RPMDB_INIT
154cf="${RPMTEST}"/etc/my.conf
155rm -rf "${cf}"*
156echo "otherstuff" > "${cf}"
157runroot rpm -U /build/RPMS/noarch/configtest-1.0-1.noarch.rpm
158cat "${cf}"
159cat "${cf}.rpmnew"
160runroot rpm -e configtest
161cat "${cf}.rpmsave"
162cat "${cf}.rpmnew"
163],
164[0],
165[otherstuff
166foo
167otherstuff
168foo
169],
170[warning: /etc/my.conf created as /etc/my.conf.rpmnew
171warning: /etc/my.conf saved as /etc/my.conf.rpmsave]
172)
173
174# Erase modified config(noreplace) file
175AT_CHECK([
176RPMDB_INIT
177cf="${RPMTEST}"/etc/my.conf
178rm -rf "${cf}"*
179
180runroot rpm -U /build/RPMS/noarch/configtest-1.0-1.noarch.rpm
181cat "${cf}"
182echo "otherstuff" > "${cf}"
183runroot rpm -e configtest
184cat "${cf}.rpmsave"
185test ! -f "${cf}"
186],
187[0],
188[foo
189otherstuff
190],
191[warning: /etc/my.conf saved as /etc/my.conf.rpmsave]
192)
193AT_CLEANUP
194
195# ------------------------------
196AT_SETUP([upgrade changing config])
197AT_KEYWORDS([install])
198RPMDB_INIT
199
200for v in "1.0" "2.0"; do
201    runroot rpmbuild --quiet -bb \
202        --define "ver $v" \
203	--define "filedata foo-$v" \
204          /data/SPECS/configtest.spec
205done
206
207# Upgrade package with unmodified config file, changed in pkg
208AT_CHECK([
209RPMDB_INIT
210cf="${RPMTEST}"/etc/my.conf
211rm -rf "${cf}"*
212
213runroot rpm -U /build/RPMS/noarch/configtest-1.0-1.noarch.rpm
214cat "${cf}"
215runroot rpm -U /build/RPMS/noarch/configtest-2.0-1.noarch.rpm
216cat "${cf}"
217],
218[0],
219[foo-1.0
220foo-2.0
221],
222[])
223
224# ------------------------------
225# Upgrade package with locally modified config file, changed in pkg
226AT_KEYWORDS([install])
227AT_CHECK([
228RPMDB_INIT
229cf="${RPMTEST}"/etc/my.conf
230rm -rf "${cf}"*
231
232runroot rpm -U /build/RPMS/noarch/configtest-1.0-1.noarch.rpm
233cat "${cf}"
234echo "otherstuff" > "${RPMTEST}"/etc/my.conf
235cat "${cf}"
236runroot rpm -U /build/RPMS/noarch/configtest-2.0-1.noarch.rpm
237cat "${cf}"
238cat "${cf}.rpmsave"
239],
240[0],
241[foo-1.0
242otherstuff
243foo-2.0
244otherstuff
245],
246[warning: /etc/my.conf saved as /etc/my.conf.rpmsave]
247)
248
249# ------------------------------
250# Modified config file matches the content from new package.
251AT_CHECK([
252RPMDB_INIT
253cf="${RPMTEST}"/etc/my.conf
254rm -rf "${cf}"*
255
256runroot rpm -U /build/RPMS/noarch/configtest-1.0-1.noarch.rpm
257cat "${cf}"
258echo "foo-2.0" > "${RPMTEST}"/etc/my.conf
259cat "${cf}"
260runroot rpm -U /build/RPMS/noarch/configtest-2.0-1.noarch.rpm
261cat "${cf}"
262],
263[0],
264[foo-1.0
265foo-2.0
266foo-2.0
267],
268[])
269AT_CLEANUP
270
271# config(noreplace) variants of the same cases.
272# ------------------------------
273AT_SETUP([upgrade changing config(noreplace)])
274AT_KEYWORDS([install])
275RPMDB_INIT
276
277for v in "1.0" "2.0"; do
278    runroot rpmbuild --quiet -bb \
279        --define "ver $v" \
280	--define "filedata foo" \
281	--define "noreplace 1" \
282          /data/SPECS/configtest.spec
283done
284#
285# Upgrade package with config file, no backup here
286AT_CHECK([
287RPMDB_INIT
288cf="${RPMTEST}"/etc/my.conf
289rm -rf "${cf}"*
290
291runroot rpm -U /build/RPMS/noarch/configtest-1.0-1.noarch.rpm
292cat "${cf}"
293runroot rpm -U /build/RPMS/noarch/configtest-2.0-1.noarch.rpm
294cat "${cf}"
295],
296[0],
297[foo
298foo
299],
300[])
301
302# Upgrade package with locally modified config file, unchanged in pkg
303AT_CHECK([
304RPMDB_INIT
305cf="${RPMTEST}"/etc/my.conf
306rm -rf "${cf}"*
307
308runroot rpm -U /build/RPMS/noarch/configtest-1.0-1.noarch.rpm
309cat "${cf}"
310echo "otherstuff" > "${cf}"
311cat "${cf}"
312runroot rpm -U /build/RPMS/noarch/configtest-2.0-1.noarch.rpm
313cat "${cf}"
314],
315[0],
316[foo
317otherstuff
318otherstuff
319],
320[])
321AT_CLEANUP
322
323# ------------------------------
324# noreplace variants of the same
325AT_SETUP([upgrade changing config(noreplace)])
326AT_KEYWORDS([install])
327RPMDB_INIT
328for v in "1.0" "2.0"; do
329    runroot rpmbuild --quiet -bb \
330        --define "ver $v" \
331	--define "filedata foo-$v" \
332	--define "noreplace 1" \
333          /data/SPECS/configtest.spec
334done
335
336# Upgrade package with unmodified config file, changed in pkg
337AT_CHECK([
338RPMDB_INIT
339cf="${RPMTEST}"/etc/my.conf
340rm -rf "${cf}"*
341
342runroot rpm -U /build/RPMS/noarch/configtest-1.0-1.noarch.rpm
343cat "${cf}"
344runroot rpm -U /build/RPMS/noarch/configtest-2.0-1.noarch.rpm
345cat "${cf}"
346],
347[0],
348[foo-1.0
349foo-2.0
350],
351[])
352
353# Upgrade package with locally modified config file, changed in pkg
354AT_CHECK([
355RPMDB_INIT
356cf="${RPMTEST}"/etc/my.conf
357rm -rf "${cf}"*
358
359runroot rpm -U /build/RPMS/noarch/configtest-1.0-1.noarch.rpm
360cat "${cf}"
361echo "otherstuff" > "${RPMTEST}"/etc/my.conf
362cat "${cf}"
363runroot rpm -U /build/RPMS/noarch/configtest-2.0-1.noarch.rpm
364cat "${cf}"
365cat "${cf}.rpmnew"
366],
367[0],
368[foo-1.0
369otherstuff
370otherstuff
371foo-2.0
372],
373[warning: /etc/my.conf created as /etc/my.conf.rpmnew]
374)
375
376# Modified config file matches the content from new package.
377AT_CHECK([
378RPMDB_INIT
379cf="${RPMTEST}"/etc/my.conf
380rm -rf "${cf}"*
381
382runroot rpm -U /build/RPMS/noarch/configtest-1.0-1.noarch.rpm
383cat "${cf}"
384echo "foo-2.0" > "${RPMTEST}"/etc/my.conf
385cat "${cf}"
386runroot rpm -U /build/RPMS/noarch/configtest-2.0-1.noarch.rpm
387cat "${cf}"
388],
389[0],
390[foo-1.0
391foo-2.0
392foo-2.0
393],
394[])
395AT_CLEANUP
396
397# Shared config file variants of the same cases
398# ------------------------------
399AT_SETUP([upgrade shared config])
400AT_KEYWORDS([install])
401RPMDB_INIT
402for s in "A" "B"; do
403    for v in "1.0" "2.0"; do
404        runroot rpmbuild --quiet -bb \
405            --define "sub $s" \
406            --define "ver $v" \
407	    --define "filedata foo" \
408              /data/SPECS/configtest.spec
409    done
410done
411
412# Upgrade package with config file, no backup here
413AT_CHECK([
414RPMDB_INIT
415cf="${RPMTEST}"/etc/my.conf
416rm -rf "${cf}"*
417
418runroot rpm -U \
419    /build/RPMS/noarch/configtest-A-1.0-1.noarch.rpm \
420    /build/RPMS/noarch/configtest-B-1.0-1.noarch.rpm
421cat "${cf}"
422runroot rpm -U \
423    /build/RPMS/noarch/configtest-A-2.0-1.noarch.rpm \
424    /build/RPMS/noarch/configtest-B-2.0-1.noarch.rpm
425cat "${cf}"
426],
427[0],
428[foo
429foo
430],
431[])
432
433# Upgrade package with locally modified config file, unchanged in pkg
434AT_CHECK([
435RPMDB_INIT
436cf="${RPMTEST}"/etc/my.conf
437rm -rf "${cf}"*
438
439runroot rpm -U \
440    /build/RPMS/noarch/configtest-A-1.0-1.noarch.rpm \
441    /build/RPMS/noarch/configtest-B-1.0-1.noarch.rpm
442cat "${cf}"
443echo "otherstuff" > "${cf}"
444cat "${cf}"
445runroot rpm -U \
446    /build/RPMS/noarch/configtest-A-2.0-1.noarch.rpm \
447    /build/RPMS/noarch/configtest-B-2.0-1.noarch.rpm
448cat "${cf}"
449],
450[0],
451[foo
452otherstuff
453otherstuff
454],
455[])
456AT_CLEANUP
457
458# ------------------------------
459AT_SETUP([upgrade changing shared config])
460AT_KEYWORDS([install])
461RPMDB_INIT
462for s in "A" "B"; do
463    for v in "1.0" "2.0"; do
464        runroot rpmbuild --quiet -bb \
465            --define "sub $s" \
466            --define "ver $v" \
467	    --define "filedata foo-$v" \
468              /data/SPECS/configtest.spec
469    done
470done
471
472# Upgrade package with unmodified config file, changed in pkg
473AT_CHECK([
474RPMDB_INIT
475cf="${RPMTEST}"/etc/my.conf
476rm -rf "${cf}"*
477
478runroot rpm -U \
479    /build/RPMS/noarch/configtest-A-1.0-1.noarch.rpm \
480    /build/RPMS/noarch/configtest-B-1.0-1.noarch.rpm
481cat "${cf}"
482runroot rpm -U \
483    /build/RPMS/noarch/configtest-A-2.0-1.noarch.rpm \
484    /build/RPMS/noarch/configtest-B-2.0-1.noarch.rpm
485cat "${cf}"
486],
487[0],
488[foo-1.0
489foo-2.0
490],
491[])
492
493# Upgrade package with locally modified config file, changed in pkg
494AT_CHECK([
495RPMDB_INIT
496cf="${RPMTEST}"/etc/my.conf
497rm -rf "${cf}"*
498
499runroot rpm -U \
500    /build/RPMS/noarch/configtest-A-1.0-1.noarch.rpm \
501    /build/RPMS/noarch/configtest-B-1.0-1.noarch.rpm
502cat "${cf}"
503echo "otherstuff" > "${RPMTEST}"/etc/my.conf
504cat "${cf}"
505runroot rpm -U \
506    /build/RPMS/noarch/configtest-A-2.0-1.noarch.rpm \
507    /build/RPMS/noarch/configtest-B-2.0-1.noarch.rpm
508cat "${cf}"
509cat "${cf}.rpmsave"
510],
511[0],
512[foo-1.0
513otherstuff
514foo-2.0
515otherstuff
516],
517[warning: /etc/my.conf saved as /etc/my.conf.rpmsave]
518)
519
520# Modified config file matches the content from new package.
521AT_CHECK([
522RPMDB_INIT
523cf="${RPMTEST}"/etc/my.conf
524rm -rf "${cf}"*
525
526runroot rpm -U \
527    /build/RPMS/noarch/configtest-A-1.0-1.noarch.rpm \
528    /build/RPMS/noarch/configtest-B-1.0-1.noarch.rpm
529cat "${cf}"
530echo "foo-2.0" > "${RPMTEST}"/etc/my.conf
531cat "${cf}"
532runroot rpm -U \
533    /build/RPMS/noarch/configtest-A-2.0-1.noarch.rpm \
534    /build/RPMS/noarch/configtest-B-2.0-1.noarch.rpm
535cat "${cf}"
536],
537[0],
538[foo-1.0
539foo-2.0
540foo-2.0
541],
542[])
543AT_CLEANUP
544
545# Shared config(noreplace) variants of the more interesting cases
546# ------------------------------
547# Upgrade package with locally modified config file, changed in pkg.
548AT_SETUP([upgrade shared config(noreplace)])
549AT_KEYWORDS([install])
550RPMDB_INIT
551
552for s in "A" "B"; do
553    for v in "1.0" "2.0"; do
554        runroot rpmbuild --quiet -bb \
555            --define "sub $s" \
556            --define "ver $v" \
557	    --define "filedata foo-$v" \
558	    --define "noreplace 1" \
559              /data/SPECS/configtest.spec
560    done
561done
562
563AT_CHECK([
564RPMDB_INIT
565cf="${RPMTEST}"/etc/my.conf
566rm -rf "${cf}"*
567
568runroot rpm -U \
569    /build/RPMS/noarch/configtest-A-1.0-1.noarch.rpm \
570    /build/RPMS/noarch/configtest-B-1.0-1.noarch.rpm
571cat "${cf}"
572echo "otherstuff" > "${RPMTEST}"/etc/my.conf
573cat "${cf}"
574runroot rpm -U \
575    /build/RPMS/noarch/configtest-A-2.0-1.noarch.rpm \
576    /build/RPMS/noarch/configtest-B-2.0-1.noarch.rpm
577cat "${cf}"
578cat "${cf}.rpmnew"
579],
580[0],
581[foo-1.0
582otherstuff
583otherstuff
584foo-2.0
585],
586[warning: /etc/my.conf created as /etc/my.conf.rpmnew]
587)
588
589# ------------------------------
590# Modified config file matches the content from new package.
591AT_CHECK([
592RPMDB_INIT
593cf="${RPMTEST}"/etc/my.conf
594rm -rf "${cf}"*
595
596runroot rpm -U \
597    /build/RPMS/noarch/configtest-A-1.0-1.noarch.rpm \
598    /build/RPMS/noarch/configtest-B-1.0-1.noarch.rpm
599cat "${cf}"
600echo "foo-2.0" > "${RPMTEST}"/etc/my.conf
601cat "${cf}"
602runroot rpm -U \
603    /build/RPMS/noarch/configtest-A-2.0-1.noarch.rpm \
604    /build/RPMS/noarch/configtest-B-2.0-1.noarch.rpm
605cat "${cf}"
606],
607[0],
608[foo-1.0
609foo-2.0
610foo-2.0
611],
612[])
613AT_CLEANUP
614
615---------
616# Test pre-existing and post-install config ghost survival and erasure
617AT_SETUP([ghost config])
618AT_KEYWORDS([install])
619AT_CHECK([
620RPMDB_INIT
621cf="${RPMTEST}"/etc/my.conf
622rm -rf "${cf}"*
623
624for v in 1.0 2.0; do
625    runroot rpmbuild --quiet -bb \
626        --define "ver ${v}" \
627        --define "filetype file" \
628        --define "filedata buster" \
629        --define "fileattr %ghost" \
630          /data/SPECS/configtest.spec
631done
632
633# pre-existing config, install, erase
634test ! -f "${cf}" && echo OK1
635echo "keaton" > "${cf}"
636cat "${cf}"
637runroot rpm -U /build/RPMS/noarch/configtest-1.0-1.noarch.rpm
638cat "${cf}"
639runroot rpm -e configtest
640cat "${cf}"
641rm -f "${cf}"
642
643# post-install config, upgrade, erase
644runroot rpm -U /build/RPMS/noarch/configtest-1.0-1.noarch.rpm
645test ! -f "${cf}" && echo OK2
646echo "buster" > "${cf}"
647cat "${cf}"
648runroot rpm -U /build/RPMS/noarch/configtest-2.0-1.noarch.rpm
649cat "${cf}"
650runroot rpm -e configtest
651cat "${cf}"
652],
653[],
654[OK1
655keaton
656keaton
657keaton
658OK2
659buster
660buster
661buster
662],
663[])
664AT_CLEANUP
665