Add possibility to enable IPv4 or IPv6 check in dynv6
This commit is contained in:
parent
dfea4a8bb9
commit
f535a2f3d8
2 changed files with 55 additions and 32 deletions
|
@ -16,6 +16,8 @@ The following are at least required for the script to work:
|
||||||
- DYNV6_MAIL_ADDRESS="" // (optional) mail.rc has to be configured
|
- DYNV6_MAIL_ADDRESS="" // (optional) mail.rc has to be configured
|
||||||
- DYNV6_TOKEN="" // the dynv6 token
|
- DYNV6_TOKEN="" // the dynv6 token
|
||||||
- DYNV6_HOSTNAME="" // the dynv6 hostname
|
- DYNV6_HOSTNAME="" // the dynv6 hostname
|
||||||
|
- DYNV6_IPV4_ENABLED=true // if should update ipv4
|
||||||
|
- DYNV6_IPV6_ENABLED=true // if should update ipv6
|
||||||
|
|
||||||
You can copy this script to '/usr/local/bin' and use create a custom CONFIG_FILE as user. Examples can be found in '/usr/share/doc/<scriptname>'.
|
You can copy this script to '/usr/local/bin' and use create a custom CONFIG_FILE as user. Examples can be found in '/usr/share/doc/<scriptname>'.
|
||||||
EOF
|
EOF
|
||||||
|
@ -45,17 +47,32 @@ source_config() {
|
||||||
}
|
}
|
||||||
|
|
||||||
apply_defaults() {
|
apply_defaults() {
|
||||||
[[ -z ${DYNV6_MAIL_ENABLED} ]] && DYNV6_MAIL_ENABLED=false;
|
if [ -z ${DYNV6_MAIL_ENABLED} ]; then
|
||||||
[[ -z ${DYNV6_MAIL_ADDRESS} ]] && DYNV6_MAIL_ADDRESS="";
|
DYNV6_MAIL_ENABLED=false;
|
||||||
[[ -z ${DYNV6_TOKEN} ]] && DYNV6_TOKEN="";
|
fi
|
||||||
[[ -z ${DYNV6_HOSTNAME} ]] && DYNV6_HOSTNAME="";
|
if [ -z ${DYNV6_MAIL_ADDRESS} ]; then
|
||||||
|
DYNV6_MAIL_ADDRESS="";
|
||||||
|
fi
|
||||||
|
if [ -z ${DYNV6_TOKEN} ]; then
|
||||||
|
DYNV6_TOKEN="";
|
||||||
|
fi
|
||||||
|
if [ -z ${DYNV6_HOSTNAME} ]; then
|
||||||
|
DYNV6_HOSTNAME="";
|
||||||
|
fi
|
||||||
|
if [ -z ${DYNV6_IPV4_ENABLED} ]; then
|
||||||
|
DYNV6_IPV4_ENABLED=true;
|
||||||
|
fi
|
||||||
|
if [ -z ${DYNV6_IPV6_ENABLED} ]; then
|
||||||
|
DYNV6_IPV6_ENABLED=true;
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
check_required() {
|
check_required() {
|
||||||
if [[ -z ${DYNV6_TOKEN} ]]; then
|
if [ -z ${DYNV6_TOKEN} ]; then
|
||||||
echo "DYNV6_TOKEN is required"
|
echo "DYNV6_TOKEN is required"
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
if [[ -z ${DYNV6_HOSTNAME} ]]; then
|
if [ -z ${DYNV6_HOSTNAME} ]; then
|
||||||
echo "DYNV6_HOSTNAME is required"
|
echo "DYNV6_HOSTNAME is required"
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
|
@ -65,8 +82,8 @@ check_required() {
|
||||||
CONFIG_FILE="$1";
|
CONFIG_FILE="$1";
|
||||||
FALLBACK_CONFIG_FILE="${HOME}/.dynv6.conf";
|
FALLBACK_CONFIG_FILE="${HOME}/.dynv6.conf";
|
||||||
source_config "${CONFIG_FILE}" "${FALLBACK_CONFIG_FILE}";
|
source_config "${CONFIG_FILE}" "${FALLBACK_CONFIG_FILE}";
|
||||||
#apply_defaults;
|
apply_defaults;
|
||||||
#check_required;
|
check_required;
|
||||||
|
|
||||||
# DO NOT CHANGE
|
# DO NOT CHANGE
|
||||||
token=${DYNV6_TOKEN}
|
token=${DYNV6_TOKEN}
|
||||||
|
@ -76,34 +93,38 @@ echo "Checking ${hostname}"
|
||||||
|
|
||||||
# check via service
|
# check via service
|
||||||
# ipv6
|
# ipv6
|
||||||
echo "Testing IPv6";
|
if [ "${DYNV6_IPV6_ENABLED}" = "true" ]; then
|
||||||
ipv6Res=$(curl -fsS "http://dynv6.com/api/update?hostname=${hostname}&token=${token}")
|
echo "Testing IPv6";
|
||||||
ipv6Changed=true;
|
ipv6Res=$(curl -fsS "http://dynv6.com/api/update?hostname=${hostname}&token=${token}")
|
||||||
|
ipv6Changed=true;
|
||||||
|
|
||||||
if [ "$ipv6Res" = "addresses unchanged" ]; then
|
if [ "${ipv6Res}" = "addresses unchanged" ]; then
|
||||||
ipv6Changed=false;
|
ipv6Changed=false;
|
||||||
fi
|
fi
|
||||||
if [ "$ipv6Changed" = "true" ]; then
|
if [ "${ipv6Changed}" = "true" ]; then
|
||||||
echo "IPv6 changed"
|
echo "IPv6 changed"
|
||||||
|
|
||||||
if [ "${DYNV6_MAIL_ENABLED}" = true ]; then
|
if [ "${DYNV6_MAIL_ENABLED}" = "true" ]; then
|
||||||
HOSTMACHINE=$(hostname)
|
HOSTMACHINE=$(hostname)
|
||||||
echo -e "IPv6 for ${hostname} on host ${HOSTMACHINE} changed" | mailx -s "[dynv6 IPv6 ${HOSTMACHINE}] IPv6 changed for ${hostname}" "${DYNV6_MAIL_ADDRESS}"
|
echo -e "IPv6 for ${hostname} on host ${HOSTMACHINE} changed" | mailx -s "[dynv6 IPv6 ${HOSTMACHINE}] IPv6 changed for ${hostname}" "${DYNV6_MAIL_ADDRESS}"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ipv4
|
# ipv4
|
||||||
echo "Testing IPv4";
|
if [ "${DYNV6_IPV4_ENABLED}" = "true" ]; then
|
||||||
ipv4Res=$(curl -fsS "http://ipv4.dynv6.com/api/update?hostname=${hostname}&ipv4=auto&token=${token}")
|
echo "Testing IPv4";
|
||||||
ipv4Changed=true;
|
ipv4Res=$(curl -fsS "http://ipv4.dynv6.com/api/update?hostname=${hostname}&ipv4=auto&token=${token}")
|
||||||
if [ "$ipv4Res" = "addresses unchanged" ]; then
|
ipv4Changed=true;
|
||||||
|
if [ "$ipv4Res" = "addresses unchanged" ]; then
|
||||||
ipv4Changed=false;
|
ipv4Changed=false;
|
||||||
fi
|
fi
|
||||||
if [ "$ipv4Changed" = "true" ]; then
|
if [ "${ipv4Changed}" = "true" ]; then
|
||||||
echo "IPv4 changed"
|
echo "IPv4 changed"
|
||||||
|
|
||||||
if [ "${DYNV6_MAIL_ENABLED}" = true ]; then
|
if [ "${DYNV6_MAIL_ENABLED}" = "true" ]; then
|
||||||
HOSTMACHINE=$(hostname)
|
HOSTMACHINE=$(hostname)
|
||||||
echo -e "IPv4 for ${hostname} on host ${HOSTMACHINE} changed" | mailx -s "[dynv6 IPv4 ${HOSTMACHINE}] IPv4 changed for ${hostname}" "${DYNV6_MAIL_ADDRESS}"
|
echo -e "IPv4 for ${hostname} on host ${HOSTMACHINE} changed" | mailx -s "[dynv6 IPv4 ${HOSTMACHINE}] IPv4 changed for ${hostname}" "${DYNV6_MAIL_ADDRESS}"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
fi
|
fi
|
|
@ -1,5 +1,7 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
DYNV6_MAIL_ENABLED= // if notify via mail
|
DYNV6_MAIL_ENABLED="false" // if notify via mail
|
||||||
DYNV6_MAIL_ADDRESS="" // (optional) mail.rc has to be configured
|
DYNV6_MAIL_ADDRESS="" // (optional) mail.rc has to be configured
|
||||||
DYNV6_TOKEN="" // the dynv6 token
|
DYNV6_TOKEN="" // the dynv6 token
|
||||||
DYNV6_HOSTNAME="" // the dynv6 hostname
|
DYNV6_HOSTNAME="" // the dynv6 hostname
|
||||||
|
DYNV6_IPV4_ENABLED=true // if should update ipv4
|
||||||
|
DYNV6_IPV6_ENABLED=true // if should update ipv6
|
Loading…
Reference in a new issue