particle-os-cli/scripts/exports.sh
Gerald Pinder 0c7033ccd2
feat: Move module run logic into its own script (#168)
This will help make the Containerfile just a little bit easier to read
(ignoring all the mounts lol). This would also allow us to add logic
later to support modules that run executables other than `*.sh`.
2024-04-27 15:19:58 -04:00

27 lines
755 B
Bash

#!/usr/bin/env bash
# Function to retrieve module configs and populate an array
# Arguments:
# 1. Variable name to store result
# 2. jq query
# 3. Module config content
get_yaml_array() {
local -n arr=$1
local jq_query=$2
local module_config=$3
if [[ -z $jq_query || -z $module_config ]]; then
echo "Usage: get_yaml_array VARIABLE_TO_STORE_RESULTS JQ_QUERY MODULE_CONFIG" >&2
return 1
fi
readarray -t arr < <(echo "$module_config" | yq -I=0 "$jq_query")
}
# Parse OS version and export it
export OS_VERSION=$(grep -Po "(?<=VERSION_ID=)\d+" /usr/lib/os-release)
# Export functions for use in sub-shells or sourced scripts
export -f get_yaml_array
mkdir -p /var/roothome /var/opt /var/lib/alternatives /var/opt /var/usrlocal