grml-chroot: mount /dev/pts as devpts inside chroot
[grml-scripts.git] / usr_sbin / grml-hostname
index e97c353..ade8631 100755 (executable)
@@ -37,6 +37,20 @@ else
   retval=0
 fi
 
+# stupid + simplified checking for valid hostname (according to RFC 952)
+VALIDATE=$(echo "$NEW_HOSTNAME" | tr --delete '[:alnum:]-')
+if [ -n "$VALIDATE" ] ; then
+  if [ -z "$NONINTERACTIVE" ] ; then
+    dialog --title "${PN}" \
+      --msgbox "Error: invalid characters specified in hostname: '$VALIDATE' can not be used inside hostnames." \
+      0 0
+    exec "$0"
+  else
+    echo "Error: invalid characters specified in hostname: '$VALIDATE' can not be used inside hostnames." >&2
+    exit 1
+  fi
+fi
+
 case $retval in
   0)
      echo "$NEW_HOSTNAME" > /etc/hostname
@@ -57,7 +71,11 @@ Configuration of myhostname in /etc/postfix/main.cf has been adjusted as well. D
        fi
      fi
 
-     /etc/init.d/hostname.sh
+     if [ -x /etc/init.d/avahi-daemon ] && pgrep avahi-daemon >/dev/null ; then
+       /etc/init.d/avahi-daemon restart
+     fi
+
+     hostname "$NEW_HOSTNAME"
 
      if [ -z "$NONINTERACTIVE" ] ; then
         dialog --stdout --title "${PN}" --msgbox "Setting hostname to $NEW_HOSTNAME was successful.$POSTFIX" 0 0