From 093ee7bf398acde737cada410fbe8aaa0184582d Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Tue, 13 Feb 2007 12:17:21 +0100 Subject: [PATCH] grml-hostname: support non-interactive mode and to not set hostname via hostname(1) --- debian/changelog | 8 ++++++++ manpages/grml-scripts.1 | 6 +++++- usr_sbin/grml-hostname | 53 ++++++++++++++++++++++++++----------------------- 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/debian/changelog b/debian/changelog index 1aed3a7..5fc9a7d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +grml-scripts (0.9.16) unstable; urgency=low + + * grml-hostname: support non-interactive mode and do not + set hostname via hostname(1) but write to according + files only so it does not break for example running X. + + -- Michael Prokop Tue, 13 Feb 2007 12:08:39 +0100 + grml-scripts (0.9.15) unstable; urgency=low * The "I love working on new architectures! :)" release. diff --git a/manpages/grml-scripts.1 b/manpages/grml-scripts.1 index a9390e2..0c50534 100644 --- a/manpages/grml-scripts.1 +++ b/manpages/grml-scripts.1 @@ -164,7 +164,11 @@ Central configuration interface to configure the grml system. .SS grml-config-root Configuration interface for admin tasks on the grml system. .SS grml-hostname -Simple frontend to set hostname. +Simple frontend to configure hostname in the corresponding +files. When executed without a parameter a dialog based +frontend will be used, when given a parameter the provided +parameter will be used as hostname and script is executed in +non-interactive mode. .SS grml-nessus Prepare nessus for use on grml system. .SS grml-postfix diff --git a/usr_sbin/grml-hostname b/usr_sbin/grml-hostname index b48449e..644b798 100755 --- a/usr_sbin/grml-hostname +++ b/usr_sbin/grml-hostname @@ -4,37 +4,37 @@ # Authors: (c) Michael Prokop # Bug-Reports: see http://grml.org/bugs/ # License: This file is licensed under the GPL v2. -# Latest change: Son Dez 17 16:23:34 CET 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) @@ -46,7 +46,12 @@ case $retval in 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 + if [ -z "$NONINTERACTIVE" ] ; then + dialog --stdout --title "${PN}" --msgbox "Setting hostname to $HOSTNAME was successful.$POSTFIX" 0 0 + else + echo "Setting hostname to $HOSTNAME: done" + fi + exit 0 ;; 1) echo "Cancel pressed." @@ -58,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 ################################################################# -- 2.1.4