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.
78 lines
2.0 KiB
78 lines
2.0 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
|
|
fi
|
|
fi
|
|
|
|
[ -z "$NO_PAKER_INIT" ] && $PACKER init -upgrade . || exit 1
|
|
|
|
PACKER_LOG=1 $PACKER build -only=$SOURCE . 2>$PACKER_LOG_FILE || exit 1
|
|
|
|
if [ "$SOURCE" = "vmware-iso.msvsphere-9-ovf-x86_64" ]; then
|
|
OUT_DIR='./vmware-iso.msvsphere-9-ovf-x86_64_ovf'
|
|
rm -rf $OUT_DIR
|
|
mkdir $OUT_DIR
|
|
|
|
/usr/lib/vmware-ovftool/ovftool --machineOutput --X:logFile=./ovftool.log --X:logLevel=verbose --exportFlags=extraconfig --allowExtraConfig --X:vCloudEnableGuestCustomization ./output-msvsphere-9-ovf-x86_64/msvsphere-9.4.vmx $OUT_DIR || exit 1
|
|
fi
|