Update check_dyndns.sh.
This commit is contained in:
parent
84c2c5582b
commit
ee95ca3899
184
check_dyndns.sh
184
check_dyndns.sh
@ -1,8 +1,25 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
|
||||||
|
|
||||||
function usage() {
|
#---------------------------------------
|
||||||
|
#-----------------------------
|
||||||
|
# Predifined Variables
|
||||||
|
#-----------------------------
|
||||||
|
#---------------------------------------
|
||||||
|
|
||||||
|
conf_file="/etc/ddclient.conf"
|
||||||
|
ddclient_script="/usr/sbin/ddclient"
|
||||||
|
|
||||||
|
_SKIP_IP=false
|
||||||
|
|
||||||
|
|
||||||
|
#---------------------------------------
|
||||||
|
#-----------------------------
|
||||||
|
# Functions
|
||||||
|
#-----------------------------
|
||||||
|
#---------------------------------------
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
|
||||||
echo
|
echo
|
||||||
|
|
||||||
@ -15,93 +32,136 @@ function usage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fatal(){
|
||||||
|
echo ""
|
||||||
|
echo -e " [ Fatal ] $*"
|
||||||
|
echo ""
|
||||||
|
echo -e "\tScript terminated.."
|
||||||
|
echo ""
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
info (){
|
||||||
|
echo ""
|
||||||
|
echo -e " [ Info ] $*"
|
||||||
|
echo ""
|
||||||
|
}
|
||||||
|
|
||||||
|
ok (){
|
||||||
|
echo ""
|
||||||
|
echo -e " [ Ok ] $*"
|
||||||
|
echo ""
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#---------------------------------------
|
||||||
|
#-----------------------------
|
||||||
|
# Evaluate command line
|
||||||
|
#-----------------------------
|
||||||
|
#---------------------------------------
|
||||||
|
|
||||||
[ $# -eq "0" -o $# -gt "2" ] && usage "wrong number of arguments"
|
[ $# -eq "0" -o $# -gt "2" ] && usage "wrong number of arguments"
|
||||||
|
|
||||||
DYNDNS_NAME=$1
|
DYNDNS_NAME=$1
|
||||||
|
|
||||||
_SKIP_IP=false
|
|
||||||
|
|
||||||
|
#---------------------------------------
|
||||||
|
#-----------------------------
|
||||||
|
# Some checks
|
||||||
|
#-----------------------------
|
||||||
|
#---------------------------------------
|
||||||
|
|
||||||
|
# - Only run ddclient, if it is installed
|
||||||
|
# -
|
||||||
## - only run ddclient, if it is installed
|
if [[ ! -x "$ddclient_script" ]]; then
|
||||||
## -
|
fatal "Script '${ddclient_script}' not found!"
|
||||||
if [ ! -x "/usr/sbin/ddclient" ]; then
|
|
||||||
exit 0
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# - Configuration present?
|
||||||
|
# -
|
||||||
|
if [[ ! -f "$conf_file" ]]; then
|
||||||
|
fatal "ddclient Configuration '${conf_file}' not found!"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -f "/etc/ddclient.conf" ]; then
|
# - Running on a terminal?
|
||||||
|
# -
|
||||||
## - read variable "if" from configurationd file "/etc/ddclient.conf"
|
if [[ -t 1 ]] ; then
|
||||||
## -
|
LOGGING=true
|
||||||
eval `sed -n 's/\(if=[^ ,]*\)/\1/p' /etc/ddclient.conf`
|
|
||||||
|
|
||||||
## - check if interface used by dyndns is present
|
|
||||||
##
|
|
||||||
if [ -n "$if" ];then
|
|
||||||
for _IFACE in `ifconfig | grep -e"^ppp" | cut -d" " -f1 `; do
|
|
||||||
if [ "$_IFACE" = $if ];then
|
|
||||||
PPP_IFACE=$_IFACE
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
## - exit if no connection for dydns interface exists
|
|
||||||
## -
|
|
||||||
if [ "X" = "X$PPP_IFACE" ]; then
|
|
||||||
echo "No interface for dydns exists. exiting now.."
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
else
|
|
||||||
_SKIP_IP=true
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
## - No configuration file found, so do not run
|
LOGGING=false
|
||||||
## -
|
|
||||||
echo "No configuration file \"/etc/ddclient.conf\" found, so do not run"
|
|
||||||
exit 0
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# - Check, if ddclient uses a local interface (variable "if")
|
||||||
|
# -
|
||||||
|
# - if true, interface name will be stored into variable 'if'
|
||||||
|
# -
|
||||||
|
eval `sed -n 's/\(if=[^ ,]*\)/\1/p' /etc/ddclient.conf`
|
||||||
|
|
||||||
|
# - Check if interface used by dyndns is present
|
||||||
|
#
|
||||||
|
if [ -n "$if" ];then
|
||||||
|
for _IFACE in `ifconfig | grep -e"^ppp" | cut -d" " -f1 `; do
|
||||||
|
if [ "$_IFACE" = $if ];then
|
||||||
|
PPP_IFACE=$_IFACE
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
## - exit if no connection for dydns interface exists
|
||||||
|
## -
|
||||||
|
if [ "X" = "X$PPP_IFACE" ]; then
|
||||||
|
fatal "No interface for dydns exists."
|
||||||
|
fi
|
||||||
|
|
||||||
|
else
|
||||||
|
_SKIP_IP=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
#---------------------------------------
|
||||||
|
#-----------------------------
|
||||||
|
# Update DynDNS IP-Address if needed
|
||||||
|
#-----------------------------
|
||||||
|
#---------------------------------------
|
||||||
|
|
||||||
if ! $_SKIP_IP ; then
|
if ! $_SKIP_IP ; then
|
||||||
|
|
||||||
PPP_REMOTE=`ifconfig $PPP_IFACE 2>/dev/null | grep -e "P-[tz]-P" | cut -d":" -f3 | cut -d " " -f1`
|
PPP_REMOTE=`ifconfig $PPP_IFACE 2>/dev/null | grep -e "P-[tz]-P" | cut -d":" -f3 | cut -d " " -f1`
|
||||||
PPP_LOCAL=`ifconfig $PPP_IFACE 2>/dev/null | grep -e "P-[tz]-P" | cut -d":" -f2 | cut -d " " -f1`
|
PPP_LOCAL=`ifconfig $PPP_IFACE 2>/dev/null | grep -e "P-[tz]-P" | cut -d":" -f2 | cut -d " " -f1`
|
||||||
fi
|
|
||||||
|
|
||||||
|
if [ "X$PPP_REMOTE" != "X" -a "X$PPP_LOCAL" != "X" ] ; then
|
||||||
if [ "X$PPP_REMOTE" != "X" -a "X$PPP_LOCAL" != "X" ] ; then
|
|
||||||
|
|
||||||
if $_SKIP_IP ; then
|
|
||||||
|
|
||||||
# Load defaults
|
|
||||||
if [ -f /etc/default/ddclient ]; then
|
|
||||||
|
|
||||||
source /etc/default/ddclient
|
|
||||||
if [ "$run_daemon" = "true" ]; then
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
/usr/sbin/ddclient
|
|
||||||
|
|
||||||
else
|
|
||||||
|
|
||||||
DYNDNS_IP=`dig $DYNDNS_NAME +short`
|
DYNDNS_IP=`dig $DYNDNS_NAME +short`
|
||||||
#echo "$DYNDNS_NAME: $DYNDNS_IP - Local (PPP) IP: $PPP_LOCAL"
|
|
||||||
|
|
||||||
if [ "$DYNDNS_IP" != "$PPP_LOCAL" ] ; then
|
if [ "$DYNDNS_IP" != "$PPP_LOCAL" ] ; then
|
||||||
|
|
||||||
## - Run ddclient with the IP address of the ppp device
|
# - Run ddclient with the IP address of the ppp device
|
||||||
## -
|
# -
|
||||||
echo "try to update ipadress entry at dyndns.org.."
|
info "Try to update ip-adress entry at dyndns.org.."
|
||||||
echo
|
|
||||||
/usr/sbin/ddclient -syslog -ip $PPP_LOCAL
|
/usr/sbin/ddclient -syslog -ip $PPP_LOCAL
|
||||||
|
else
|
||||||
|
if $LOGGING ; then
|
||||||
|
ok "DynDNS IP is up-to-date"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
# - Load defaults
|
||||||
|
source /etc/default/ddclient
|
||||||
|
if [ "$run_daemon" = "true" ]; then
|
||||||
|
if $LOGGING ; then
|
||||||
|
info "'ddclient' is configured to run as daemon. So nothing to do here."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if $LOGGING ; then
|
||||||
|
info "Going to run '${ddclient_script}'.."
|
||||||
|
fi
|
||||||
|
/usr/sbin/ddclient -file $conf_file
|
||||||
|
fi
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
exit 0;
|
exit 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user