X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=usr_sbin%2Fgrml-hostname;h=644b79873dfb496378f3557df084cfd1e8c8d7f2;hb=d79405e77fb6caeea45b6d5c29398a46a1ac58be;hp=6e0c8403e4d760825319dba4ed3af638bc3412b2;hpb=e720deae78f1eda5e6f62629606c194f16796762;p=grml-scripts.git diff --git a/usr_sbin/grml-hostname b/usr_sbin/grml-hostname index 6e0c840..644b798 100755 --- a/usr_sbin/grml-hostname +++ b/usr_sbin/grml-hostname @@ -4,53 +4,54 @@ # Authors: (c) Michael Prokop # Bug-Reports: see http://grml.org/bugs/ # License: This file is licensed under the GPL v2. -# Latest change: Sam Sep 30 12:36:24 CEST 2006 [mika] +# Latest change: Die Feb 13 12:16:57 CET 2007 [mika] ################################################################################ -if [ $UID != 0 ] ; then - echo Error: become root before starting $0 >& 2 - exit 100 -fi +source /etc/grml/script-functions + +check4root || exit 1 PN='grml-hostname' -TMP=$(mktemp) OLDHOSTNAME="$(hostname)" -if [ -x /usr/bin/random-hostname ] ; then - HOSTNAME="$(/usr/bin/random-hostname)" +case "$1" in -h|--help) echo "Usage: $0 [hostname]">&2; exit 1 ;; esac + +if [ -n "$1" ] ; then + HOSTNAME="$1" + NONINTERACTIVE=1 else - HOSTNAME="$(hostname)" + if [ -x /usr/bin/random-hostname ] ; then + HOSTNAME="$(/usr/bin/random-hostname)" + else + HOSTNAME="$(hostname)" + fi fi -bailout() { - rm -f $TMP - exit 1 -} -trap bailout 1 2 3 15 - -# running inside grml2hd? Don't warn because of hostname + X -[ -n "$GRML2HD" ] || MSG='\n\nNotice: setting a different hostname while running X is *not* recommend!' - -HOSTNAME="$(dialog --stdout --title "${PN}" --extra-button --extra-label "Propose hostname" \ ---inputbox "Set hostname (/etc/hostname, /etc/hosts and /etc/postfix/main.cf will be adjusted)\ -\n\nTip: press 'Propose hostname' for another proposal${MSG}" 14 70 $HOSTNAME)" -retval=$? +if [ -z "$NONINTERACTIVE" ] ; then + HOSTNAME="$(dialog --stdout --title "${PN}" --extra-button --extra-label "Propose hostname" \ + --inputbox "Set hostname (/etc/hostname, /etc/hosts and /etc/postfix/main.cf will be adjusted)\ +\n\nTip: press 'Propose hostname' for another proposal" 14 70 $HOSTNAME)" + retval=$? +else + retval=0 +fi case $retval in 0) - if hostname "$HOSTNAME" 1>/dev/null 2>${TMP} ; then - echo "$HOSTNAME" > /etc/hostname - sed -i "s/^127.0.0.1[ \t]*$OLDHOSTNAME[ \t]*localhost/127.0.0.1 $HOSTNAME localhost/" /etc/hosts - sed -i "s/^::1[ \t]*ip6-localhost ip6-loopback[ \t]*$OLDHOSTNAME/::1 ip6-localhost ip6-loopback $HOSTNAME/" /etc/hosts - POSTFIX='' - if [ -r /etc/postfix/main.cf ] ; then - sed -i "s/^myhostname = .*/myhostname = $HOSTNAME/" /etc/postfix/main.cf && POSTFIX=' + echo "$HOSTNAME" > /etc/hostname + sed -i "s/^127.0.0.1[ \t]*$OLDHOSTNAME[ \t]*localhost/127.0.0.1 $HOSTNAME localhost/" /etc/hosts + sed -i "s/^::1[ \t]*ip6-localhost ip6-loopback[ \t]*$OLDHOSTNAME/::1 ip6-localhost ip6-loopback $HOSTNAME/" /etc/hosts + POSTFIX='' + if [ -r /etc/postfix/main.cf ] ; then + sed -i "s/^myhostname = .*/myhostname = $HOSTNAME/" /etc/postfix/main.cf && POSTFIX=' Configuration of myhostname in /etc/postfix/main.cf has been adjusted as well. Do not forget to restart postfix if necessary.' - fi - dialog --stdout --title "${PN}" --msgbox "Setting hostname to $HOSTNAME was successful.$POSTFIX" 0 0 + fi + if [ -z "$NONINTERACTIVE" ] ; then + dialog --stdout --title "${PN}" --msgbox "Setting hostname to $HOSTNAME was successful.$POSTFIX" 0 0 else - dialog --stdout --title "${PN}" --msgbox "Error when setting hostname to $HOSTNAME: `cat $TMP`" 0 0 + echo "Setting hostname to $HOSTNAME: done" fi + exit 0 ;; 1) echo "Cancel pressed." @@ -62,6 +63,4 @@ Configuration of myhostname in /etc/postfix/main.cf has been adjusted as well. D ;; esac -rm -f $TMP 2>/dev/null - ## END OF FILE #################################################################