ce91001c1294a853efbcf8a961d177567e952652
[grml-live.git] / etc / grml / fai / config / scripts / GRMLBASE / 05-hostname
1 #!/bin/bash
2 # Filename:      ${GRML_FAI_CONFIG}/config/scripts/GRMLBASE/05-hostname
3 # Purpose:       set hostname of live-system
4 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2 or any later version.
7 ################################################################################
8
9 set -u
10 set -e
11
12 HOSTNAME=''
13 [ -r /etc/grml/grml-live.conf ]  && . /etc/grml/grml-live.conf
14 [ -n "$GRML_LIVE_LOCAL_CONFIG" ] && . "$GRML_LIVE_LOCAL_CONFIG"
15 [ -n "$HOSTNAME" ] || HOSTNAME=grml
16
17 # the hostname of the chroot usually isn't the same as the one for the live-system
18 BUILD_HOSTNAME="$($ROOTCMD hostname)"
19 [ -n "$BUILD_HOSTNAME" ] || BUILD_HOSTNAME="grml"
20
21 echo "$HOSTNAME" > $target/etc/hostname
22 echo "$HOSTNAME" > $target/etc/mailname
23
24 if [ -r $target/etc/postfix/main.cf ] ; then
25   sed -i "s/^mydestination = .*/mydestination = $HOSTNAME, localhost, localhost.localdomain/" $target/etc/postfix/main.cf
26   sed -i "s/^myhostname = .*/myhostname = $HOSTNAME/" $target/etc/postfix/main.cf
27   echo "postfix postfix/mailname     string $HOSTNAME" | $ROOTCMD debconf-set-selections
28   echo "postfix postfix/destinations string ${HOSTNAME}, localhost.grml.org, localhost" \
29   | $ROOTCMD debconf-set-selections
30   # make sure to execute newaliases after adjusting configuration,
31   # otherwise the old hostname will be left inside /etc/aliases.db
32   $ROOTCMD newaliases
33 fi
34
35 if [ -r $target/etc/bacula/bacula-fd.conf ] ; then
36   sed -i "s/$BUILD_HOSTNAME/$HOSTNAME/g" $target/etc/bacula/bacula-fd.conf
37 fi
38
39 ## END OF FILE #################################################################
40 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2