Merge remote-tracking branch 'origin/github/pr/148'
[grml-live.git] / etc / grml / fai / config / scripts / GRMLBASE / 05-hostname
index 0b0fe17..cf55d8d 100755 (executable)
@@ -1,5 +1,5 @@
-#!/bin/sh
-# Filename:      /etc/grml/fai/config/scripts/GRMLBASE/05-hostname
+#!/bin/bash
+# Filename:      ${GRML_FAI_CONFIG}/config/scripts/GRMLBASE/05-hostname
 # Purpose:       set hostname of live-system
 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
 # Bug-Reports:   see http://grml.org/bugs/
@@ -9,11 +9,14 @@
 set -u
 set -e
 
-HOSTNAME=''
-[ -r /etc/grml/grml-live.conf ]  && . /etc/grml/grml-live.conf
-[ -r /etc/grml/grml-live.local ] && . /etc/grml/grml-live.local
-[ -n "$HOSTNAME" ] || HOSTNAME=grml
+. "$GRML_LIVE_CONFIG"
+
+# the hostname of the chroot usually isn't the same as the one for the live-system
+BUILD_HOSTNAME="$($ROOTCMD hostname)"
+[ -n "$BUILD_HOSTNAME" ] || BUILD_HOSTNAME="grml"
+
 echo "$HOSTNAME" > $target/etc/hostname
+echo "$HOSTNAME" > $target/etc/mailname
 
 if [ -r $target/etc/postfix/main.cf ] ; then
   sed -i "s/^mydestination = .*/mydestination = $HOSTNAME, localhost, localhost.localdomain/" $target/etc/postfix/main.cf
@@ -21,7 +24,10 @@ if [ -r $target/etc/postfix/main.cf ] ; then
   echo "postfix postfix/mailname     string $HOSTNAME" | $ROOTCMD debconf-set-selections
   echo "postfix postfix/destinations string ${HOSTNAME}, localhost.grml.org, localhost" \
   | $ROOTCMD debconf-set-selections
+  # make sure to execute newaliases after adjusting configuration,
+  # otherwise the old hostname will be left inside /etc/aliases.db
+  $ROOTCMD newaliases
 fi
 
 ## END OF FILE #################################################################
-# vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=3
+# vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2