echo"AMI ID $imageid will be used for the new Launch Configuration. Note that as-update-launch-config uses Amazon Linux AMIs by default."
}
#determines that the user provided AMI does, in fact, exit
imageidvalidation()
{
#amivalid redirects stderr to stdout - if the user provided AMI does not exist, the if statement will exit as-update-launch-config.sh else it is assumed that the user provided AMI exists
thenecho"The AMI ID $imageid could not be found. If you specify an AMI (-m) it must exist and be in the given region (-r). Note that region (-r defaults to \"us-east-1\" if not given." 1>&2;exit64
elseecho"The user provided AMI \"$imageid\" will be used when updating the Launch Configuration for the Auto Scaling Group \"$asgroupname.\""
fi
}
#confirms that executables required for succesful script execution are available
prerequisitecheck()
{
for prerequisite in basename cut curl date head grep as-update-auto-scaling-group as-describe-launch-configs as-describe-auto-scaling-groups ec2-describe-images
do
#use of "hash" chosen as it is a shell builtin and will add programs to hash table, possibly speeding execution. Use of type also considered - open to suggestions.
hash$prerequisite&> /dev/null
if[[$?==1]]#has exits with exit status of 70, executable was not found
thenecho"In order to use `basename $0`, the executable \"$prerequisite\" must be installed." 1>&2;exit70
fi
done
}
#calls prerequisitecheck function to ensure that all executables required for script execution are available
*)echo"Error with Options Input. Cause of failure is most likely that an unsupported parameter was passed or a parameter was passed without a corresponding option." 1>&2;exit64;;
esac
done
#sets previewmode - will echo commands rather than performing work
case$preview in
true|True)previewmode="echo";echo"Preview Mode is set to $preview" 1>&2;;
""|false|False)previewmode="";;
*)echo"You specified \"$preview\" for Preview Mode. If specifying a Preview Mode you must specific either \"true\" or \"false.\"" 1>&2;exit64;;
esac
# instance-type validator
case$instancetype in
t1.micro|m1.small|c1.medium|m1.medium)bits=$bits;
# bit depth validator for micro to medium instances - demands that input of bits for micro to medium size instances be 32 or 64 bit
if[[$bits -ne 32&& bits -ne 64]]
thenecho"You must specify either a 32-bit (-b 32) or 64-bit (-b 64) platform for the \"$instancetype\" EC2 Instance Type." 1>&2;exit64
"")echo"You did not specify an EC2 Instance Type. You must specify a valid EC2 Instance Type (example: -i m1.small or -i m1.large)." 1>&2;exit 64;;
*)echo"The \"$instancetype\" EC2 Instance Type does not exist. You must specify a valid EC2 Instance Type (example: -i m1.small or -i m1.large)." 1>&2;exit 64;;
esac
# user-data validator
if[[ ! -f $userdata]]
thenecho"The user-data file \"$userdata\" does not exist. You must specify a valid user-data file (example: -u /path/to/user-data.txt)." 1>&2;exit64
fi
# storage validator
case$storage in
ebs|EBS)storage=EBS;;
s3|S3)storage=S3;;
"")storage=EBS ;;# if no storage type is set - default to EBS
*)echo"The \"$storage\" storage type does not exist. You must specify a valid storage type (either: -s ebs or -s s3)." 1>&2;exit 64;;
echo"A new Launch Configuration named \"$launchconfig_new\" for Auto Scaling Group \"$asgroupname\" will be created using EC2 Instance Type \"$instancetype\" and AMI \"$imageid.\""