You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.6 KiB
70 lines
1.6 KiB
#!/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 <<EOF
|
|
Usage:
|
|
|
|
$0 -s <source name> [option]
|
|
source name:
|
|
EOF
|
|
for SRC in $SOURCES; do
|
|
echo -e "\t$SRC"
|
|
done
|
|
cat <<EOF
|
|
option:
|
|
-n - Do not run packer init;
|
|
-p - Do not packages install;
|
|
Display this help and exit:
|
|
$0 -h
|
|
|
|
EOF
|
|
}
|
|
|
|
# ------------------------------------------------------------------------------
|
|
CheckSource()
|
|
{
|
|
local INSOURCE="$1"
|
|
for SRC in $SOURCES; do
|
|
[ "X$SRC" = "X$INSOURCE" ] && return 0
|
|
done
|
|
return 1
|
|
}
|
|
|
|
while getopts "s:hnp" OPTION; do
|
|
case $OPTION in
|
|
's') SOURCE="$OPTARG" ;;
|
|
'n') NO_PAKER_INIT='Y' ;;
|
|
'p') NO_PKG_INSTALL='Y' ;;
|
|
'h') Usage; exit 0 ;;
|
|
esac
|
|
done
|
|
|
|
shift $(($OPTIND-1))
|
|
OPTIND=1
|
|
|
|
[ -z "$SOURCE" ] && { Usage; exit 1; }
|
|
|
|
CheckSource "$SOURCE" || { echo "Unknown source: $SOURCE"; exit 1; }
|
|
|
|
if [ -z "$NO_PKG_INSTALL" ]; then
|
|
if which dnf &>/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
|