Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Freedns init script
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
drbrain9k
n00b
n00b


Joined: 05 Jun 2006
Posts: 1

PostPosted: Mon Jun 05, 2006 1:17 am    Post subject: Freedns init script Reply with quote

I just finished writing a freedns dynamic ip init script and figured I would share it. I would really love coding style comments, as it's my first script.

The idea is that my IPs only really change when I physically move my box. So I only need to check and update at boot time. If you want to check all the time, there are plenty of good cron scripts at http://freedns.afraid.org/scripts/freedns.clients.php that will suit.

The only thing you need to change is $UPDATE_URL in the /etc/conf.d/freedns file, and then use a simple rc-update to install it.

Here is the /etc/init.d/freedns file:

Code:
#!/sbin/runscript
# Copyright 2006 Jeffrey Nichols

depend() {
        need net
        use dns logger
}

checkconfig() {
        if [ -z "${CHECK_CMD}" ] ; then
                eerror "Please edit /etc/conf.d/freedns"
                eerror "I need to know how to check for IP!"
                return 1
        fi
        if [ -z "${OLDIP_FILE}" ] ; then
                eerror "Please edit /etc/conf.d/freedns"
                eerror "I need to know where to store the IP file!"
                return 1
        fi
        if [ -z "${UPDATE_COMMAND}" ] ; then
                eerror "Please edit /etc/conf.d/freedns"
                eerror "I need to know how to update the IP!"
                return 1
        fi
        return 0
}

start() {
        checkconfig || return $?

        ebegin "Getting current IP"
        CURRENTIP=`${CHECK_CMD}`
        echo "Found ${CURRENTIP}"

        if [ ! -e "${OLDIP_FILE}" ] ; then
                echo "Creating ${OLDIP_FILE}"
                echo "0.0.0.0" > "${OLDIP_FILE}"
        fi

        OLDIP=`cat ${OLDIP_FILE}`
        eend $? "Error reading old ip"

        if [ "${CURRENTIP}" != "${OLDIP}" ] ; then
                ebegin "Issuing update command"
                ${UPDATE_COMMAND}
                eend $? "Update failed"
        fi

        ebegin "Saving IP"
        echo "${CURRENTIP}" > "${OLDIP_FILE}"
        eend $? "Save failed"
}


and here is the /etc/conf.d/freedns file:

Code:
# /etc/conf.d/freedns

# Command to find the current IP on the system.
CHECK_CMD="/usr/bin/curl -s http://ip.dnsexit.com/ | sed -e 's/ //'"

# Where to store the file containing the old IP
# for comparison on the next run.
OLDIP_FILE="/var/lib/misc/oldip"

# The command to run when the IP is different.
UPDATE_URL="http://freedns.afraid.org/dynamic/update.php?" <--edit this line to the url from http://freedns.afraid.org/dynamic/index.php
UPDATE_COMMAND="/usr/bin/curl -s $UPDATE_URL"


Credit: I used the dynIP.sh file from http://freedns.afraid.org/forums/viewtopic.php?p=4161 for the idea and the ntp-client init files as a very loose template.
Back to top
View user's profile Send private message
disi
Veteran
Veteran


Joined: 28 Nov 2003
Posts: 1354
Location: Out There ...

PostPosted: Wed Feb 11, 2009 3:04 pm    Post subject: Reply with quote

That is what I use as a cron job on my system (copied a lot of yours :) )

Code:
#! /bin/bash
# this script updates the dynamic ip on http://freedns.afraid.org/ using curl
# check http://freedns.afraid.org/api/ and as weapon ASCII for the phrase in UPDATE_URL
OLDIP_FILE="/var/lib/misc/oldip"
CHECK_CMD="/usr/bin/curl -s http://ip.dnsexit.com/ | sed -e 's/ //'"
UPDATE_URL="http://freedns.afraid.org/dynamic/update.php?<blablubbblablablablubbphrasesumber>"
UPDATE_COMMAND="/usr/bin/curl -s $UPDATE_URL"

echo "Getting current IP"
CURRENTIP=`${CHECK_CMD}`
echo "Found ${CURRENTIP}"

if [ ! -e "${OLDIP_FILE}" ] ; then
echo "Creating ${OLDIP_FILE}"
echo "0.0.0.0" > "${OLDIP_FILE}"
fi

OLDIP=`cat ${OLDIP_FILE}`

if [ "${CURRENTIP}" != "${OLDIP}" ] ; then
echo "Issuing update command"
${UPDATE_COMMAND}
fi

echo "Saving IP"
echo "${CURRENTIP}" > "${OLDIP_FILE}"
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum