File submit-ip.sh of Package submit-ip

#!/bin/sh
CONFIG="/etc/sysconfig/submit-ip"
OLDIPFILE=/var/tmp/myip
TEMPFILE=$(mktemp "/tmp/myip.XXXXXX") || exit 1
trap "rm -f $TEMPFILE" EXIT
DATE=$(date)

function cleanup_and_exit(){
	local EXITCODE="$1"
	test -f "$TEMPFILE" && rm "$TEMPFILE"
	exit $EXITCODE
}

function submit_ip_via_ssh(){
	IP=$(cat "$TEMPFILE")
	ssh -p$REMOTEPORT -i "$REMOTEKEY" $REMOTEUSER@$REMOTEHOST "$IP $SYSTEMNAME"
	echo "$DATE [$SYSTEMNAME] : IP $IP submitted via ssh -p$REMOTEPORT -i "$REMOTEKEY" $REMOTEUSER@$REMOTEHOST" >> $LOGFILE
}

function submit_ip_via_ddclient(){
	/usr/sbin/ddclient -daemon=0 -syslog -use=ip -ip=$(cat "$TEMPFILE")
}

if [ -r "$CONFIG" ]; then
	. "$CONFIG"
else
	echo "Could not read $CONFIG - exiting" >&2
	cleanup_and_exit 1
fi

wget --quiet $WHATSMYIPURL --output-document="$TEMPFILE"

if test -r "$OLDIPFILE"; then 
	if ! grep -q $(cat "$TEMPFILE") "$OLDIPFILE"; then
		submit_ip_via_ssh
	fi
else
	submit_ip_via_ssh
fi
if [ "$1" == "-f" ]; then
	submit_ip_via_ssh
fi
mv -f "$TEMPFILE" "$OLDIPFILE"
cleanup_and_exit "0"

openSUSE Build Service is sponsored by