ansible-sshd/meta/make_ostree_packages_files
Rich Megginson 4543f0c679 feat: support for ostree systems
Feature: Allow running and testing the role with ostree managed nodes.

Reason: We have users who want to use the role to manage ostree
systems.

Result: Users can use the role to manage ostree managed nodes.
Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2023-11-28 09:40:18 -07:00

48 lines
1.4 KiB
Bash
Executable file

#!/bin/bash
set -euo pipefail
declare -A os_family=( [RedHat]=RedHat [CentOS]=RedHat [Fedora]=RedHat
[AlmaLinux]=RedHat [Rocky]=RedHat [OracleLinux]=RedHat )
for file in vars/*.yml; do
if [ "$file" = vars/main.yml ]; then
continue
fi
# get platform and optional version
if [[ "$file" =~ vars/([^_]+)_([0-9]+).yml$ ]]; then
platform="${BASH_REMATCH[1]}"
version="${BASH_REMATCH[2]}"
packages_file=".ostree/packages-runtime-${platform}-${version}.txt"
elif [[ "$file" =~ vars/([^_.]+).yml$ ]]; then
platform="${BASH_REMATCH[1]}"
packages_file=".ostree/packages-runtime-${platform}.txt"
else
echo ERROR: cannot parse "$file"
exit 1
fi
# only os_family == RedHat is supported
if [ "${os_family[$platform]:-}" = RedHat ]; then
: # proceed - fall through
else
echo platform "$platform" not supported for ostree
continue
fi
# parse packages from file
printit=0
while read -r item pkg; do
if [[ "$item" =~ ^__sshd_packages: ]]; then
printit=1
elif [ "$printit" = 1 ]; then
if [ "$item" = "-" ] && [ -n "$pkg" ]; then
echo "$pkg"
else
break
fi
fi
done < "$file" | sort > "$packages_file"
# remove empty files
if [ ! -s "$packages_file" ]; then
rm -f "$packages_file"
fi
done