Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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 | |
| 12 | hostname -b -F /etc/hostname 2> /dev/null |
| 13 | if [ $? -eq 0 ]; then |
| 14 | exit |
| 15 | fi |
| 16 | |
| 17 | # Busybox hostname doesn't support -b so we need implement it on our own |
| 18 | if [ -f /etc/hostname ];then |
| 19 | hostname `cat /etc/hostname` |
| 20 | elif [ -z "$HOSTNAME" -o "$HOSTNAME" = "(none)" -o ! -z "`echo $HOSTNAME | sed -n '/^[0-9]*\.[0-9].*/p'`" ] ; then |
| 21 | hostname localhost |
| 22 | fi |