Skip to content

Commit 3ea7b75

Browse files
committedJan 12, 2012
grml-hostname: improve regex for hostname matching [Closes: issue1005]
Do not trust on output of hostname(1) as this might not necessarily be what's used inside /etc/hosts. This is supposed to work on Grml systems as well as on Debian. While at it also use same formating WRT whitespace chars when replacing the localhost line(s).
1 parent 8ca48f1 commit 3ea7b75

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed
 

‎usr_sbin/grml-hostname

+4-2
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,16 @@ case $retval in
4141
0)
4242
echo "$NEW_HOSTNAME" > /etc/hostname
4343
echo "$NEW_HOSTNAME" > /etc/mailname
44-
sed -i "s/^127.0.0.1[ \t]*$OLDHOSTNAME[ \t]*localhost/127.0.0.1 $NEW_HOSTNAME localhost/" /etc/hosts
45-
sed -i "s/^::1[ \t]*ip6-localhost ip6-loopback[ \t]*$OLDHOSTNAME/::1 ip6-localhost ip6-loopback $NEW_HOSTNAME/" /etc/hosts
44+
sed -ir "s/^\(127.0.0.1\s*\).*localhost.*/\1$NEW_HOSTNAME localhost/" /etc/hosts
45+
sed -ir "s/^\(::1\s*\).*ip6-localhost.*/\1ip6-localhost ip6-loopback $NEW_HOSTNAME/" /etc/hosts
46+
4647
POSTFIX=''
4748
if [ -r /etc/postfix/main.cf ] ; then
4849
sed -i "s/^mydestination = .*/mydestination = $NEW_HOSTNAME, localhost, localhost.localdomain/" /etc/postfix/main.cf && \
4950
sed -i "s/^myhostname = .*/myhostname = $NEW_HOSTNAME/" /etc/postfix/main.cf && POSTFIX='
5051
Configuration of myhostname in /etc/postfix/main.cf has been adjusted as well. Do not forget to restart postfix if necessary.'
5152
fi
53+
5254
if [ -n "$DISPLAY" ] ; then
5355
if sudo -u $RUNASUSER xauth add $(xauth -n list | grep "${OLDHOSTNAME}/unix:0" | sed "s|${OLDHOSTNAME}/unix:0|${NEW_HOSTNAME}/unix:0|") ; then
5456
sudo -u $RUNASUSER xauth remove "${OLDHOSTNAME}/unix:0"

0 commit comments

Comments
 (0)
Please sign in to comment.