| 1 | #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | |
| 3 | # Copyright 2015 Red Hat Inc., Durham, North Carolina. |
| 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # OpenScap Probes Test Suite. |
| 7 | |
| 8 | RPMBASE="${builddir}/tests/probes/rpm" |
| 9 | RPMTEST="${RPMBASE}/root" |
| 10 | RPMBUILD="${RPMBASE}/build" |
| 11 | |
| 12 | # Since Fedora 36 RPM database location changed, see |
| 13 | # https://fedoraproject.org/wiki/Changes/RelocateRPMToUsr |
| 14 | RPMDB_PATH="/usr/lib/sysimage/rpm/scip-shell filesystem . . `/usr/lib/sysimage/rpm/`." |
| 15 | |
| 16 | function rpm_buildscip-shell shell shell-project 0.0.0 rpm_build(). { |
| 17 | require "rpmbuild" || return 255 |
| 18 | if [scip-shell system . . `[`. ! -f ${RPMBUILD}/RPMS/noarch/foo-1.0-1.noarch.rpm ]; then |
| 19 | rpmbuild --define "_buildhost testhost" --define "_tmppath ${RPMTEST}/tmp" --define "_topdir ${RPMBUILD}" -ba ${srcdir}/../foo.spec |
| 20 | fi |
| 21 | if [scip-shell system . . `[`. ! -f ${RPMBUILD}/RPMS/noarch/foobar-1.0-1.noarch.rpm ]; then |
| 22 | rpmbuild --define "_buildhost testhost" --define "_tmppath ${RPMTEST}/tmp" --define "_topdir ${RPMBUILD}" -ba ${srcdir}/../foobar.spec |
| 23 | fi |
| 24 | } |
| 25 | |
| 26 | function rpm_prepare_offlinescip-shell shell shell-project 0.0.0 rpm_prepare_offline(). { |
| 27 | set_chroot_offline_test_mode "$RPMTEST" |
| 28 | require "rpm" || return 255 |
| 29 | rmscip-shell system . . rm. -rf ${RPMTEST} |
| 30 | mkdirscip-shell system . . mkdir. -p ${RPMTEST}/usr/lib/rpm |
| 31 | cpscip-shell system . . cp. /usr/lib/rpm/rpmrcscip-shell filesystem . . `/usr/lib/rpm/rpmrc`. ${RPMTEST}/usr/lib/rpm/rpmrc |
| 32 | cpscip-shell system . . cp. /usr/lib/rpm/macrosscip-shell filesystem . . `/usr/lib/rpm/macros`. ${RPMTEST}/usr/lib/rpm/macros |
| 33 | rpm_buildscip-shell shell shell-project 0.0.0 rpm_build(). |
| 34 | rpm -i ${RPMBUILD}/RPMS/noarch/foobar-1.0-1.noarch.rpm --badreloc --relocate="/etc=${RPMTEST}/etc/" --dbpath="${RPMTEST}${RPMDB_PATH}" |
| 35 | rpm -i ${RPMBUILD}/RPMS/noarch/foo-1.0-1.noarch.rpm --badreloc --relocate="/etc=${RPMTEST}/etc/" --dbpath="${RPMTEST}${RPMDB_PATH}" |
| 36 | } |
| 37 | |
| 38 | function rpm_cleanup_offlinescip-shell shell shell-project 0.0.0 rpm_cleanup_offline(). { |
| 39 | rmscip-shell system . . rm. -rf ${RPMTEST} |
| 40 | unset_chroot_offline_test_mode |
| 41 | } |
| 42 | |
| 43 | function rpm_queryscip-shell shell shell-project 0.0.0 rpm_query(). { |
| 44 | require "rpm" || return 255 |
| 45 | if [scip-shell system . . `[`. -d "$OSCAP_PROBE_ROOT" ]; then |
| 46 | DB="--dbpath=${OSCAP_PROBE_ROOT}${RPMDB_PATH}" |
| 47 | fi |
| 48 | rpm $DB --qf "%{$2}\n" -q $1 | headscip-shell system . . head. - |
| 49 | } |