2024-07-12 11:37:10 -04:00

110 lines
3.1 KiB
Bash
Executable File

#!/bin/bash
#########################################################################################
# Setup for platform certificates for testing
# usage pc_setup.sh -p <profile> -t <test> [-u] [-n]
# By default, copies platform certs (Base and Delta) to the tcg directory.
# -u: upload the certs to the ACA directly.
# -n: disable copy of certs to the tcg directory.
#########################################################################################
# Load env variables
. ./.ci/docker/.env
profile=laptop
test=default
ciTestDir=$HIRS_CI_TEST_ROOT
ciTestHwJsonFile=$HIRS_CI_TEST_HW_JSON_FILE
# By default save the artifacts in EFI and do not upload to the ACA
UPLOAD_ARTIFACTS=NO
PUT_ARTIFACTS_IN_ESP=YES
# Process parameters Argument handling
POSITIONAL_ARGS=()
ORIGINAL_ARGS=("$@")
while [[ $# -gt 0 ]]; do
case $1 in
-p|--profile)
shift # past argument
profile=$1
shift # past parameter
;;
-t|--test)
shift # past argument
test=$1
shift # past parameter
;;
-u|--upload)
UPLOAD_ARTIFACTS=YES
shift # past argument
;;
-n|--no-efi)
PUT_ARTIFACTS_IN_ESP=NO
shift # past argument
;;
-*|--*)
echo "pc_setup.sh: Unknown option $1"
shift # past argument
;;
*)
POSITIONAL_ARGS+=("$1") # save positional arg
# shift # past argument
break
;;
esac
# Profile selections
profileDir="$HIRS_CI_REPO_ROOT/.ci/system-tests/profiles/$profile"
testDir="$profileDir/$test"
pcDir="$testDir/platformcerts"
dmiZip="$profileDir/$profile"_dmi.zip
hwJsonFileName="$profile"_"$test"_hw.json
hwJsonFile="$testDir/$hwJsonFileName"
# Use default settings if profile does not have specific changes
if [ ! -f "$hwJsonFile" ]; then
echo "Test is using a profile with no hardware manifest file. Using default."
hwJsonFile="$profileDir"/default/laptop_default_hw.json
fi
if [ ! -f "$dmiZip" ]; then
echo "Test is using a profile with no DMI data. Using default."
dmiZip="$profileDir"/default/laptop_dmi.zip
fi
# Ensure platform folder under efi is set up and cleared
$HIRS_CI_REPO_ROOT/.ci/system-tests/container/efi_setup.sh -p
echo "Test is using platform cert(s) from $profile : $test"
# Step 1: Copy hw json file, if it exists.
if [ -f "$hwJsonFile" ]; then
echo "hw file used was $hwJsonFile"
cp "$hwJsonFile" "$ciTestHwJsonFile"
fi
# Can remove this once unzip is added to the image
dnf install -y unzip &> /dev/null
# Step 2: Unpack the dmi files.
echo "dmi file used was $dmiZip"
unzip -o "$dmiZip" -d "$ciTestDir"
# Step 3: Copy the platform cert to tcg folder and or upload it to the ACA
if [[ ! -d $pcDir ]]; then
pcDir=$profileDir/default/platformcerts;
fi
pushd $pcDir > /dev/null
# Skip copy of platform cert if .gitigore exists (empty profile)
if [[ ! -f ".gitignore" ]]; then
for cert in * ; do
if [ "$PUT_ARTIFACTS_IN_ESP" = YES ]; then
cp $cert $HIRS_CI_EFI_PATH_PLATFORM
fi
if [ "$UPLOAD_ARTIFACTS" = YES ]; then
curl -k -F "file=@$cert" $SERVER_PCERT_POST
fi
done
fi
popd > /dev/null