Try to lookup for hostname if the var is empty

This commit is contained in:
Jeremy Gardais 2019-06-30 14:55:57 +02:00
parent 189a1ff13a
commit 3468bce210
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 10 additions and 2 deletions

12
debian/chroot.install vendored
View File

@ -9,7 +9,8 @@ else
exit 0
fi
## Computer hostname
new_hostname="ks10"
## If empty, the script will try to get one with nslookup
new_hostname=""
## Volume Group name to use for LVM
vgname="ovhsys"
## If the script should manage the partitions (delete, add,…)
@ -227,7 +228,14 @@ chroot /target update-grub
## }}}
## Hostname {{{
printf '%b\n' "${new_hostname}" > /target/etc/hostname
if [ -z "${new_hostname}" ]; then
lookup_hostname=$(nslookup "${net_address}" || echo "server name = new_server")
get_hostname=$(echo "${lookup_hostname}" | awk '/name =/{print $4;}' | cut -d. -f1)
printf '%b\n' "${get_hostname}" > /target/etc/hostname
else
printf '%b\n' "${new_hostname}" > /target/etc/hostname
fi
#printf '%b\n' "127.0.0.1 ${new_hostname}" >> /target/etc/hosts
## }}}