Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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