2 # Filename: grml-hostname
3 # Purpose: simple frontend to set hostname
4 # Authors: (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports: see http://grml.org/bugs/
6 # License: This file is licensed under the GPL v2.
7 ################################################################################
9 . /etc/grml/script-functions
14 OLDHOSTNAME="$(hostname)"
16 case "$1" in -h|--help) echo "Usage: $0 [hostname]">&2; exit 1 ;; esac
22 if [ -x /usr/bin/random-hostname ] ; then
23 NEW_HOSTNAME="$(/usr/bin/random-hostname)"
25 NEW_HOSTNAME="$(hostname)"
29 if [ -z "$NONINTERACTIVE" ] ; then
30 NEW_HOSTNAME="$(dialog --stdout --title "${PN}" --extra-button --extra-label "Propose hostname" \
31 --inputbox "Set hostname (/etc/hostname, /etc/hosts and /etc/postfix/main.cf will be adjusted)\
32 \n\nTip: press 'Propose hostname' for another proposal" 14 70 $NEW_HOSTNAME)"
40 echo "$NEW_HOSTNAME" > /etc/hostname
41 echo "$NEW_HOSTNAME" > /etc/mailname
42 sed -i "s/^127.0.0.1[ \t]*$OLDHOSTNAME[ \t]*localhost/127.0.0.1 $NEW_HOSTNAME localhost/" /etc/hosts
43 sed -i "s/^::1[ \t]*ip6-localhost ip6-loopback[ \t]*$OLDHOSTNAME/::1 ip6-localhost ip6-loopback $NEW_HOSTNAME/" /etc/hosts
45 if [ -r /etc/postfix/main.cf ] ; then
46 sed -i "s/^mydestination = .*/mydestination = $NEW_HOSTNAME, localhost, localhost.localdomain/" /etc/postfix/main.cf && \
47 sed -i "s/^myhostname = .*/myhostname = $NEW_HOSTNAME/" /etc/postfix/main.cf && POSTFIX='
48 Configuration of myhostname in /etc/postfix/main.cf has been adjusted as well. Do not forget to restart postfix if necessary.'
50 if [ -z "$NONINTERACTIVE" ] ; then
51 dialog --stdout --title "${PN}" --msgbox "Setting hostname to $NEW_HOSTNAME was successful.$POSTFIX" 0 0
53 echo "Setting hostname to $NEW_HOSTNAME: done"
58 echo "Cancel pressed."
67 ## END OF FILE #################################################################