From cbcc07d0666e208ca3785ab58f1ed0eabe349b03 Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Sat, 29 Mar 2014 22:16:03 +0100 Subject: [PATCH] Support --ami and --instance-id options --- ec2-publish-ami | 12 +++++++----- ec2-stop-instance | 10 ++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/ec2-publish-ami b/ec2-publish-ami index 2fc1b3f..6c884c3 100755 --- a/ec2-publish-ami +++ b/ec2-publish-ami @@ -15,17 +15,18 @@ usage() { Usage: - $0 + $0 --ami [] Supported OPTIONS: + --ami mark AMI_ID as public --help display this help text --region specify region that should be used (if unset defaults to the eu-west-1 zone) " } -CMDLINE_OPTS=help,region: +CMDLINE_OPTS=ami:,help,region: _opt_temp=$(getopt --name $0 -o +bch --long $CMDLINE_OPTS -- "$@") if [ $? -ne 0 ]; then @@ -38,6 +39,9 @@ _opt_public=false while :; do case "$1" in + --ami) + shift; AMI_ID="$1" + ;; --help) usage ; exit 0; ;; @@ -84,13 +88,11 @@ if ! check4progs ec2-modify-image-attribute ; then exit 1 fi -if [ $# -lt 1 ] ; then +if [ -z "$AMI_ID" ] ; then usage >&2 exit 1 fi -AMI_ID="$1" - echo "Marking AMI $AMI_ID as public" ec2-modify-image-attribute --region "$AWS_REGION" "$AMI_ID" --launch-permission -a all if [ $? -ne 0 ] ; then diff --git a/ec2-stop-instance b/ec2-stop-instance index 4c40b3a..d35b363 100755 --- a/ec2-stop-instance +++ b/ec2-stop-instance @@ -20,13 +20,14 @@ Usage: Supported OPTIONS: --help display this help text + --instance-id operate on specified instance ID --region specify region that should be used (if unset defaults to the eu-west-1 zone) --terminate terminate instead of just stopping the instance " } -CMDLINE_OPTS=help,region:,terminate +CMDLINE_OPTS=help,instance-id:,region:,terminate _opt_temp=$(getopt --name $0 -o +bch --long $CMDLINE_OPTS -- "$@") if [ $? -ne 0 ]; then @@ -43,6 +44,9 @@ while :; do --help) usage ; exit 0; ;; + --instance-id) + shift; INSTANCE_ID="$1" + ;; --region) shift; AWS_REGION="$1" ;; @@ -89,13 +93,11 @@ if ! check4progs ec2-stop-instances ; then exit 1 fi -if [ $# -lt 1 ] ; then +if [ -z "$INSTANCE_ID" ] ; then usage >&2 exit 1 fi -INSTANCE_ID="$1" - if $_opt_terminate ; then echo "Terminating instance ID $INSTANCE_ID (as requested via --terminate)" ec2-terminate-instances --region "$AWS_REGION" "$INSTANCE_ID"