#!/bin/bash PACKER_LOG_FILE='./packer.log' SOURCES="$(for FILE in *.pkr.hcl; do cat $FILE | awk 'BEGIN{f=0} {if($1 ~ /build/ && $2 ~ /{/){f=1};if(f == 1){if($1 ~ /sources/ && $2 ~ /=/ && $3 ~ /\[/){f=2;next}};if(f == 2){if($1 ~ /\]/) {f=0}};if(f == 2){print $0}}' | sed -E 's/"//g;s/,//g;s/sources\.//g'; done)" SOURCE='' NO_PAKER_INIT='' NO_PKG_INSTALL='' # Use $PATH to find packer PACKER='packer' # ------------------------------------------------------------------------------ Usage() { cat < [option] source name: EOF for SRC in $SOURCES; do echo -e "\t$SRC" done cat </dev/null; then sudo dnf install edk2-ovmf libvirt libvirt-daemon-kvm ansible-core libnsl fi fi [ -z "$NO_PAKER_INIT" ] && $PACKER init -upgrade . || exit 1 PACKER_LOG=1 $PACKER build -only=$SOURCE . 2>$PACKER_LOG_FILE || exit 1