#    rpmconfig3.at: rpm config file type change tests

AT_BANNER([RPM config filetype changes])

AT_SETUP([upgrade config to/from non-config])
AT_KEYWORDS([install])
RPMDB_INIT

runroot rpmbuild --quiet -bb \
        --define "ver 1.0" \
	--define "filetype file" \
	--define "filedata foo" \
          /data/SPECS/configtest.spec

runroot rpmbuild --quiet -bb \
        --define "ver 2.0" \
	--define "filetype file" \
	--define "filedata bar" \
	--define "noconfig 1" \
          /data/SPECS/configtest.spec

# non-modified config changes to non-config and back, no backups
RPMTEST_CHECK([
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}" "${cf}".rpm*

runroot rpm -U /build/RPMS/noarch/configtest-1.0-1.noarch.rpm
cat "${cf}"
runroot rpm -U /build/RPMS/noarch/configtest-2.0-1.noarch.rpm
cat "${cf}"
runroot rpm -U --oldpackage /build/RPMS/noarch/configtest-1.0-1.noarch.rpm
cat "${cf}"
],
[0],
[foo
bar
foo
],
[])

# modified config changes to non-config and back, back up on first upgrade
RPMTEST_CHECK([
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}"*

runroot rpm -U /build/RPMS/noarch/configtest-1.0-1.noarch.rpm
cat "${cf}"
echo "otherstuff" > "${cf}"
cat "${cf}"
runroot rpm -U /build/RPMS/noarch/configtest-2.0-1.noarch.rpm
cat "${cf}"
cat "${cf}.rpmsave"
runroot rpm -U --oldpackage /build/RPMS/noarch/configtest-1.0-1.noarch.rpm
cat "${cf}"
],
[0],
[foo
otherstuff
bar
otherstuff
foo
],
[warning: /etc/my.conf saved as /etc/my.conf.rpmsave]
)

# modified config changes to identical non-config and back, no backups
RPMTEST_CHECK([
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}"*

runroot rpm -U /build/RPMS/noarch/configtest-1.0-1.noarch.rpm
cat "${cf}"
echo "bar" > "${cf}"
cat "${cf}"
runroot rpm -U /build/RPMS/noarch/configtest-2.0-1.noarch.rpm
cat "${cf}"
runroot rpm -U --oldpackage /build/RPMS/noarch/configtest-1.0-1.noarch.rpm
cat "${cf}"
],
[0],
[foo
bar
bar
foo
],
[])
RPMTEST_CLEANUP

AT_SETUP([upgrade config to/from config link])
AT_KEYWORDS([install])
RPMDB_INIT

runroot rpmbuild --quiet -bb \
        --define "ver 1.0" \
	--define "filetype file" \
	--define "filedata foo" \
          /data/SPECS/configtest.spec

runroot rpmbuild --quiet -bb \
        --define "ver 2.0" \
	--define "filetype link" \
	--define "filedata bar" \
          /data/SPECS/configtest.spec

# non-modified config file changes to config symlink and back, no backups
RPMTEST_CHECK([
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}" "${cf}".rpm*

runroot rpm -U /build/RPMS/noarch/configtest-1.0-1.noarch.rpm
cat "${cf}"
runroot rpm -U /build/RPMS/noarch/configtest-2.0-1.noarch.rpm
readlink "${cf}"
runroot rpm -U --oldpackage /build/RPMS/noarch/configtest-1.0-1.noarch.rpm
cat "${cf}"
],
[0],
[foo
bar
foo
],
[])

# Modified config changes to config symlink
RPMTEST_CHECK([
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}" "${cf}".rpm*

runroot rpm -U /build/RPMS/noarch/configtest-1.0-1.noarch.rpm
cat "${cf}"
echo "otherstuff" > "${cf}"
cat "${cf}"
runroot rpm -U /build/RPMS/noarch/configtest-2.0-1.noarch.rpm
readlink "${cf}"
cat "${cf}.rpmsave"
],
[0],
[foo
otherstuff
bar
otherstuff
],
[warning: /etc/my.conf saved as /etc/my.conf.rpmsave]
)
RPMTEST_CLEANUP

# Modified config link changes to config file
AT_SETUP([upgrade modified config link to config])
AT_KEYWORDS([install])
RPMTEST_CHECK([
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}" "${cf}".rpm*

runroot rpmbuild --quiet -bb \
        --define "ver 1.0" \
	--define "filetype link" \
	--define "filedata foo" \
          /data/SPECS/configtest.spec

runroot rpmbuild --quiet -bb \
        --define "ver 2.0" \
	--define "filetype file" \
	--define "filedata bar" \
          /data/SPECS/configtest.spec

runroot rpm -U /build/RPMS/noarch/configtest-1.0-1.noarch.rpm
readlink "${cf}"
ln -sf "otherstuff" "${cf}"
readlink "${cf}"
runroot rpm -U /build/RPMS/noarch/configtest-2.0-1.noarch.rpm
cat "${cf}"
readlink "${cf}.rpmsave"
],
[0],
[foo
otherstuff
bar
otherstuff
],
[warning: /etc/my.conf saved as /etc/my.conf.rpmsave]
)
RPMTEST_CLEANUP

AT_SETUP([upgrade config to directory])
AT_KEYWORDS([install])
RPMDB_INIT

runroot rpmbuild --quiet -bb \
        --define "ver 1.0" \
	--define "filetype file" \
	--define "filedata foo" \
          /data/SPECS/configtest.spec

runroot rpmbuild --quiet -bb \
        --define "ver 2.0" \
	--define "filetype dir" \
          /data/SPECS/configtest.spec

# Non-modified config file changes to directory.
RPMTEST_CHECK([
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}"*

runroot rpm -U /build/RPMS/noarch/configtest-1.0-1.noarch.rpm
cat "${cf}"
runroot rpm -U /build/RPMS/noarch/configtest-2.0-1.noarch.rpm
test -d "${cf}"
],
[0],
[foo
],
[])

# Modified config changes to directory
RPMTEST_CHECK([
RPMDB_INIT
cf="${RPMTEST}"/etc/my.conf
rm -rf "${cf}"*

runroot rpm -U /build/RPMS/noarch/configtest-1.0-1.noarch.rpm
cat "${cf}"
echo "otherstuff" > "${cf}"
cat "${cf}"
runroot rpm -U /build/RPMS/noarch/configtest-2.0-1.noarch.rpm
test -d "${cf}"
cat "${cf}.rpmsave"
],
[0],
[foo
otherstuff
otherstuff
],
[warning: /etc/my.conf saved as /etc/my.conf.rpmsave]
)
RPMTEST_CLEANUP
