From 454e4c1ad4161ba615f6666810da8f5e645e3d57 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Tue, 23 Sep 2014 17:58:05 -0400 Subject: [PATCH] Added --oem_pkg oem override option to image_to_vm.sh This sets the IMG_FORCE_OEM_PACKAGE variable to the supplied string. If a ':' is present, what follows it gets put in the IMG_FORCE_OEM_USE variable and what precedes in the former. _get_vm_opt() has been modified to generally support forced overrides such as this one, simply set variables named IMG_FORCE_$opt. Now you can do things like: for fmt in cloudstack \ digitalocean \ ec2-compat:ec2 \ ec2-compat:openstack \ ec2-compat:brightbox \ exoscale \ gce \ hyperv \ rackspace \ rackspace-onmetal; do ./image_to_vm.sh --format=qemu --oem_pkg=$fmt ../build/images/amd64-usr/latest/coreos_developer_qemu.sh -curses done rather than having to modify build_library/vm_image_util.sh to test oem builds in qemu. --- build_library/vm_image_util.sh | 38 +++++++++++++++++++++++++++++++++- image_to_vm.sh | 6 ++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/build_library/vm_image_util.sh b/build_library/vm_image_util.sh index 04de1af4c3..19826b672b 100644 --- a/build_library/vm_image_util.sh +++ b/build_library/vm_image_util.sh @@ -31,6 +31,21 @@ VALID_IMG_TYPES=( hyperv ) +#list of oem package names, minus the oem- prefix +VALID_OEM_PACKAGES=( + azure + cloudstack + digitalocean + ec2-compat + exoscale + gce + hyperv + rackspace + rackspace-onmetal + vagrant + vagrant-key +) + # Set at runtime to one of the above types VM_IMG_TYPE=DEFAULT @@ -57,9 +72,15 @@ IMG_DEFAULT_BOOT_KERNEL=1 # If set install the given package name to the OEM partition IMG_DEFAULT_OEM_PACKAGE= +# Forced OEM package name overriding what may be in the format +IMG_FORCE_OEM_PACKAGE= + # USE flags for the OEM package IMG_DEFAULT_OEM_USE= +# Forced USE flags for the OEM package +IMG_FORCE_OEM_USE= + # Hook to do any final tweaks or grab data while fs is mounted. IMG_DEFAULT_FS_HOOK= @@ -210,6 +231,20 @@ set_vm_type() { return 1 } +# Validate and set the oem package, colon delimited USE optional +set_vm_oem_pkg() { + local oem_pkg="${1%:*}" oem_use="${1##*:}" + local valid_pkg + for valid_pkg in "${VALID_OEM_PACKAGES[@]}"; do + if [[ "${oem_pkg}" == "${valid_pkg}" ]]; then + IMG_FORCE_OEM_PACKAGE="oem-${oem_pkg}" + IMG_FORCE_OEM_USE="${oem_use}" + return 0 + fi + done + return 1 +} + # Validate and set source vm image path set_vm_paths() { local src_dir="$1" @@ -238,7 +273,8 @@ _get_vm_opt() { local opt="$1" local type_opt="IMG_${VM_IMG_TYPE}_${opt}" local default_opt="IMG_DEFAULT_${opt}" - echo "${!type_opt:-${!default_opt}}" + local force_opt="IMG_FORCE_${opt}" + echo "${!force_opt:-${!type_opt:-${!default_opt}}}" } # Translate source image names to output names. diff --git a/image_to_vm.sh b/image_to_vm.sh index cc6870df42..162aded577 100755 --- a/image_to_vm.sh +++ b/image_to_vm.sh @@ -40,6 +40,8 @@ DEFINE_boolean prod_image "${FLAGS_FALSE}" \ "Use the production image instead of the default developer image." DEFINE_string to "" \ "Destination folder for VM output file(s)" +DEFINE_string oem_pkg "" \ + "OEM package to install" # include upload options . "${BUILD_LIBRARY_DIR}/release_util.sh" || exit 1 @@ -57,6 +59,10 @@ if ! set_vm_type "${FLAGS_format}"; then die_notrace "Invalid format: ${FLAGS_format}" fi +if [ ! -z "${FLAGS_oem_pkg}" ] && ! set_vm_oem_pkg "${FLAGS_oem_pkg}"; then + die_notrace "Invalid oem : ${FLAGS_oem_pkg}" +fi + if [ -z "${FLAGS_board}" ] ; then die_notrace "--board is required." fi