#!/bin/zsh -e
# PUMP Script
# $1 Calling circumstance (up, renewal, down)
# $2 interface
# $3 ip

# Exit early, if we're not being called for the initial lease
[ "$1" != "up" ] && exit 0

. /etc/grml/autoconfig.functions

# only run if no nodhcphostname parameter is given
# and if running in live mode
if ! checkbootparam 'nodhcphostname' && [ -f /etc/grml_cd ] ; then

    hostname=$(busybox nslookup "$3" | awk '/Address 1: '$3'/ {print $4}')
    [ -n "$hostname" ] || exit 1

    grml-hostname "$hostname"
    hostname -F /etc/hostname
fi
