for prerequisite in basename cut date ec2-create-snapshot ec2-create-tags ec2-delete-snapshot ec2-describe-snapshots;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]];then#has exits with exit status of 70, executable was not found
echo"In order to use $app_name, the executable \"$prerequisite\" must be installed." 1>&2;exit70
echo"The selection method \"volumeid\" (which is $app_name's default selection_method of operation or requested by using the -s volumeid parameter) requires a volumeid (-v volumeid) for operation. Correct usage is as follows: \"-v vol-6d6a0527\",\"-s volumeid -v vol-6d6a0527\" or \"-v \"vol-6d6a0527 vol-636a0112\"\" if multiple volumes are to be selected." 1>&2;exit64
fi
ebs_selection_string="$volumeid"
;;
tag)
if[[ -z $tag]];then
echo"The selected selection_method \"tag\" (-s tag) requires a valid tag (-t key=value) for operation. Correct usage is as follows: \"-s tag -t backup=true\" or \"-s tag -t Name=my_tag.\"" 1>&2;exit64
fi
ebs_selection_string="--filter tag:$tag"
;;
*)echo"If you specify a selection_method (-s selection_method) for selecting EBS volumes you must select either \"volumeid\" (-s volumeid) or \"tag\" (-s tag)." 1>&2;exit64;;
esac
#creates a list of all ebs volumes that match the selection string from above
#if purge_after_date is not set then we have a problem. Need to alert user.
if[[ -z $purge_after_fe]];then
#Alerts user to the fact that a Snapshot was found with PurgeAllow=true but with no PurgeAfterFE date.
echo"Snapshot with the Snapshot ID \"$snapshot_id_evaluated\" has the tag \"PurgeAllow=true\" but does not have a \"PurgeAfterFE=xxxxxxxxxx\" key/value pair. $app_name is unable to determine if $snapshot_id_evaluated should be purged." 1>&2
else
# if $purge_after_fe is less than $current_date then
# PurgeAfterFE is earlier than the current date
# and the snapshot can be safely purged
if[[$purge_after_fe < $current_date]];then
echo"Snapshot \"$snapshot_id_evaluated\" with the PurgeAfterFE date of \"$purge_after_fe\" will be deleted."
#date_binary allows a user to set the "date" binary that is installed on their system and, therefore, the options that will be given to the date binary to perform date calculations
#sets the user_tags feature to false - user_tag creates tags on snapshots - by default each snapshot is tagged with volume_id and current_date timestamp
*)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;;
#sources "cron_primer" file for running under cron or other restricted environments - this file should contain the variables and environment configuration required for ec2-automate-backup to run correctly
#if the date_binary is not set, call the get_date_binary function
if[[ -z $date_binary]];then
get_date_binary
fi
purge_after_date_fe=$(get_purge_after_date_fe)
echo"Snapshots taken by $app_name will be eligible for purging after the following date (the purge after date given in seconds from epoch): $purge_after_date_fe."
#get_EBS_List gets a list of EBS instances for which a snapshot is desired. The list of EBS instances depends upon the selection_method that is provided by user input