Files
secureblue/build.sh
ER 38dda90a23 refactor: rename fedora version to os version
this change makes sense for when in the future it's possible to
build other OS's with this same system
it was done now, because i'm bundling a bunch of breaking changes
into a single update
2023-08-13 18:00:58 +03:00

51 lines
1.8 KiB
Bash

#!/usr/bin/env bash
# Tell build process to exit if there are any errors.
set -oue pipefail
export CONFIG_DIRECTORY="/usr/share/ublue-os/startingpoint"
RECIPE_FILE="$CONFIG_DIRECTORY/$RECIPE"
MODULE_DIRECTORY="/tmp/modules"
# https://mikefarah.gitbook.io/yq/usage/tips-and-tricks#yq-in-a-bash-loop
get_yaml_array() {
# creates array $1 with content at key $2 from $3
readarray "$1" < <(echo "$3" | yq -o=j -I=0 "$2")
}
export -f get_yaml_array # this makes the function available to all modules
# Declare dynamically generated variables as read-only and exported
declare -rx IMAGE_NAME BASE_IMAGE OS_VERSION
# Read configuration variables.
BASE_IMAGE="$(yq '.base-image' "$RECIPE_FILE")"
IMAGE_NAME="$(yq '.name' "$RECIPE_FILE")"
# Automatically determine which Fedora version we're building.
OS_VERSION="$(grep -Po '(?<=VERSION_ID=)\d+' /usr/lib/os-release)"
# Welcome.
echo "Building $IMAGE_NAME from $BASE_IMAGE:$OS_VERSION."
# Run each module
readarray MODULES < <(yq -o=j -I=0 '.modules[]' "$RECIPE_FILE" )
for MODULE in "${MODULES[@]}"; do
TYPE=$(echo "$MODULE" | yq '.type')
if [[ "$TYPE" != "null" ]]; then
# If type is found, that means that the module config
# has been declared inline, and thus is safe to pass to the module
echo "=== Launching module of type: $TYPE ==="
bash "$MODULE_DIRECTORY/$TYPE/$TYPE.sh" "$MODULE"
else
# If the type is not found, that means that the module config
# is in a separate file, and has to be read from it
FILE=$(echo "$MODULE" | yq '.from-file')
MODULE_CONFIG=$(yq -o=j -I=0 '.' "$CONFIG_DIRECTORY/$FILE")
TYPE=$(echo "$MODULE_CONFIG" | yq '.type')
echo "=== Launching module of type: $TYPE ==="
bash "$MODULE_DIRECTORY/$TYPE/$TYPE.sh" "$MODULE_CONFIG"
fi
echo "======"
done