Reworked and grmlfied patch from Andreas Thienemann
[grml-autoconfig.git] / etc / grml / pump-scripts.d / set-hostname
1 #!/bin/zsh -e
2 # PUMP Script
3 # $1 Calling circumstance (up, renewal, down)
4 # $2 interface
5 # $3 ip
6
7 # Exit early, if we're not being called for the initial lease
8 [ "$1" != "up" ] && exit 0
9
10 . /etc/grml/autoconfig.functions
11
12
13 # only run if no nodhcphostname parameter is given
14 if ! checkbootparam 'nodhcphostname' ; then
15
16     hostname=$(host $3) || exit 1
17     # dhcphostname is set, get the PTR for the ip
18     hostname=$(echo ${hostname} | awk '{ print substr($5, 0, length($5)-1) }')
19
20     if [ -n "$hostname" ] ; then
21         echo $hostname > /etc/hostname
22         hostname -F /etc/hostname
23     fi
24 fi