#!/bin/bash set -e -o pipefail . common.sh # Initialize vars compartment=$(get_tenancy_id) availability_domain=$(get_availability_domain "${compartment}") image_id=$(get_an_image_id "${compartment}") subnet_id=$(get_subnet_id "${compartment}" "${availability_domain}") name= shape="BM.Standard1.36" ipxe=0 ignition= baseurl="http://alpha.release.core-os.net/amd64-usr/current" bucket_base="users.developer.core-os.net/$USER/bmcs" kargs= # Parse args usage="Usage: $0 [args] -n name Options: -c COMPARTMENT Compartment ID (default: ${compartment}) -a AVAIL-DOMAIN Availability domain ID (default: ${availability_domain}) -n NAME Instance name -s SHAPE Instance shape (default: ${shape}) -S SUBNET-ID Subnet ID to use (default: ${subnet_id}) -i IGNITION Path to Ignition config -p Boot with iPXE -I IMAGE-ID Image ID to use; only relevant for non-iPXE (default: ${image_id}) -b BASEURL URL to the image mirror; only relevant for iPXE (default: ${baseurl}) -B BUCKET-BASE GS bucket and relative path for iPXE script (default: ${bucket_base}) -k ARGS Additional kernel command line arguments for iPXE script -h This ;-) " while getopts "c:a:n:s:S:i:pI:b:B:k:h" OPTION do case "${OPTION}" in c) compartment="${OPTARG}" ;; a) availability_domain="${OPTARG}" ;; n) name="${OPTARG}" ;; s) shape="${OPTARG}" ;; S) subnet_id="${OPTARG}" ;; i) ignition="${OPTARG}" ;; p) ipxe=1 ;; I) image_id="${OPTARG}" ;; b) baseurl="${OPTARG}" ;; B) bucket_base="${OPTARG}" ;; k) kargs="${OPTARG}" ;; h) echo "${usage}"; exit 2 ;; *) exit 2 ;; esac done if [[ -z "${name}" ]]; then echo "Instance name is required." >&2 exit 2 fi launch_args=() if [[ "${ipxe}" = 1 ]]; then # Make scratch dir tmpdir=$(mktemp -d bmcs-XXXXXX) trap "rm -rf '${tmpdir}'" EXIT if [[ -n "${ignition}" ]]; then # Generate OEM image mkdir -p "${tmpdir}/usr/share/oem" cp "${ignition}" "${tmpdir}/usr/share/oem/ign.ign" pushd "${tmpdir}" >/dev/null find usr | cpio -o -H newc --quiet | gzip -c > oem.cpio.gz popd >/dev/null # Upload it. Don't delete it afterward, since the instance could # reboot at any point and need the OEM image again. oempath="${bucket_base}/$(mktemp -u XXXXXXX)" gsutil -q cp "${tmpdir}/oem.cpio.gz" "gs://${oempath}" ignition_initrd_args="initrd=ignition coreos.config.url=oem:///ign.ign" ignition_initrd_cmd="initrd --name ignition http://${oempath}" fi # Create iPXE script cat >"${tmpdir}/ipxe" <