From 80e887dd8a91bbf8479f4df7355dd4cdfbf7bc87 Mon Sep 17 00:00:00 2001 From: Alex Crawford Date: Tue, 10 Feb 2015 16:01:04 -0800 Subject: [PATCH] oem/azure: add share-image.sh --- oem/azure/share-image.sh | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 oem/azure/share-image.sh diff --git a/oem/azure/share-image.sh b/oem/azure/share-image.sh new file mode 100755 index 0000000000..5db5a8a77b --- /dev/null +++ b/oem/azure/share-image.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +# This script will replicate the given image into all Azure regions. It needs +# to be run in an environment where the azure-xplat-cli has been installed and +# configured with the production credentials and (optionally) SUBSCRIPTION_ID +# is defined, containing the subscription GUID. + +DIR=$(dirname $0) +. $DIR/common.sh + +set -e + +GROUP="${1^}" +VERSION=$2 + +if [[ -z $GROUP || -z $VERSION ]]; then + echo "Usage: $0 " + exit 2 +fi + +image_name="CoreOS-${GROUP}-${VERSION}" + +subscription_id=$SUBSCRIPTION_ID +if [ -z $subscription_id ]; then + subscription_id=$(getSubscriptionId) +fi + +url="$(getManagementEndpoint)/${subscription_id}/services/images/${image_name}/share?permission=public" + +workdir=$(mktemp --directory) +trap "rm --force --recursive ${workdir}" SIGINT SIGTERM EXIT + +azure account cert export \ + --file="${workdir}/cert" \ + --subscription="${subscription_id}" > /dev/null + +result=$(curl \ + --silent \ + --request PUT \ + --header "x-ms-version: 2014-10-01" \ + --header "Content-Type: application/xml" \ + --header "Content-Length: 0" \ + --cert "${workdir}/cert" \ + --url "${url}" \ + --write-out "%{http_code}" \ + --output "${workdir}/out") + +if [[ $result != 200 ]]; then + echo "${result} - $(< ${workdir}/out)" + exit 1 +fi