hostname.sh 580 B

12345678910111213141516171819202122
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: hostname
  4. # Required-Start:
  5. # Required-Stop:
  6. # Default-Start: S
  7. # Default-Stop:
  8. # Short-Description: Set hostname based on /etc/hostname
  9. ### END INIT INFO
  10. HOSTNAME=$(/bin/hostname)
  11. hostname -b -F /etc/hostname 2> /dev/null
  12. if [ $? -eq 0 ]; then
  13. exit
  14. fi
  15. # Busybox hostname doesn't support -b so we need implement it on our own
  16. if [ -f /etc/hostname ];then
  17. hostname `cat /etc/hostname`
  18. elif [ -z "$HOSTNAME" -o "$HOSTNAME" = "(none)" -o ! -z "`echo $HOSTNAME | sed -n '/^[0-9]*\.[0-9].*/p'`" ] ; then
  19. hostname localhost
  20. fi