#!/bin/bash ########## # File: pump.script # Author: Cody Casterline # # This script makes pump run the dhcpcd-.exe script when # the DHCP-assigned IP changes. # # Note: You'll need a line like this in your pump.conf file: # script /full/path/to/pump.script ########## # Set SCRIPTDIR to the location of your dhcpcd-.exe scripts. SCRIPTDIR="/etc/dhcpc"; # Arguments passed by pump: # arg1 = up/renewal/down ACTION=$1; # arg2 = device (ex: eth0) DEVICE=$2; # arg3 = IP address IPADDR=$3; # IPs only change when the DHCP lease is brought up or renewed. if [[ ($ACTION != "up") && ($ACTION != "renewal") ]]; then { exit; } fi; # Also, make sure there's a script to run: scriptname="$SCRIPTDIR/dhcpcd-$DEVICE.exe"; if [[ !(-x $scriptname) ]]; then exit; fi; # Make sure the IP has actually changed: cachefile="$SCRIPTDIR/pump.$DEVICE.lastip"; if [[ -e $cachefile ]]; then OLDIP=`cat $cachefile`; if [[ $OLDIP == $IPADDR ]]; then exit; fi; # IP hasn't changed, exit. fi; # Ok, we know now the IP has changed, and our script exists. # Let's update our cache, and call the script! echo -n $IPADDR > $cachefile; exec $scriptname