#!/bin/bash

if [ $# -eq 1 ]; then
	echo "about to create image for instance $1"	
	
	NOW=$(date +"%Y-%m-%d-%H-%M-%S");
	
	
	image=$(ec2-create-image -n "ami-$NOW" -d "this is my testing image"  "$1" | cut -f2);
	echo "The created image is:$image";

	echo "now we are going to wait image to be available for quite some minutes, be patient..."

	while [ 0 -eq 0 ]; do
		result=$(ec2-describe-images $image | cut -f5);


		if [ "$result" == "available" ]; then
			break;
		fi
		
		echo -n .;
		sleep 1;
	done

	echo -e "\nThe result status of image is:$result\n";

fi

