Toolbox
Here is where we can put little bash functions and other components that can be used to glue workflows together.
Generate a unique identifier based on provided input
#!/bin/bash
function make_ia_identifier {
# squish out everything that isn't alphanumeric, _, -, or .
IDENTIFIER=$(echo "$1" | tr -cd "[:alnum:]-_.");
# crop it to 64 characters
IDENTIFIER="${IDENTIFIER:0:64}";
# check IA for duplicate
STUBBY=0;
until check_ia_identifier "$IDENTIFIER"; do
IDENTIFIER="$IDENTIFIER$STUBBY";
STUBBY=$((STUBBY += 1));
sleep 1;
done;
return $IDENTIFIER
}
function check_ia_identifier {
ia metadata -e "$1"
if [ $? -ne 0 ]; then
return 0
fi
return 1
}
make_ia_identifier "$1"