Releasing debian version 1.236.2-1.
[live-boot-grml.git] / scripts / live-bottom / 06hostname
1 #!/bin/sh
2
3 #set -e
4
5 # initramfs-tools header
6
7 PREREQ=""
8
9 prereqs()
10 {
11         echo "${PREREQ}"
12 }
13
14 case "${1}" in
15         prereqs)
16                 prereqs
17                 exit 0
18                 ;;
19 esac
20
21 # live-initramfs header
22
23 if [ -n "${NOHOSTS}" ]
24 then
25         exit 0
26 fi
27
28 . /scripts/live-functions
29
30 log_begin_msg "Setting hostname"
31
32 # live-initramfs script
33
34 # Change hostname only if it is not set
35 if [ ! -f /root/etc/hostname ] || grep -qs localhost\.localdomain /root/etc/hostname
36 then
37         echo "${HOSTNAME}" > /root/etc/hostname
38 else
39         HOSTNAME="$(cat /root/etc/hostname)"
40         really_export HOSTNAME
41 fi
42
43 # Create /etc/hosts only if it is not present or empty
44 if [ ! -s /root/etc/hosts ]
45 then
46         cat > /root/etc/hosts << EOF
47 127.0.0.1 localhost
48 127.0.1.1 ${HOSTNAME}
49
50 # The following lines are desirable for IPv6 capable hosts
51 ::1     ip6-localhost ip6-loopback
52 fe00::0 ip6-localnet
53 ff00::0 ip6-mcastprefix
54 ff02::1 ip6-allnodes
55 ff02::2 ip6-allrouters
56 ff02::3 ip6-allhosts
57 EOF
58 fi
59
60 hostname "${HOSTNAME}"
61
62 log_end_msg