Created
October 31, 2021 08:54
-
-
Save goffinet/12cc9af6999d975df8d94843e81ed6a7 to your computer and use it in GitHub Desktop.
Bash snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if environment variables are are set. | |
# https://stackoverflow.com/a/65396324 | |
varlist=" | |
MAIL_TO | |
MAIL_ADMIN | |
SCW_DEFAULT_PROJECT_ID | |
SCW_DEFAULT_ORGANIZATION_ID | |
SCW_DEFAULT_REGION | |
SCW_DEFAULT_ZONE | |
SCW_ACCESS_KEY | |
SCW_SECRET_KEY | |
SCW_URL | |
SG_KEY | |
SG_SENDER | |
CLOUDFLARE_API_EMAIL | |
CLOUDFLARE_API_TOKEN | |
CLOUDFLARE_ZONE | |
" | |
check_vars() { | |
var_names=("$@") | |
for var_name in "${var_names[@]}"; do | |
[ -z "${!var_name}" ] \ | |
&& echo "$var_name is unset." \ | |
&& var_unset=true | |
done | |
[ -n "$var_unset" ] && exit 1 | |
return 0 | |
} | |
check_vars $varlist | |
echo "You are good to go" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment