Tizen 2.1 base
[platform/upstream/sysvinit.git] / debian / src / initscripts / etc / init.d / hostname.sh
1 #! /bin/sh
2 ### BEGIN INIT INFO
3 # Provides:          hostname
4 # Required-Start:
5 # Required-Stop:
6 # Should-Start:      glibc
7 # Default-Start:     S
8 # Default-Stop:
9 # Short-Description: Set hostname based on /etc/hostname
10 # Description:       Read the machines hostname from /etc/hostname, and
11 #                    update the kernel value with this value.  If
12 #                    /etc/hostname is empty, the current kernel value
13 #                    for hostname is used.  If the kernel value is
14 #                    empty, the value 'localhost' is used.
15 ### END INIT INFO
16
17 PATH=/sbin:/bin
18
19 . /lib/init/vars.sh
20 . /lib/lsb/init-functions
21
22 do_start () {
23         [ -f /etc/hostname ] && HOSTNAME="$(cat /etc/hostname)"
24
25         # Keep current name if /etc/hostname is missing.
26         [ -z "$HOSTNAME" ] && HOSTNAME="$(hostname)"
27
28         # And set it to 'localhost' if no setting was found
29         [ -z "$HOSTNAME" ] && HOSTNAME=localhost
30
31         [ "$VERBOSE" != no ] && log_action_begin_msg "Setting hostname to '$HOSTNAME'"
32         hostname "$HOSTNAME"
33         ES=$?
34         [ "$VERBOSE" != no ] && log_action_end_msg $ES
35         exit $ES
36 }
37
38 do_status () {
39         HOSTNAME=$(hostname)
40         if [ "$HOSTNAME" ] ; then
41                 return 0
42         else
43                 return 4
44         fi
45 }
46
47 case "$1" in
48   start|"")
49         do_start
50         ;;
51   restart|reload|force-reload)
52         echo "Error: argument '$1' not supported" >&2
53         exit 3
54         ;;
55   stop)
56         # No-op
57         ;;
58   status)
59         do_status
60         echo $?
61         ;;
62   *)
63         echo "Usage: hostname.sh [start|stop]" >&2
64         exit 3
65         ;;
66 esac
67
68 :