X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=usr_sbin%2Fgrml-hostname;h=b529d1772107c632ef79b92b46880a7b0ca907c6;hb=9375a86c1fe0f2936a7ff20f46aa98a4d5f1ffb3;hp=1c958a05fab771c05309c2b02a82b026bce5a87c;hpb=9fef74081f53d30174118872324fa62d4a8145b5;p=grml-scripts.git diff --git a/usr_sbin/grml-hostname b/usr_sbin/grml-hostname index 1c958a0..b529d17 100755 --- a/usr_sbin/grml-hostname +++ b/usr_sbin/grml-hostname @@ -10,6 +10,8 @@ check4root || exit 1 +[ -n "$SUDO_USER" ] && RUNASUSER=$SUDO_USER || RUNASUSER=grml + PN='grml-hostname' OLDHOSTNAME="$(hostname)" @@ -39,14 +41,28 @@ case $retval in 0) echo "$NEW_HOSTNAME" > /etc/hostname echo "$NEW_HOSTNAME" > /etc/mailname - sed -i "s/^127.0.0.1[ \t]*$OLDHOSTNAME[ \t]*localhost/127.0.0.1 $NEW_HOSTNAME localhost/" /etc/hosts - sed -i "s/^::1[ \t]*ip6-localhost ip6-loopback[ \t]*$OLDHOSTNAME/::1 ip6-localhost ip6-loopback $NEW_HOSTNAME/" /etc/hosts + sed -ir "s/^\(127.0.0.1\s*\).*localhost.*/\1$NEW_HOSTNAME localhost/" /etc/hosts + sed -ir "s/^\(::1\s*\).*ip6-localhost.*/\1ip6-localhost ip6-loopback $NEW_HOSTNAME/" /etc/hosts + POSTFIX='' if [ -r /etc/postfix/main.cf ] ; then sed -i "s/^mydestination = .*/mydestination = $NEW_HOSTNAME, localhost, localhost.localdomain/" /etc/postfix/main.cf && \ sed -i "s/^myhostname = .*/myhostname = $NEW_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 + + if [ -n "$DISPLAY" ] ; then + if sudo -u $RUNASUSER xauth add $(xauth -n list | grep "${OLDHOSTNAME}/unix:0" | sed "s|${OLDHOSTNAME}/unix:0|${NEW_HOSTNAME}/unix:0|") ; then + sudo -u $RUNASUSER xauth remove "${OLDHOSTNAME}/unix:0" + fi + fi + + if [ -x /etc/init.d/avahi-daemon ] && pgrep avahi-daemon >/dev/null ; then + /etc/init.d/avahi-daemon restart + fi + + /etc/init.d/hostname.sh + if [ -z "$NONINTERACTIVE" ] ; then dialog --stdout --title "${PN}" --msgbox "Setting hostname to $NEW_HOSTNAME was successful.$POSTFIX" 0 0 else