installer: Don't try to install /etc/hosts which does not exist
[ipfire-2.x.git] / src / installer / dracut-module / 70-dhcpcd.exe
index 4100fc9..660f269 100755 (executable)
 #
 ########################################################################
 
-dhcpcd_up()
-{
-       set | grep "^new_" | sed "s|^new_||g" | \
-       sed "s|'||g" | \
-       sort > /var/ipfire/dhcpc/dhcpcd-$interface.info
+LEASE_FILE="/var/ipfire/dhcpc/dhcpcd-${interface}.info"
 
-       DNS=`grep "domain_name_servers" /var/ipfire/dhcpc/dhcpcd-$interface.info | cut -d"=" -f2`
-       DNS1=`echo $DNS | cut -d" " -f1`
-       DNS2=`echo $DNS | cut -d" " -f2`
+export_lease() {
+       set | grep "^new_" | sed "s|^new_||g" | \
+       sed "s|'||g" | sort > ${LEASE_FILE}
+}
 
-       echo "nameserver $DNS1" > /etc/resolv.conf
-       echo "nameserver $DNS2" >> /etc/resolv.conf
+make_resolvconf() {
+       local DNS="$(grep 'domain_name_servers' ${LEASE_FILE} | cut -d'=' -f2)"
+       local DNS1="$(echo ${DNS} | cut -d' ' -f1)"
+       local DNS2="$(echo ${DNS} | cut -d' ' -f2)"
 
+       (
+               echo "nameserver ${DNS1}"
+               echo "nameserver ${DNS2}"
+       ) > /etc/resolv.conf
 }
 
-case "$reason" in
-BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT|STATIC)       dhcpcd_up;;
+case "${reason}" in
+       PREINIT)
+               # Configure MTU
+               if [ -n "${new_interface_mtu}" ] && [ ${new_interface_mtu} -gt 576 ]; then
+                       echo "Setting MTU to ${new_interface_mtu}"
+                       ip link set "${interface}" mtu "${new_interface_mtu}"
+               fi
+               ;;
+
+       BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT|STATIC)
+               # Export all information about the newly received lease
+               # to file
+               export_lease
+
+               # Create system configuration files
+               make_resolvconf
+               ;;
+
+       EXPIRE|FAIL|IPV4LL|NAK|NOCARRIER|RELEASE|STOP)
+               rm -f "${LEASE_FILE}"
+               ;;
 esac
+
+exit 0