gentoo_bootstrap / make_latest_public.sh

#!/bin/bash

region=$1
architecture=$2
root_device_type=$3

if [ $architecture == "x86_64" -a $root_device_type == "ebs" ]; then
    building="Gentoo 64 EBS"
elif [ $architecture == "i386" -a $root_device_type == "ebs" ]; then
	building="Gentoo 32 EBS"
elif [ $architecture == "x86_64" -a $root_device_type == "instance-store" ]; then
    building="Gentoo 64 Instance-Store"
elif [ $architecture == "i386" -a $root_device_type == "instance-store" ]; then
	building="Gentoo 32 Instance-Store" 
else
	echo "Unknown architecture, root_device_type combination"
	echo "architecture = $architecture"
	echo "root_device_type = $root_device_type"
	echo "valid values for architecture: x86_64, i386"
	echo "valid values for root_device_type: ebs, instance-store"
	exit
fi

start_time=`date +%Y-%m-%dT%H:%M:%S`

echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: AMI_TYPE = $AMI_TYPE"
echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: region = $region"
echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: architecture = $architecture"
echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: root_device_type = $root_device_type"

echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: finding latest image"

if [ -z $AMI_TYPE ]; then
    manifest_location="*/Gentoo_*"
else
    manifest_location="*/{$AMI_TYPE}-Gentoo_*"
fi

latest_image=`ec2-describe-images \
--region $region \
--owner self \
--filter image-type=machine \
--filter manifest-location=${manifest_location} \
--filter architecture=$architecture \
--filter root-device-type=$root_device_type \
| grep "^IMAGE" \
| awk '{ print $3 $0 }' \
| sort -r \
| head -n 1`

echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: latest_image = $latest_image"

echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: checking if public"

public_check=`echo $latest_image | awk '{ print $6 }'`

if [[ $public_check == "public" ]]; then
	echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: already public"
	exit
else
	echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: is private"
fi

echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: finding ami"

ami=`echo $latest_image | awk '{ print $2 }'`

echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: ami = $ami"

echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: making public"
ec2-modify-image-attribute --region $region $ami --launch-permission --add all
echo "$building $start_time - `date +%Y-%m-%dT%H:%M:%S`: done"
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.