rendered paste body#!/bin/sh## Name: dyndnsup# Description: Auto-update dynamic dns service# Version: 1.0# Author: Jose V Beneyto, <joberui@eui.upv.es># Depends on: netcat# checkid:checkid() { user_id=`id -u` if [ "$user_id" != "0" ] then echo "you need to be root for running this script!" >&2 exit 1 fi}# checkdepends: check dependeciescheckdepends() { for dep in netcat do which $dep >& /dev/null if [ $? == 1 ] then echo "$dep not found, please install it!" >&2 exit 1 fi done}# readconfig:readconfig() { if [ -f $CONFIG_FILE ] then . $CONFIG_FILE [ "$DYNDNS_SERVER" == "" ] && {echo "DYNDNS_SERVER variable not set!" >&2; exit 1} [ "$DYNDNS_PROTOCOL" == "" ] && {echo "DYNDNS_PROTOCOL variable not set!" >&2; exit 1} [ "$DYNDNS_HOSTNAME" == "" ] && {echo "DYNDNS_HOSTNAME variable not set!" >&2; exit 1} [ "$DYNDNS_IF" == "" ] && {echo "DYNDNS_IF variable not set!" >&2; exit 1} fi}# chech time:checktime(){ if [ ! -f $CACHE_FILE ] then TIME_EXPIRED="yes" # force update else last_mod_date=`date +'%y%m%d' -r $CACHE_FILE` #last_mod_time=`date +'%H%M%S' -r $CACHE_FILE` current_date=`date +'%y%m%d'` #current_time=`date +'%H%M%S'` # check if timer has expired days_since_last_mod=`expr $current_date - $last_mod_date` if [ "$days_since_last_mod" -lt "$MAX_TIME" ] then TIME_EXPIRED="no" else TIME_EXPIRED="yes" fi fi}# checkip:checkip() { current_ip=`ifconfig $DYNDNS_IF | grep 'inet addr' | awk '{print $2}' | sed -e 's/.*://'` if [ ! -f $CACHE_FILE ] then echo "ip=$current_ip" > $CACHE_FILE last_ip="" # force update else last_ip=`cat $CACHE_FILE | grep 'ip' | sed 's/ip=//g'` fi if [ "$last_ip" == "$current_ip" ] then echo "can't update, ip not changed!" >&2 exit 1 else DYNDNS_IP=$current_ip fi}# update:update() { DYNDNS_IP=$1 echo -ne "GET /nic/update?system=$DYNDNS_PROTOCOL&hostname=$DYNDNS_HOSTNAME&myip=$DYNDNS_IP" | netcat -vv $SERVER_DYNDNS 80}# cache fileCACHE_FILE="/var/cache/dyndnsup.cache"# config file# (you can edit this file to overwrite script variables)CONFIG_FILE="/etc/dyndnsup.conf"# script variables# (CONFIG_FILE overwrite them)MAX_TIME="20" # (days)DYNDNS_SERVER="members.dyndns.org"DYNDNS_PROTOCOL="dyndns2"DYNDNS_HOSTNAME="mikeux.dyndns.org"DYNDNS_IP=""DYNDNS_IF="eth0"checkidcheckdependsreadconfigchecktimecheckip[ "$TIME_EXPIRED" == "yes" ] && echo "update!"#updateecho "DYNDNS_SERVER=$DYNDNS_SERVER"echo "DYNDNS_PROTOCOL=$DYNDNS_PROTOCOL"echo "DYNDNS_HOSTNAME=$DYNDNS_HOSTNAME"echo "DYNDNS_IP=$DYNDNS_IP"echo "DYNDNS_IF=$DYNDNS_IF"echo ""exit 0# End of File