installer: Don't try to install /etc/hosts which does not exist
[ipfire-2.x.git] / src / installer / dracut-module / 70-dhcpcd.exe
1 #/bin/bash
2 ########################################################################
3 # Begin
4 #
5 # Description : DHCP Client Script (initrd version)
6 #
7 # Authors : Arne Fitzenreiter - arne_f@ipfire.org
8 #
9 # Version : 02.00
10 #
11 # Notes :
12 #
13 ########################################################################
14
15 LEASE_FILE="/var/ipfire/dhcpc/dhcpcd-${interface}.info"
16
17 export_lease() {
18 set | grep "^new_" | sed "s|^new_||g" | \
19 sed "s|'||g" | sort > ${LEASE_FILE}
20 }
21
22 make_resolvconf() {
23 local DNS="$(grep 'domain_name_servers' ${LEASE_FILE} | cut -d'=' -f2)"
24 local DNS1="$(echo ${DNS} | cut -d' ' -f1)"
25 local DNS2="$(echo ${DNS} | cut -d' ' -f2)"
26
27 (
28 echo "nameserver ${DNS1}"
29 echo "nameserver ${DNS2}"
30 ) > /etc/resolv.conf
31 }
32
33 case "${reason}" in
34 PREINIT)
35 # Configure MTU
36 if [ -n "${new_interface_mtu}" ] && [ ${new_interface_mtu} -gt 576 ]; then
37 echo "Setting MTU to ${new_interface_mtu}"
38 ip link set "${interface}" mtu "${new_interface_mtu}"
39 fi
40 ;;
41
42 BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT|STATIC)
43 # Export all information about the newly received lease
44 # to file
45 export_lease
46
47 # Create system configuration files
48 make_resolvconf
49 ;;
50
51 EXPIRE|FAIL|IPV4LL|NAK|NOCARRIER|RELEASE|STOP)
52 rm -f "${LEASE_FILE}"
53 ;;
54 esac
55
56 exit 0