File: //usr/local/mailchannels/bin/lib/run_fatal.sh
#!/usr/bin/env bash
#run the given command and fail with an error message if it doesn't run successfully. The second parameter is the optional
#error message, but a default message is printed if the error message isn't provided
CMD=$1
if [[ -z ${CMD} ]]; then
echo "You must provide a command to run."
exit 1
fi
ERROR_MESSAGE=$2
if [[ -z ${ERROR_MESSAGE} ]]; then
ERROR_MESSAGE="Failed to run command ${CMD}, Aborting."
fi
${CMD}
if [[ $? != 0 ]]; then
echo ${ERROR_MESSAGE}
exit 1
fi