f4b46d125fffbec50a5e63d07b522f5d0abb19fa
[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 # only run if no nodhcphostname parameter is given
13 # and if running in live mode
14 if ! checkbootparam 'nodhcphostname' && [ -f /etc/grml_cd ] ; 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         grml-hostname $hostname
22         hostname -F /etc/hostname
23     fi
24 fi