2023-05-09 15:34:59 +02:00
|
|
|
#!/usr/bin/env bash
|
2023-05-09 15:26:26 +02:00
|
|
|
|
|
|
|
# Tell build process to exit if there are any errors.
|
2023-05-09 16:29:59 +02:00
|
|
|
set -oue pipefail
|
2023-05-09 15:26:26 +02:00
|
|
|
|
2023-08-13 15:06:44 +02:00
|
|
|
export CONFIG_DIRECTORY="/usr/share/ublue-os/startingpoint"
|
2023-08-13 14:19:55 +02:00
|
|
|
RECIPE_FILE="$CONFIG_DIRECTORY/$RECIPE"
|
2023-08-13 14:24:11 +02:00
|
|
|
MODULE_DIRECTORY="/tmp/modules"
|
2023-08-09 19:27:42 +02:00
|
|
|
|
2023-08-13 14:00:21 +02:00
|
|
|
# https://mikefarah.gitbook.io/yq/usage/tips-and-tricks#yq-in-a-bash-loop
|
2023-05-09 16:56:23 +02:00
|
|
|
get_yaml_array() {
|
2023-08-13 15:59:23 +02:00
|
|
|
# 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")
|
2023-05-09 18:36:27 +02:00
|
|
|
}
|
2023-08-13 15:59:23 +02:00
|
|
|
export -f get_yaml_array # this makes the function available to all modules
|
2023-08-13 14:00:21 +02:00
|
|
|
|
2023-08-13 16:29:11 +02:00
|
|
|
# Declare dynamically generated variables as read-only and exported
|
2023-08-13 17:14:06 +02:00
|
|
|
declare -x IMAGE_NAME BASE_IMAGE OS_VERSION
|
2023-05-09 19:56:25 +02:00
|
|
|
|
2023-05-09 18:41:40 +02:00
|
|
|
# Read configuration variables.
|
2023-08-13 14:19:55 +02:00
|
|
|
BASE_IMAGE="$(yq '.base-image' "$RECIPE_FILE")"
|
|
|
|
IMAGE_NAME="$(yq '.name' "$RECIPE_FILE")"
|
2023-05-09 19:56:25 +02:00
|
|
|
|
2023-08-13 16:29:11 +02:00
|
|
|
# Automatically determine which Fedora version we're building.
|
2023-08-13 17:00:58 +02:00
|
|
|
OS_VERSION="$(grep -Po '(?<=VERSION_ID=)\d+' /usr/lib/os-release)"
|
2023-08-13 16:29:11 +02:00
|
|
|
|
2023-05-09 19:56:25 +02:00
|
|
|
# Welcome.
|
2023-08-13 17:00:58 +02:00
|
|
|
echo "Building $IMAGE_NAME from $BASE_IMAGE:$OS_VERSION."
|
2023-07-23 21:10:12 +02:00
|
|
|
|
2023-08-09 19:27:42 +02:00
|
|
|
# Run each module
|
2023-08-13 15:59:23 +02:00
|
|
|
readarray MODULES < <(yq -o=j -I=0 '.modules[]' "$RECIPE_FILE" )
|
2023-07-23 08:37:13 +02:00
|
|
|
|
2023-08-13 14:09:40 +02:00
|
|
|
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 ==="
|
2023-08-13 14:09:40 +02:00
|
|
|
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"
|
2023-08-13 14:09:40 +02:00
|
|
|
fi
|
2023-08-13 16:20:25 +02:00
|
|
|
echo "======"
|
2023-08-09 19:27:42 +02:00
|
|
|
done
|