Skip to content

Commit

Permalink
Merge pull request #202 from Honny1/auto-product
Browse files Browse the repository at this point in the history
Auto product
  • Loading branch information
jan-cerny authored Jul 25, 2023
2 parents d3c2903 + 9878eb2 commit 0aecd7a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 42 deletions.
51 changes: 35 additions & 16 deletions generate_arf.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env bash
# This script generate ARF results.
# This script generates ARF results.
# Supported OS:
# - Fedora
# - RHEL8/9
# - Centos8/9
# Requirements:
# - cmake
# - make
Expand All @@ -12,8 +16,7 @@
# - scap-security-guide
# Usage: ./generate_arf MODE FETCH PRODUCT ARF_FILE SKIP_BUILD
# MODE [latest, ssg] use scap-security-guide or latest content from github
# FETCH [yes, no] scanner fetch remote resources
# PRODUCT build or use security content for one specific product
# FETCH [yes, no] scanner fetch remote resources
# ARF_FILE Writes results to a given ARF_FILE.
# SKIP_BUILD [yes] Skip build of latest content(Have affect with mode latest).

Expand All @@ -25,13 +28,16 @@ build_content() {
product=$1

echo "Build - Start"

git clone https://github.com/ComplianceAsCode/content.git
cd content/
git checkout master

./build_product "${product}"
cd ..

cd build/
cmake ../
make -j4 "${product}"

cd ../../
echo "Build - Done"
}

Expand All @@ -48,6 +54,24 @@ run_oscap_scan() {
fi
}

get_product() {
cpe_name=$(grep "CPE_NAME=" < /etc/os-release | sed 's/CPE_NAME=//g' | sed 's/["]//g')
if [[ "${cpe_name}" =~ fedora ]]; then
echo "fedora"
elif [[ "${cpe_name}" =~ redhat.*8 ]]; then
echo "rhel8"
elif [[ "${cpe_name}" =~ redhat.*9 ]]; then
echo "rhel9"
elif [[ "${cpe_name}" =~ centos.*8 ]]; then
echo "centos8"
elif [[ "${cpe_name}" =~ centos.*9 ]]; then
echo "cs9"
else
echo $cpe_name
echo "ERROR: Not supported OS!"
exit 1
fi
}

if [ "$1" = "" ]; then
echo "ERROR: Missing MODE parameter!"
Expand All @@ -62,17 +86,12 @@ fi


if [ "$3" = "" ]; then
echo "ERROR: Missing PRODUCT parameter!"
exit 1
fi

if [ "$4" = "" ]; then
echo "ERROR: Missing PRODUCT parameter!"
echo "ERROR: Missing ARF_FILE parameter!"
exit 1
fi
file=$3

file=$4
product=$3
product=$(get_product)

fetch="--fetch-remote-resources"
if [ "$2" = "no" ]; then
Expand All @@ -81,7 +100,7 @@ fi


if [ "$1" = "latest" ]; then
if [ "$5" != "yes" ]; then
if [ "$4" != "yes" ]; then
build_content "${product}"
fi
run_oscap_scan "./content/build/ssg-${product}-ds.xml" "${fetch}" "${file}"
Expand Down
34 changes: 8 additions & 26 deletions plans/integration.fmf
Original file line number Diff line number Diff line change
@@ -1,27 +1,8 @@
summary: Test integration with latest versions of content
discover+:
filter: tag:integration
adjust:
- when: distro == fedora
environment:
PRODUCT: fedora
TO_BUILD_PRODUCT: fedora
- when: distro == rhel-9
environment:
PRODUCT: rhel9
TO_BUILD_PRODUCT: rhel9
- when: distro == rhel-8
environment:
PRODUCT: rhel8
TO_BUILD_PRODUCT: rhel8
- when: distro == centos-8
environment:
PRODUCT: centos8
TO_BUILD_PRODUCT: rhel8
- when: distro == centos-9 or distro == centos-stream-9
environment:
PRODUCT: cs9
TO_BUILD_PRODUCT: rhel9
provision:
memory: 4096
prepare:
- name: Install packages require for generation ARF files
how: install
Expand All @@ -30,18 +11,19 @@ prepare:
- make
- openscap-utils
- openscap-scanner
- python3
- python3-pyyaml
- python3-jinja2
- python3-setuptools
- git
- scap-security-guide
- name: Generate ARF files
how: shell
script:
- ./generate_arf.sh ssg no ${PRODUCT} ${TMT_PLAN_DATA}/arf.xml
- ./generate_arf.sh ssg yes ${PRODUCT} ${TMT_PLAN_DATA}/arf_fetch-remote-resources.xml
- ./generate_arf.sh latest no ${TO_BUILD_PRODUCT} ${TMT_PLAN_DATA}/arf-latest.xml
- ./generate_arf.sh latest yes ${TO_BUILD_PRODUCT} ${TMT_PLAN_DATA}/arf_fetch-remote-resources-latest.xml yes
script:
- ./generate_arf.sh ssg no ${TMT_PLAN_DATA}/arf.xml
- ./generate_arf.sh ssg yes ${TMT_PLAN_DATA}/arf_fetch-remote-resources.xml
- ./generate_arf.sh latest no ${TMT_PLAN_DATA}/arf-latest.xml
- ./generate_arf.sh latest yes ${TMT_PLAN_DATA}/arf_fetch-remote-resources-latest.xml yes

execute:
how: tmt

0 comments on commit 0aecd7a

Please sign in to comment.