2020-07-11 18:13:20 +02:00
|
|
|
#!/bin/ash
|
2020-05-30 00:01:28 +02:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2011-11-28 16:28:03 +01:00
|
|
|
|
|
|
|
run_hook () {
|
2016-05-26 23:53:07 +02:00
|
|
|
# Do *not* declare 'bootif_dev' local! We need it in run_latehook().
|
|
|
|
local i net_mac bootif_mac
|
2020-07-11 18:13:20 +02:00
|
|
|
local DNSDOMAIN HOSTNAME IPV4DNS0 IPV4DNS1 ROOTSERVER
|
2011-11-28 16:28:03 +01:00
|
|
|
# These variables will be parsed from /tmp/net-*.conf generated by ipconfig
|
2020-07-11 18:13:20 +02:00
|
|
|
# shellcheck disable=SC2034
|
|
|
|
local DEVICE IPV4ADDR IPV4BROADCAST IPV4NETMASK IPV4GATEWAY NISDOMAIN ROOTPATH filename
|
2011-11-28 16:28:03 +01:00
|
|
|
|
2020-07-11 18:13:20 +02:00
|
|
|
if [ -n "${ip}" ]; then
|
|
|
|
if [ -n "${BOOTIF}" ]; then
|
|
|
|
bootif_mac="${BOOTIF#01-}"
|
2020-07-16 14:49:23 +02:00
|
|
|
# shellcheck disable=SC2169
|
|
|
|
# ash supports bash-like string replacment
|
2020-07-11 18:13:20 +02:00
|
|
|
bootif_mac="${bootif_mac//-/:}"
|
2011-11-28 16:28:03 +01:00
|
|
|
for i in /sys/class/net/*/address; do
|
2020-07-11 18:13:20 +02:00
|
|
|
read -r net_mac < "${i}"
|
|
|
|
if [ "${bootif_mac}" = "${net_mac}" ]; then
|
2011-11-28 16:28:03 +01:00
|
|
|
bootif_dev=${i#/sys/class/net/}
|
|
|
|
bootif_dev=${bootif_dev%/address}
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2020-07-11 18:13:20 +02:00
|
|
|
if [ "${ip}" = "dhcp" ]; then
|
2017-03-10 21:01:06 +01:00
|
|
|
ip=":::::${bootif_dev}:dhcp"
|
2020-07-11 18:13:20 +02:00
|
|
|
else
|
2017-03-10 21:01:06 +01:00
|
|
|
ip="${ip}::${bootif_dev}"
|
|
|
|
fi
|
2011-11-28 16:28:03 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# setup network and save some values
|
2017-03-10 21:01:05 +01:00
|
|
|
if ! ipconfig -t 20 "ip=${ip}"; then
|
2020-07-11 18:13:20 +02:00
|
|
|
echo "ERROR; Failed to configure network"
|
|
|
|
echo " Falling back to interactive prompt"
|
|
|
|
echo " You can try to fix the problem manually, log out when you are finished"
|
|
|
|
launch_interactive_shell
|
2015-05-29 15:51:14 +02:00
|
|
|
fi
|
2011-11-28 16:28:03 +01:00
|
|
|
|
2020-07-16 14:49:23 +02:00
|
|
|
# shellcheck disable=SC1090
|
|
|
|
# ipconfig generates these files
|
2011-11-28 16:28:03 +01:00
|
|
|
. /tmp/net-*.conf
|
|
|
|
|
2020-07-11 18:13:20 +02:00
|
|
|
export pxeserver="${ROOTSERVER}"
|
2011-11-28 16:28:03 +01:00
|
|
|
|
|
|
|
# setup DNS resolver
|
2020-07-11 18:13:20 +02:00
|
|
|
if [ "${IPV4DNS0}" != "0.0.0.0" ]; then
|
2016-09-29 17:24:35 +02:00
|
|
|
echo "# added by archiso_pxe_common hook" > /etc/resolv.conf
|
|
|
|
echo "nameserver ${IPV4DNS0}" >> /etc/resolv.conf
|
2011-11-28 16:28:03 +01:00
|
|
|
fi
|
2020-07-11 18:13:20 +02:00
|
|
|
if [ "${IPV4DNS1}" != "0.0.0.0" ]; then
|
2011-11-28 16:28:03 +01:00
|
|
|
echo "nameserver ${IPV4DNS1}" >> /etc/resolv.conf
|
|
|
|
fi
|
2020-07-11 18:13:20 +02:00
|
|
|
if [ -n "${DNSDOMAIN}" ]; then
|
2016-09-29 17:09:59 +02:00
|
|
|
echo "search ${DNSDOMAIN}" >> /etc/resolv.conf
|
2016-09-29 17:58:19 +02:00
|
|
|
echo "domain ${DNSDOMAIN}" >> /etc/resolv.conf
|
2016-09-29 17:09:59 +02:00
|
|
|
fi
|
2011-11-28 16:28:03 +01:00
|
|
|
fi
|
|
|
|
}
|
2012-05-19 21:16:17 +02:00
|
|
|
|
|
|
|
run_latehook () {
|
2020-07-11 18:13:20 +02:00
|
|
|
if [ -n "${ip}" ]; then
|
|
|
|
[ -z "${copy_resolvconf}" ] && copy_resolvconf="y"
|
2012-05-19 21:16:17 +02:00
|
|
|
|
2020-07-16 14:49:23 +02:00
|
|
|
# shellcheck disable=SC2154
|
|
|
|
# defined via initcpio's parse_cmdline()
|
2020-07-11 18:13:20 +02:00
|
|
|
if [ "${copytoram}" = "y" ]; then
|
2020-11-18 22:12:00 +01:00
|
|
|
for curif in /sys/class/net/*; do
|
|
|
|
netdev=${curif#/sys/class/net/}
|
|
|
|
ip addr flush dev "${netdev}"
|
|
|
|
ip link set "${netdev}" down
|
|
|
|
done
|
2020-07-11 18:13:20 +02:00
|
|
|
elif [ "${copy_resolvconf}" != "n" ] && [ -f /etc/resolv.conf ]; then
|
2021-01-18 11:07:14 +01:00
|
|
|
rm -f /new_root/etc/resolv.conf
|
2016-05-24 13:57:08 +02:00
|
|
|
cp /etc/resolv.conf /new_root/etc/resolv.conf
|
|
|
|
fi
|
2012-05-19 21:16:17 +02:00
|
|
|
fi
|
|
|
|
}
|
2020-07-11 18:13:20 +02:00
|
|
|
|
|
|
|
# vim: set ft=sh:
|