summaryrefslogtreecommitdiffstats
path: root/setup-alpine.in
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2009-09-15 08:57:32 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2009-09-15 12:10:28 +0000
commitd1f2db71733268da8097db02326e7f5332671f86 (patch)
tree2e03d6fc812a101013ab6b3b684a75ea8a24d932 /setup-alpine.in
parentae716bd9e01e3e3f5322ddb2a7d90c8ff9b8c5fc (diff)
downloadalpine-conf-d1f2db71733268da8097db02326e7f5332671f86.tar.bz2
alpine-conf-d1f2db71733268da8097db02326e7f5332671f86.tar.xz
setup-alpine: add the hostname to /etc/hosts
Diffstat (limited to 'setup-alpine.in')
-rw-r--r--setup-alpine.in23
1 files changed, 23 insertions, 0 deletions
diff --git a/setup-alpine.in b/setup-alpine.in
index 3472f53..712a950 100644
--- a/setup-alpine.in
+++ b/setup-alpine.in
@@ -6,6 +6,16 @@ VERSION=@VERSION@
PREFIX=
. $PREFIX/lib/libalpine.sh
+# Extract fully qualified domain name from current hostname. If none is
+# currently set, use 'my.domain'.
+get_fqdn() {
+ local _dn
+ _dn=$(hostname -f 2>/dev/null)
+ _dn=${_dn#$(hostname -s 2>/dev/null)}
+ _dn=${_dn#.}
+ echo "${_dn:=my.domain}"
+}
+
while getopts "ah" opt ; do
case $opt in
a) ARCHIVE=yes;;
@@ -42,3 +52,16 @@ rc-update -q add networking boot
rc boot
rc default
+# update /etc/hosts - after we have got dhcp address
+# Get default fully qualified domain name from *first* domain
+# given on *last* search or domain statement.
+_dn=$(sed -n \
+-e '/^domain[[:space:]][[:space:]]*/{s///;s/\([^[:space:]]*\).*$/\1/;h;}' \
+-e '/^search[[:space:]][[:space:]]*/{s///;s/\([^[:space:]]*\).*$/\1/;h;}' \
+-e '${g;p;}' /etc/resolv.conf 2>/dev/null)
+
+_hn=$(hostname)
+_hn=${_hn%%.*}
+
+sed -i -e "s/^127\.0\.0\.1.*/127.0.0.1\t${_hn}.${_dn:-$(get_fqdn)} ${_hn} localhost.localdomain localhost/" /etc/hosts
+