set -e : Exit immediately if a command exits with a non-zero status
set -u : Treat unset variables as an error when substituting
set -o pipefail : Normally, pipelines only return a failure if the last command errors. In combination with set -e, this will make your script exit if any command in a pipeline errors.