#!/usr/bin/env bash set -euo pipefail ostree_dir="${OSTREE_DIR:-"$(dirname "$(realpath "$0")")"}" if [ -z "${4:-}" ] || [ "${1:-}" = help ] || [ "${1:-}" = -h ]; then cat <&2 echo ERROR - could not find role "$role" - please use ANSIBLE_COLLECTIONS_PATH exit 2 } get_packages() { local ostree_dir pkgtype pkgfile rolefile ostree_dir="$1" for pkgtype in "${pkgtypes[@]}"; do for suff in "" "-$distro" "-${distro}-${major_ver}" "-${distro}-${ver}"; do pkgfile="$ostree_dir/packages-${pkgtype}${suff}.txt" if [ -f "$pkgfile" ]; then cat "$pkgfile" fi done rolefile="$ostree_dir/roles-${pkgtype}.txt" if [ -f "$rolefile" ]; then local roles role rolepath roles="$(cat "$rolefile")" for role in $roles; do rolepath="$(get_rolepath "$ostree_dir" "$role")" if [ -z "$rolepath" ]; then 1>&2 echo ERROR - could not find role "$role" - please use ANSIBLE_COLLECTIONS_PATH exit 2 fi get_packages "$rolepath" done fi done | sort -u } format_packages_json() { local comma pkgs pkg comma="" pkgs="[" while read -r pkg; do pkgs="${pkgs}${comma}\"${pkg}\"" comma=, done pkgs="${pkgs}]" echo "$pkgs" } format_packages_raw() { cat } format_packages_yaml() { while read -r pkg; do echo "- $pkg" done } format_packages_toml() { while read -r pkg; do echo "[[packages]]" echo "name = \"$pkg\"" echo "version = \"*\"" done } distro="${distro_ver%%-*}" ver="${distro_ver##*-}" if [[ "$ver" =~ ^([0-9]*) ]]; then major_ver="${BASH_REMATCH[1]}" else echo ERROR: cannot parse major version number from version "$ver" exit 1 fi "get_$category" "$ostree_dir" | "format_${category}_$format"