mirror of https://github.com/sipwise/ec2-tools.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
1.6 KiB
82 lines
1.6 KiB
#!/bin/bash
|
|
|
|
export TZ="UTC"
|
|
|
|
usage() {
|
|
echo "$0 - script to mark a specified EC2 AMI as public
|
|
|
|
Usage:
|
|
|
|
$0 --ami <AMI_ID> [<OPTIONS>]
|
|
|
|
Supported OPTIONS:
|
|
|
|
--ami <AMI_ID> mark AMI_ID as public
|
|
--help display this help text
|
|
--region <REGION> specify region that should be used
|
|
(if unset defaults to the eu-west-1 zone)
|
|
"
|
|
}
|
|
|
|
CMDLINE_OPTS=ami:,help,region:
|
|
|
|
_opt_temp=$(getopt --name "$0" -o +bch --long ${CMDLINE_OPTS} -- "$@")
|
|
if [ $? -ne 0 ]; then
|
|
echo "Try '$0 --help' for more information." >& 2
|
|
exit 1
|
|
fi
|
|
eval set -- "${_opt_temp}"
|
|
|
|
while :; do
|
|
case "$1" in
|
|
--ami)
|
|
shift; AMI_ID="$1"
|
|
;;
|
|
--help)
|
|
usage ; exit 0;
|
|
;;
|
|
--region)
|
|
shift; AWS_REGION="$1"
|
|
;;
|
|
--)
|
|
shift; break
|
|
;;
|
|
*)
|
|
echo "Internal getopt error! $1" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
# if unset set sane defaults
|
|
[ -n "${AWS_REGION}" ] || AWS_REGION="eu-west-1"
|
|
|
|
check4progs(){
|
|
local RC=''
|
|
for arg in "$@" ; do
|
|
which "${arg}" >/dev/null 2>&1 || RC="${arg}"
|
|
done
|
|
if [ -n "${RC}" ] ; then
|
|
echo "${RC} not found/executable" >&2
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
if ! check4progs aws ; then
|
|
echo "Required tool aws not found, forgot to install awscli?" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [ -z "${AMI_ID}" ] ; then
|
|
usage >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "Marking AMI ${AMI_ID} as public"
|
|
aws ec2 modify-image-attribute --region "${AWS_REGION}" --image-id "${AMI_ID}" --launch-permission "Add=[{Group=all}]"
|
|
if [ $? -ne 0 ] ; then
|
|
echo "Noticed problem when trying to mark AMI with ID ${AMI_ID} as public." >&2
|
|
exit 1
|
|
fi
|