#    rpmscript.at: rpm scriptlet tests

AT_BANNER([RPM scriptlets])

# ------------------------------
# 
AT_SETUP([basic scripts and arguments])
AT_KEYWORDS([verify])
AT_CHECK([
RPMDB_CLEAR
RPMDB_INIT
rm -rf "${TOPDIR}"

runroot rpmbuild --quiet -bb /data/SPECS/fakeshell.spec
runroot rpmbuild --quiet -bb --define "rel 1" /data/SPECS/scripts.spec
runroot rpmbuild --quiet -bb --define "rel 2" /data/SPECS/scripts.spec

runroot rpm -U /build/RPMS/noarch/fakeshell-1.0-1.noarch.rpm
runroot rpm -Vvp /build/RPMS/noarch/scripts-1.0-1.noarch.rpm
runroot rpm -U /build/RPMS/noarch/scripts-1.0-1.noarch.rpm
runroot rpm -U /build/RPMS/noarch/scripts-1.0-2.noarch.rpm
runroot rpm -Vv scripts
runroot rpm -e scripts
],
[0],
[scripts-1.0-1 VERIFY 0
scripts-1.0-1 PRETRANS 1
scripts-1.0-1 PRE 1
scripts-1.0-1 POST 1
scripts-1.0-1 POSTTRANS 1
scripts-1.0-2 PRETRANS 2
scripts-1.0-2 PRE 2
scripts-1.0-2 POST 2
scripts-1.0-1 PREUN 1
scripts-1.0-1 POSTUN 1
scripts-1.0-2 POSTTRANS 1
scripts-1.0-2 VERIFY 1
scripts-1.0-2 PREUN 0
scripts-1.0-2 POSTUN 0
],
[])
AT_CLEANUP

AT_SETUP([basic trigger scripts and arguments])
AT_KEYWORDS([trigger script])
AT_CHECK([
RPMDB_CLEAR
RPMDB_INIT
rm -rf "${TOPDIR}"

runroot rpmbuild --quiet -bb /data/SPECS/fakeshell.spec
runroot rpmbuild --quiet -bb --define "rel 1" /data/SPECS/scripts.spec
runroot rpmbuild --quiet -bb --define "rel 2" /data/SPECS/scripts.spec
runroot rpmbuild --quiet -bb --define "rel 1" --define "trigpkg scripts" /data/SPECS/triggers.spec
runroot rpmbuild --quiet -bb --define "rel 2" --define "trigpkg scripts" /data/SPECS/triggers.spec

runroot rpm -U /build/RPMS/noarch/fakeshell-1.0-1.noarch.rpm
echo TRIGGERS 1
runroot rpm -U /build/RPMS/noarch/triggers-1.0-1.noarch.rpm
echo SCRIPTS 1
runroot rpm -U /build/RPMS/noarch/scripts-1.0-1.noarch.rpm
echo SCRIPTS 2
runroot rpm -U /build/RPMS/noarch/scripts-1.0-2.noarch.rpm
echo TRIGGERS 2
runroot rpm -U /build/RPMS/noarch/triggers-1.0-2.noarch.rpm
echo ERASE
runroot rpm -e scripts
],
[0],
[TRIGGERS 1
SCRIPTS 1
scripts-1.0-1 PRETRANS 1
triggers-1.0-1 TRIGGERPREIN 1 0
scripts-1.0-1 PRE 1
scripts-1.0-1 POST 1
triggers-1.0-1 TRIGGERIN 1 1
scripts-1.0-1 POSTTRANS 1
SCRIPTS 2
scripts-1.0-2 PRETRANS 2
triggers-1.0-1 TRIGGERPREIN 1 1
scripts-1.0-2 PRE 2
scripts-1.0-2 POST 2
triggers-1.0-1 TRIGGERIN 1 2
triggers-1.0-1 TRIGGERUN 1 1
scripts-1.0-1 PREUN 1
scripts-1.0-1 POSTUN 1
triggers-1.0-1 TRIGGERPOSTUN 1 1
scripts-1.0-2 POSTTRANS 1
TRIGGERS 2
triggers-1.0-2 TRIGGERPREIN 1 1
triggers-1.0-2 TRIGGERIN 2 1
triggers-1.0-1 TRIGGERUN 1 1
ERASE
triggers-1.0-2 TRIGGERUN 1 0
scripts-1.0-2 PREUN 0
scripts-1.0-2 POSTUN 0
triggers-1.0-2 TRIGGERPOSTUN 1 0
],
[])
AT_CLEANUP

