#!/bin/bash
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# runtest.sh of /tools/openscap/Sanity/oscap-builds-ssg
# Description: Checks that scap-security-guide can be built by the tested oscap.
# Author: Matej Tyc <matyc@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2018 Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/bin/rhts-environment.sh || exit 1
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="openscap-utils"
ssgname="scap-security-guide"
ssgtag="v0.1.38"
rlJournalStart
rlPhaseStartSetup
rlAssertRpm $PACKAGE
rlRun "git clone https://github.com/OpenSCAP/$ssgname.git" 0 "Cloning SSG source"
rlRun "pushd $ssgname" 0
rlRun "git checkout $ssgtag" 0 "Check out to the latest released version."
rlRun "mkdir -p build" 0 "Ensuring that build dir exists"
rlRun "pushd build"
rlRun "rm -rf * && cmake .. && make" 0 "Get rid of everything and build ssg from scratch."
rlPhaseEnd
rlPhaseStartTest
rlRun "make test" 0 "Checking that the freshly built SSG is OK"
rlPhaseEnd
rlPhaseStartCleanup
rlRun "popd"
rlRun "popd"
rlRun "rm -rf $ssgname" 0 "Removing the whole SSG tree."
rlPhaseEnd
rlJournalPrintText
rlJournalEnd