Skip to content

Instantly share code, notes, and snippets.

@frennkie
Created July 3, 2020 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frennkie/a52d1eddfad03d3cda94d49fdd364e16 to your computer and use it in GitHub Desktop.
Save frennkie/a52d1eddfad03d3cda94d49fdd364e16 to your computer and use it in GitHub Desktop.
#!/bin/bash
# store values from environment
env_IP2TOR_SHOP_URL=${IP2TOR_SHOP_URL-notset}
env_IP2TOR_HOST_ID=${IP2TOR_HOST_ID-notset}
env_IP2TOR_HOST_TOKEN=${IP2TOR_HOST_TOKEN-notset}
# if config file exists use it (but vars set from environment overwrite file vars)
if [ -f /etc/ip2tor.conf ]; then
unset IP2TOR_SHOP_URL
unset IP2TOR_HOST_ID
unset IP2TOR_HOST_TOKEN
source /etc/ip2tor.conf
if [ -n "${env_IP2TOR_SHOP_URL}" ]; then
IP2TOR_SHOP_URL=${env_IP2TOR_SHOP_URL}
fi
if [ -n "${env_IP2TOR_HOST_ID}" ]; then
IP2TOR_HOST_ID=${env_IP2TOR_HOST_ID}
fi
if [ -n "${env_IP2TOR_HOST_TOKEN}" ]; then
IP2TOR_HOST_TOKEN=${env_IP2TOR_HOST_TOKEN}
fi
fi
if [ "${IP2TOR_SHOP_URL}" = "notset" ] && [ "${IP2TOR_HOST_ID}" = "notset" ] && [ "${IP2TOR_HOST_TOKEN}" = "notset" ]; then
echo "Error: IP2TOR_SHOP_URL, IP2TOR_HOST_ID and IP2TOR_HOST_TOKEN must be set via environment or config file!"
exit 1
fi
if [ -z "${IP2TOR_SHOP_URL}" ] && [ -z "${IP2TOR_HOST_ID}" ] && [ -z "${IP2TOR_HOST_TOKEN}" ]; then
echo "Error: IP2TOR_SHOP_URL, IP2TOR_HOST_ID and IP2TOR_HOST_TOKEN must be set via environment or config file!"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment