From 693bf2f8153f20912363761e382c35224af14f7f Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Thu, 29 Aug 2013 13:59:30 -0700 Subject: [PATCH 1/2] fix(test_ami): Fix help text. --- oem/ami/test_ami.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/oem/ami/test_ami.sh b/oem/ami/test_ami.sh index 5d91835443..41369f3ac9 100755 --- a/oem/ami/test_ami.sh +++ b/oem/ami/test_ami.sh @@ -12,12 +12,14 @@ set -e -o pipefail USAGE="Usage: $0 -a ami-id - -a ami-id ID of the AMI to be tests (required) + -a ami-id ID of the AMI to be tests + -V VERSION Find AMI by CoreOS version. -K KEY Path to Amazon API private key. -C CERT Path to Amazon API key certificate. -h this ;-) -v Verbose, see all the things! +The AMI to test must be specified by -a or -V. This script must be run from an ec2 host with the ec2 tools installed. " From 592bc59cca84151d85a840523b4669cbc70f923d Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Thu, 29 Aug 2013 14:24:06 -0700 Subject: [PATCH 2/2] add(upload_ami_txt): Upload text file that contains the AMI id. --- oem/ami/upload_ami_txt.sh | 60 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 oem/ami/upload_ami_txt.sh diff --git a/oem/ami/upload_ami_txt.sh b/oem/ami/upload_ami_txt.sh new file mode 100755 index 0000000000..05e1d8b63d --- /dev/null +++ b/oem/ami/upload_ami_txt.sh @@ -0,0 +1,60 @@ +#!/bin/bash +# +# Set pipefail along with -e in hopes that we catch more errors +set -e -o pipefail + +USAGE="Usage: $0 -a ami-id + -V VERSION Find AMI by CoreOS version. (required) + -K KEY Path to Amazon API private key. + -C CERT Path to Amazon API key certificate. + -h this ;-) + -v Verbose, see all the things! + +This script must be run from an ec2 host with the ec2 tools installed. +" + +IMAGE="coreos_production_ami" +URL_FMT="gs://storage.core-os.net/coreos/amd64-generic/%s/${IMAGE}_%s.txt" +AMI= +VER= + +while getopts "a:V:K:C:hv" OPTION +do + case $OPTION in + V) VER="$OPTARG";; + K) export EC2_PRIVATE_KEY="$OPTARG";; + C) export EC2_CERT="$OPTARG";; + h) echo "$USAGE"; exit;; + v) set -x;; + *) exit 1;; + esac +done + +if [[ $(id -u) -eq 0 ]]; then + echo "$0: This command should not be ran run as root!" >&2 + exit 1 +fi + +if [[ -n "$VER" ]]; then + AMI=$(ec2-describe-images -F name="CoreOS-$VER" | grep -m1 ^IMAGE \ + | cut -f2) || true # Don't die silently, error messages are good + if [[ -z "$AMI" ]]; then + echo "$0: Cannot find an AMI for CoreOS $VER" >&2 + exit 1 + fi +else + echo "$0: AMI version required via -V" >&2 + echo "$USAGE" >&2 + exit 1 +fi + +zoneurl=http://instance-data/latest/meta-data/placement/availability-zone +zone=$(curl --fail -s $zoneurl) +region=$(echo $zone | sed 's/.$//') +url=$(printf "$URL_FMT" "$VER" "$region") + +tmp=$(mktemp --suffix=.txt) +trap "rm -f '$tmp'" EXIT +echo "$AMI" > "$tmp" +gsutil cp "$tmp" "$url" +echo "OK"