ShurikenOS/build.sh

51 lines
1.8 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# Tell build process to exit if there are any errors.
set -oue pipefail
2023-08-13 15:06:44 +02:00
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
2023-08-13 16:20:25 +02:00
readarray "$1" < <(echo "$3" | yq -o=j -I=0 "$2")
}
export -f get_yaml_array # this makes the function available to all modules
2023-08-13 16:29:11 +02:00
# Declare dynamically generated variables as read-only and exported
declare -x IMAGE_NAME BASE_IMAGE OS_VERSION
# Read configuration variables.
BASE_IMAGE="$(yq '.base-image' "$RECIPE_FILE")"
IMAGE_NAME="$(yq '.name' "$RECIPE_FILE")"
2023-08-13 16:29:11 +02:00
# Automatically determine which Fedora version we're building.
OS_VERSION="$(grep -Po '(?<=VERSION_ID=)\d+' /usr/lib/os-release)"
2023-08-13 16:29:11 +02:00
# 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
2023-08-13 16:20:25 +02:00
# 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"
2023-08-13 14:20:34 +02:00
else
2023-08-13 16:20:25 +02:00
# If the type is not found, that means that the module config
# is in a separate file, and has to be read from it
2023-08-13 14:20:34 +02:00
FILE=$(echo "$MODULE" | yq '.from-file')
MODULE_CONFIG=$(yq -o=j -I=0 '.' "$CONFIG_DIRECTORY/$FILE")
TYPE=$(echo "$MODULE_CONFIG" | yq '.type')
2023-08-13 16:20:25 +02:00
echo "=== Launching module of type: $TYPE ==="
2023-08-13 14:20:34 +02:00
bash "$MODULE_DIRECTORY/$TYPE/$TYPE.sh" "$MODULE_CONFIG"
fi
2023-08-13 16:20:25 +02:00
echo "======"
done