AT_SETUP([basic file trigger scripts])
AT_KEYWORDS([file trigger script])
AT_CHECK([
RPMDB_CLEAR
RPMDB_INIT
rm -rf "${TOPDIR}"

runroot rpmbuild --quiet -bb /data/SPECS/fakeshell.spec
runroot rpmbuild --quiet -bb /data/SPECS/hello-script.spec
runroot rpmbuild --quiet -bb /data/SPECS/hlinktest.spec
runroot rpmbuild --quiet -bb /data/SPECS/filetriggers.spec

runroot rpm -U /build/RPMS/noarch/fakeshell-1.0-1.noarch.rpm
runroot rpm -U /build/RPMS/noarch/filetriggers-1.0-1.noarch.rpm
echo INSTALLATION
runroot rpm -U /build/RPMS/noarch/hello-script-1.0-1.noarch.rpm \
/build/RPMS/noarch/hlinktest-1.0-1.noarch.rpm
echo ERASE
runroot rpm -e hello-script hlinktest
],
[0],
[INSTALLATION
filetriggerin(/foo*):
/foo/aaaa
/foo/copyllo
/foo/hello
/foo/hello-bar
/foo/hello-foo
/foo/hello-world
/foo/zzzz

filetriggerin(/foo*)<lua>:
/foo/aaaa
/foo/copyllo
/foo/hello
/foo/hello-bar
/foo/hello-foo
/foo/hello-world
/foo/zzzz

filetriggerin(/usr/bin*):
/usr/bin/hello

filetriggerin(/usr/bin*)<lua>:
/usr/bin/hello

transfiletriggerin(/usr/bin*):
/usr/bin/hello

transfiletriggerin(/foo*):
/foo/aaaa
/foo/copyllo
/foo/hello
/foo/hello-bar
/foo/hello-foo
/foo/hello-world
/foo/zzzz

ERASE
transfiletriggerun(/usr/bin*):
/usr/bin/hello

transfiletriggerun(/foo*):
/foo/aaaa
/foo/copyllo
/foo/hello
/foo/hello-bar
/foo/hello-foo
/foo/hello-world
/foo/zzzz

filetriggerun(/foo*):
/foo/aaaa
/foo/copyllo
/foo/hello
/foo/hello-bar
/foo/hello-foo
/foo/hello-world
/foo/zzzz

filetriggerpostun(/foo*):
/foo/aaaa
/foo/copyllo
/foo/hello
/foo/hello-bar
/foo/hello-foo
/foo/hello-world
/foo/zzzz

filetriggerun(/usr/bin*):
/usr/bin/hello

filetriggerpostun(/usr/bin*):
/usr/bin/hello

transfiletriggerpostun(/usr/bin*):

transfiletriggerpostun(/foo*):

],
[])
AT_CLEANUP

# 
AT_SETUP([Proper reset of nice/ionice levels on scripts - only works as root!])
AT_KEYWORDS([verify nice])
AT_CHECK([
AT_XFAIL_IF([test `whoami` != root ])
RPMDB_CLEAR
RPMDB_INIT
rm -rf "${TOPDIR}"

runroot rpmbuild --quiet -bb /data/SPECS/fakeshell.spec
runroot rpmbuild --quiet -bb --define "rel 1" /data/SPECS/scripts-nice-ionice.spec
runroot rpmbuild --quiet -bb --define "rel 2" /data/SPECS/scripts-nice-ionice.spec

runroot rpm -U /build/RPMS/noarch/fakeshell-1.0-1.noarch.rpm
runroot nice -n 10 ionice -c3 rpm -Vvp /build/RPMS/noarch/scripts-nice-ionice-1.0-1.noarch.rpm
runroot nice -n 10 ionice -c3 rpm -U /build/RPMS/noarch/scripts-nice-ionice-1.0-1.noarch.rpm
runroot nice -n 10 ionice -c3 rpm -U /build/RPMS/noarch/scripts-nice-ionice-1.0-2.noarch.rpm
runroot nice -n 10 ionice -c3 rpm -Vv scripts-nice-ionice
runroot nice -n 10 ionice -c3 rpm -e scripts-nice-ionice
],
[0],
[scripts-nice-ionice-1.0-1 VERIFY 0
Nice value is 0
IOnice value is none: prio 4
scripts-nice-ionice-1.0-1 PRETRANS 1
Nice value is 0
IOnice value is none: prio 4
scripts-nice-ionice-1.0-1 PRE 1
Nice value is 0
IOnice value is none: prio 4
scripts-nice-ionice-1.0-1 POST 1
Nice value is 0
IOnice value is none: prio 4
scripts-nice-ionice-1.0-1 POSTTRANS 1
Nice value is 0
IOnice value is none: prio 4
scripts-nice-ionice-1.0-2 PRETRANS 2
Nice value is 0
IOnice value is none: prio 4
scripts-nice-ionice-1.0-2 PRE 2
Nice value is 0
IOnice value is none: prio 4
scripts-nice-ionice-1.0-2 POST 2
Nice value is 0
IOnice value is none: prio 4
scripts-nice-ionice-1.0-1 PREUN 1
Nice value is 0
IOnice value is none: prio 4
scripts-nice-ionice-1.0-1 POSTUN 1
Nice value is 0
IOnice value is none: prio 4
scripts-nice-ionice-1.0-2 POSTTRANS 1
Nice value is 0
IOnice value is none: prio 4
scripts-nice-ionice-1.0-2 VERIFY 1
Nice value is 0
IOnice value is none: prio 4
scripts-nice-ionice-1.0-2 PREUN 0
Nice value is 0
IOnice value is none: prio 4
scripts-nice-ionice-1.0-2 POSTUN 0
Nice value is 0
IOnice value is none: prio 4
],
[])
AT_CLEANUP
