diff options
| author | Jonathan Bauer | 2020-05-13 11:04:02 +0200 |
|---|---|---|
| committer | Jonathan Bauer | 2020-05-13 11:04:02 +0200 |
| commit | 1130873aa55c9b0a7e5af48edc44bd6c6fd1f888 (patch) | |
| tree | 0fcfa186cd631d8d36611b3d4bc509fd38841d51 /builder/modules.d/slx-network/scripts | |
| parent | Merge branch 'centos8' into downloader (diff) | |
| download | systemd-init-1130873aa55c9b0a7e5af48edc44bd6c6fd1f888.tar.gz systemd-init-1130873aa55c9b0a7e5af48edc44bd6c6fd1f888.tar.xz systemd-init-1130873aa55c9b0a7e5af48edc44bd6c6fd1f888.zip | |
restructure repo
* remove packager
* move everything from builder/* back to root
Diffstat (limited to 'builder/modules.d/slx-network/scripts')
4 files changed, 0 insertions, 516 deletions
diff --git a/builder/modules.d/slx-network/scripts/setup-bootif-network.stage3 b/builder/modules.d/slx-network/scripts/setup-bootif-network.stage3 deleted file mode 100755 index 53ad8de9..00000000 --- a/builder/modules.d/slx-network/scripts/setup-bootif-network.stage3 +++ /dev/null @@ -1,112 +0,0 @@ -#!/bin/bash -# -# This script sets up the main network interface we booted from, -# as designated by SLX_PXE_NETIF (parsed from the PXE KCL in the -# cmdline dracut hook). -# It is run inside dracut's initqueue, on settles to detect the -# physical network interface as fast as possible. - -type emergency_shell >/dev/null 2>&1 || . /lib/dracut-lib.sh - -. /run/openslx/network.conf - -# guard to not run until the phsyical interface is not ready yet -if [ ! -e "/sys/class/net/${SLX_PXE_NETIF}/device" ]; then - exit 1 -fi - -wait_for_iface() { - local _iface="$1" - local _timeout="${2:-50}" - while [ "$_timeout" -ne 0 ]; do - [ "$(cat /sys/class/net/${_iface}/operstate)" = "up" ] && break - (( _timeout -- )) - usleep 100000 - done - [ "$_timeout" -ne 0 ] -} - -# For debugging... -{ -set -x - -ip link set dev "$SLX_PXE_NETIF" up -if ! wait_for_iface "$SLX_PXE_NETIF" 300; then - warn "'$SLX_PXE_NETIF' still not up after 30sec ... trying anyway." - # TODO handle case where we waited for 30sec and it is still not up -fi - -# now determine whether we are in bridged/vlan/plain mode -MAIN_NETIF="$SLX_PXE_NETIF" -if [ -n "$SLX_VLAN_ID" ]; then - # create VLAN interface - modprobe 8021q || warn "Loading '8021q' failed - missing module?" - ip link add link "$SLX_PXE_NETIF" name "${SLX_PXE_NETIF}.${SLX_VLAN_ID}" \ - type vlan id "$SLX_VLAN_ID" - ip link set dev "${SLX_PXE_NETIF}.${SLX_VLAN_ID}" up - if wait_for_iface "${SLX_PXE_NETIF}.${SLX_VLAN_ID}"; then - MAIN_NETIF="${SLX_PXE_NETIF}.${SLX_VLAN_ID}" - else - warn "Setting up VLAN '$SLX_VLAN_ID' failed, trying plain..." - fi -fi - -if [ -n "$SLX_BRIDGE" ]; then - for try in {1..10} ""; do - ( - set -e - brctl addbr "$SLX_BRIDGE" - brctl stp "$SLX_BRIDGE" 0 - brctl setfd "$SLX_BRIDGE" 0.000000000001 - ip link set addr "$SLX_PXE_MAC" "$SLX_BRIDGE" - brctl addif "$SLX_BRIDGE" "$MAIN_NETIF" - ip link set dev "$SLX_BRIDGE" up - wait_for_iface "$SLX_BRIDGE" - ) - # success? - if [ "$?" -eq 0 ]; then - MAIN_NETIF="$SLX_BRIDGE" - break - fi - - # nope, handle - if [ -z "$try" ]; then - emergency_shell "Failed to setup main network bridge, giving up!" - fi - warn "Failed to setup main network bridge on try $try. Retrying ..." - # delete bridge, inc try and sleep 100ms before trying again - [ -e "/sys/class/net/${SLX_BRIDGE}" ] && brctl delbr "$SLX_BRIDGE" - usleep 100000 - done -fi - -# finally add the IP address on the main NIC -if [ -n "$SLX_PXE_CLIENT_IP" ]; then - ip addr add \ - "${SLX_PXE_CLIENT_IP}/$(ipcalc -s -p "$SLX_PXE_CLIENT_IP" "$SLX_PXE_NETMASK" | sed "s/.*=//")" \ - broadcast "$(ipcalc -s -b "$SLX_PXE_CLIENT_IP" "$SLX_PXE_NETMASK" | sed "s/.*=//")" \ - dev "$MAIN_NETIF" -fi - -if [ "$USE_DHCP_UUID" = "yes" ] && [ -s "/run/system-uuid" ]; then - UUID="$(cat /run/system-uuid)" -fi - -# udhcpc -for i in 1 1 1 fail; do - [ "$i" = "fail" ] && emergency_shell "DHCP failed 3 times... cannot continue." - udhcpc -t 4 -T 3 -f -n -q \ - -i "${MAIN_NETIF}" \ - "${SLX_PXE_CLIENT_IP:+-r $SLX_PXE_CLIENT_IP}" \ - "${UUID:+-x 0x3d:$UUID}" \ - -O ntpsrv -O domain -O wpad -O search -O nisdomain \ - -s "/usr/local/bin/udhcpc-trigger" - # success? - [ "$?" -eq 0 ] && break - # nope, keep trying... - warn "DHCP failed, retrying in 1sec..." - sleep $i -done - -set +x -} &>> "/run/openslx/initramfs-network.log.$$" diff --git a/builder/modules.d/slx-network/scripts/setup-bootif-network.stage4 b/builder/modules.d/slx-network/scripts/setup-bootif-network.stage4 deleted file mode 100755 index 61f925d0..00000000 --- a/builder/modules.d/slx-network/scripts/setup-bootif-network.stage4 +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/bash -# -# This script sets up the main network interface we booted from, -# as designated by SLX_PXE_NETIF in /opt/openslx/config -# It will run on either the bridge (SLX_BRIDGE is set) or the -# physical interface directly. - -export PATH=$PATH:/opt/openslx/sbin:/opt/openslx/bin - -. /opt/openslx/config - -if [ -z "$SLX_PXE_NETIF" ]; then - echo "Missing network information of the main boot interface." - exit 1 -fi - -MAIN_NETIF="$SLX_PXE_NETIF" -[ -n "$SLX_VLAN_ID" ] && MAIN_NETIF="${SLX_PXE_NETIF}.${SLX_VLAN_ID}" -[ -n "$SLX_BRIDGE" ] && MAIN_NETIF="${SLX_BRIDGE}" -readonly MAIN_NETIF - -# set default options -declare -a udhcpc_opts -udhcpc_opts+=("-t" "8") -udhcpc_opts+=("-O" "domain") -udhcpc_opts+=("-O" "nissrv") -udhcpc_opts+=("-O" "nisdomain") -udhcpc_opts+=("-O" "wpad") -udhcpc_opts+=("-O" "search") -udhcpc_opts+=("-O" "wins") - -# send machine uuid during DHCP if configured -if [ "$SLX_NET_DHCP_UUID" = "yes" ]; then - uid=$(dmidecode -s system-uuid | \ - sed -r 's/^(..)(..)(..)(..)-(..)(..)-(..)(..)-(....)-/00\4\3\2\1\6\5\8\7\9/') - if [ "${#uid}" = 34 ]; then - echo "Using SMBIOS uid for DHCP" - udhcpc_opts+=( "-x" "0x3d:$uid" ) - fi -fi - -mkdir -p /run/udhcpc || echo "Could not create '/run/udhcpc'." - -udhcpc "${udhcpc_opts[@]}" \ - -i "$MAIN_NETIF" \ - -r "${SLX_PXE_CLIENT_IP}" \ - -s /opt/openslx/scripts/udhcpc-trigger \ - -p "/run/udhcpc/udhcpc.${MAIN_NETIF}.pid" -ret=$? - -if [ "${ret}" != 0 ]; then - echo "udhcpc" "Could not run 'udhcpc ${udhcpc_opts[*]}' on ${MAIN_NETIF}." -fi - -exit "${ret}" - diff --git a/builder/modules.d/slx-network/scripts/udhcpc-trigger.stage3 b/builder/modules.d/slx-network/scripts/udhcpc-trigger.stage3 deleted file mode 100755 index d54939a8..00000000 --- a/builder/modules.d/slx-network/scripts/udhcpc-trigger.stage3 +++ /dev/null @@ -1,140 +0,0 @@ -#!/bin/bash -# -# This script is triggered by udhcpc in stage3 and handle the -# DHCP information given as parameters - -{ -# for debugging -set -x -NETWORK_CONF="/run/openslx/network.conf" -. "$NETWORK_CONF" - -MAIN_NETIF="$SLX_PXE_NETIF" -[ -n "$SLX_VLAN_ID" ] && MAIN_NETIF="${SLX_PXE_NETIF}.${SLX_VLAN_ID}" -[ -n "$SLX_BRIDGE" ] && MAIN_NETIF="$SLX_BRIDGE" -readonly MAIN_NETIF - -if [ "x$1" != "xbound" -a "x$1" != "xrenew" ] \ - || [ "x$interface" != "x${MAIN_NETIF}" ] \ - || [ -z "$ip" ]; then - exit 0 -fi - -## -## CORE NETWORK CONFIGURATION -## -## > IP, subnet, route - -# If we already got an IP from KCL, see if it differs, and remove first if so -# We just try to prevent everything from breaking if the DHCP server doesn't -# objey the renew request by the client and hands out a new address -if [ -n "$SLX_PXE_CLIENT_IP" ]; then - #...some address is already configured... - if [ "x${SLX_PXE_CLIENT_IP}" != "x${ip}" ]; then - #...it's a different one, reconfigure... - echo "..reconfiguring ${SLX_PXE_CLIENT_IP} to ${ip}.." - # remove default route and let it be added again below, as it might get lost when changing the primary address on the interface - ip route del default 2>/dev/null - ip addr del "$SLX_PXE_CLIENT_IP" dev "${interface}" 2>/dev/null - ip addr add "${ip}/$(ipcalc -s -p "${ip}" "${subnet}" | sed s/.*=//)" dev "${interface}" - fi -else - #...no address configured yet, just add... - echo "..adding ${ip}.." - ip addr add "${ip}/$(ipcalc -s -p "${ip}" "${subnet}" | sed s/.*=//)" dev "${interface}" -fi -echo "SLX_DHCP_CLIENT_IP='$ip'" >> "$NETWORK_CONF" - -# Same procedure for default gateway -if [ -n "${router}" ]; then - if [ -s "$SLX_PXE_GATEWAY" ]; then - if [ "x${SLX_PXE_GATEWAY}" != "x${router}" ]; then - echo "..reconfiguring default gw from ${SLX_PXE_GATEWAY} to ${router}.." - ip route replace default via "$router" - fi - else - ip route add default via "$router" - fi - echo "SLX_DHCP_GATEWAY='$router'" >> "$NETWORK_CONF" -fi - -## -## ADDITIONAL NETWORK CONFIGURATION -## -## > DNS, domain, hostname - -rm -f -- "/etc/resolv.conf" - -# DNS/domain? -if [ -n "$dns" ]; then - echo "..got DNS.." - echo "# From DHCP in stage 3.1" >> "$NETWORK_CONF" - echo "SLX_DNS='$dns'" >> "$NETWORK_CONF" -fi -for srv in $dns; do - echo "nameserver $srv" >> "/etc/resolv.conf" -done -if [ -z "$domain" ]; then - # try to get domain via reverse lookup if empty - echo "..trying to get domain via DNS, as DHCP didn't supply one.." - fqdn=$(timeout -t 3 nslookup "$ip" | grep -E "^Address +[0-9]+: +$ip " | head -n 1 | awk '{print $4}') - domain="${fqdn#*.}" -fi -# Add domain to list of search domains if not in there yet -if [ -n "$domain" ] && [ -n "$search" ]; then - FOUND=no - for sd in $search; do - [ "x$sd" = "x$domain" ] && FOUND=yes - done - [ "$FOUND" = "no" ] && search="$domain $search" -elif [ -n "$domain" ]; then - search="$domain" -fi -# Write out -if [ -n "$domain" ]; then - echo "domain $domain" >> "/etc/resolv.conf" - echo "SLX_NET_DOMAIN='$domain'" >> "/run/openslx/network.conf" -fi -if [ -n "$search" ]; then - echo "search $search" >> "/etc/resolv.conf" - echo "SLX_NET_SEARCH='$search'" >> "/run/openslx/network.conf" -fi - -if [ -n "$ntpsrv" ]; then - echo "SLX_DHCP_NTP='$ntpsrv'" >> "/run/openslx/network.conf" -fi - -# Hostname -# Ignore hostname/fqdn it if hostname was forced per KCL. -if [ -n "$SLX_PXE_HOSTNAME" ]; then - echo "Hostname set via KCL, ignoring DHCP hostname: '$hostname'" - hostname="$SLX_PXE_HOSTNAME" -else - if [ -z "$hostname" ]; then - # as with domain, if there's no hostname, try to get via DNS - echo "..trying to get hostname via DNS, as DHCP didn't supply one.." - [ -z "$fqdn" ] && fqdn=$(timeout -t 3 nslookup "$ip" | grep -E "^Address +[0-9]+: +$ip " | head -n 1 | awk '{print $4}') - hostname="${fqdn%%.*}" - elif [ -n "$domain" ]; then - fqdn="${hostname}.${domain%% *}" # in case domain is a list - fi -fi - -if [ -z "$hostname" ]; then - # no fallback hostname from DNS, use IP address - hostname="${ip//./-}" -fi - -if [ -n "$hostname" ]; then - [ -z "$fqdn" ] && fqdn="$hostname" - echo "..setting hostname $hostname (fqdn: $fqdn).." - echo "$hostname" > "/proc/sys/kernel/hostname" - echo "$hostname" > "/etc/hostname" - echo "127.0.0.1 localhost" > "/etc/hosts" - echo "127.0.1.1 $fqdn $hostname" >> "/etc/hosts" - echo "SLX_HOSTNAME='$hostname'" >> "/run/openslx/network.conf" -fi - -touch /.network -set +x -} &>> "/run/openslx/initramfs-udhcpc.log.$$" diff --git a/builder/modules.d/slx-network/scripts/udhcpc-trigger.stage4 b/builder/modules.d/slx-network/scripts/udhcpc-trigger.stage4 deleted file mode 100755 index b4dfeafa..00000000 --- a/builder/modules.d/slx-network/scripts/udhcpc-trigger.stage4 +++ /dev/null @@ -1,208 +0,0 @@ -#!/bin/bash -# -# This script is triggered by udhcpc and handle the DHCP information -# given to this script as parameters. - -export PATH=$PATH:/opt/openslx/sbin:/opt/openslx/bin - -. /opt/openslx/config - -if [ -z "$SLX_PXE_NETIF" ]; then - echo "Missing PXE network interface information." - exit 1 -fi - -MAIN_NETIF="$SLX_PXE_NETIF" -[ -n "$SLX_VLAN_ID" ] && MAIN_NETIF="${SLX_PXE_NETIF}.${SLX_VLAN_ID}" -[ -n "$SLX_BRIDGE" ] && MAIN_NETIF="$SLX_BRIDGE" -readonly MAIN_NETIF - -RESOLV_CONF="/opt/openslx/resolv.conf" -THIS_RESOLV="/run/network/${MAIN_NETIF}.resolv" - -rebuild_resolv_conf () { - # Don't do anything if the active resolv.conf is not ours - # Also this will not run resolvconf update.d... No idea if we should still do so... - [ -L "/etc/resolv.conf" ] || return 0 - [ "x$(readlink "/etc/resolv.conf")" == "x${RESOLV_CONF}" ] || return 0 - # Maybe make this smarter some time, if anyone is using clients that are on multiple networks at once etc... - # This is a little braindead but should work most of the time - sort -u /run/network/*.resolv > "$RESOLV_CONF" 2> /dev/null - - # add support for resolv.conf update scripts // see man(8) resolvconf - for s in /etc/resolvconf/update.d/*.sh; do - [ -f "$s" ] && [ -x "$s" ] && "$s" - done -} - -escape_search() { - echo "$@" | sed -e 's/[]\/()$*.^|[]/\\&/g' -} - -escape_replace() { - echo "$@" | sed -e 's/[\/&]/\\&/g' -} - -check_env() { - if [ -z "$ip" ] || [ -z "$subnet" ] || [ -z "$interface" ]; then - echo "$1 event with missing data" >&2 - echo "ip = '$ip'" >&2 - echo "subnet = '$subnet'" >&2 - echo "interface = '$interface'" >&2 - exit 1 - fi - # only run for the boot network interface - # TODO VLAN support - if [ "$interface" != "$MAIN_NETIF" ]; then - echo "Ignoring '$interface'..." - exit 1 - fi -} - -case "$1" in - bound|renew) - check_env "$1" - # Set address on interface - ip addr add "$ip/$(ipcalc -s -p "$ip" "$subnet" | sed s/.*=//)" dev "$interface" - # Set default route, if given - if [ -n "$router" ]; then - ip route replace default via "$router" - fi - - # get domain, hostname and thus fqdn from DNS - dns_fqdn=$(busybox timeout -t 3 rdns "$ip") - dns_short="${dns_fqdn%%.*}" - # check if it is fqdn - if [ "$dns_fqdn" == "$dns_short" ]; then - unset dns_fqdn dns_short - fi - - # Update resolver configuration file - conf_file="$(mktemp)" - # Own domain suffix - if [ -n "$domain" ]; then - : - elif [ -n "$dns_fqdn" ]; then - domain="${dns_fqdn#*.}" - - elif [ -n "$SLX_NET_DOMAIN" ]; then - domain="$SLX_NET_DOMAIN" - fi - if [ -n "$domain" ]; then - echo "domain ${domain%% *}" >> "${conf_file}" - fi - # Add domain to list of search domains if not in there yet - if [ -n "$domain" ] && [ -n "$search" ]; then - FOUND=no - for sd in $search; do - [ "x$sd" = "x$domain" ] && FOUND=yes - done - [ "$FOUND" = "no" ] && search="$domain $search" - elif [ -n "$domain" ]; then - search="$domain" - fi - # Search domains - if [ -n "$search" ]; then - echo "search $search" >> "${conf_file}" - elif [ -n "$SLX_NET_SEARCH" ]; then - echo "search $SLX_NET_SEARCH" >> "${conf_file}" - elif [ -n "$SLX_NET_DOMAIN" ]; then - echo "search $SLX_NET_DOMAIN" >> "${conf_file}" - fi - for i in $dns; do - echo "$0: Adding DNS $i" - echo "nameserver $i" >> "${conf_file}" - done - - if [ -x "/sbin/resolvconf" ] && [ -L "/etc/resolv.conf" ] && [ -d "/etc/resolvconf/update.d" ]; then - # Automatic handling :-) - resolvconf --create-runtime-directories - resolvconf --enable-updates - < "$conf_file" resolvconf -a "${interface}.udhcpc" - rm -- "$conf_file" - else - # Manual handling required :-( - mv -f "$conf_file" "$THIS_RESOLV" - rebuild_resolv_conf - fi - - # TODO: check if we really want/need to overwrite the PXE_IP, - # it might be better/clearer to change the SLX_DHCP_CLIENT_IP... - sed -i "s/^\(SLX_PXE_CLIENT_IP=\).*$/\1'$ip'/" /opt/openslx/config - # Write DOMAIN and SEARCH to /opt/openslx/config if empty - if [ -z "$SLX_NET_DOMAIN" ] && [ -n "$domain" ]; then - sed -i "/^SLX_NET_DOMAIN=/d" /opt/openslx/config - echo "SLX_NET_DOMAIN='$domain'" >> /opt/openslx/config - fi - if [ -z "$SLX_NET_SEARCH" ] && [ -n "$search" ]; then - sed -i "/^SLX_NET_SEARCH=/d" /opt/openslx/config - echo "SLX_NET_SEARCH='$search'" >> /opt/openslx/config - fi - # Same for WINS servers - if [ -z "$SLX_NET_WINS" ] && [ -n "$wins" ]; then - sed -i "/^SLX_NET_WINS=/d" /opt/openslx/config - echo "SLX_NET_WINS='$wins'" >> /opt/openslx/config - fi - - # TODO find a better way to trigger additional code, hook dir? - # Update /etc/issue for proper spacing - [ -x "/opt/openslx/scripts/openslx-create_issue" ] && /opt/openslx/scripts/openslx-create_issue - - # Remove any stray addresses; we expect the primary interface to only have one - # address supplied via DHCP. We do this after adding the new one, obviously. - rem_list=$( ip -o addr show "$interface" | awk '{ for (i=1;i<NF;++i) if ($i == "inet") print $(i+1) }' | grep -v "^${ip}/" ) - if [ -n "$rem_list" ]; then - echo "PRIMARY: Removing $rem_list since we just got assigned $ip" - echo 1 > "/proc/sys/net/ipv4/conf/$interface/promote_secondaries" - for addr in $rem_list; do - ip addr del "$addr" dev "$interface" - sed -i "/^$(escape_search "${addr%/*}")(\s|$)/d" /etc/hosts - done - fi - - # Write to openslx-config - echo "# Config written by openslx-dhcp-script (2)" >> /opt/openslx/config - sed -i "/^SLX_DNS=/d" /opt/openslx/config - echo "SLX_DNS='$dns'" >> /opt/openslx/config - ;; - - deconfig) - check_env "$1" - if [ "$interface" = "$primary" ]; then - echo "Ignoring deconfig for primary interface" - else - echo 1 > "/proc/sys/net/ipv4/conf/$interface/promote_secondaries" - clientip=${ip%%:*} - ip addr del "$clientip/$(ipcalc -s -p "$clientip" "$subnet" | sed s/.*=//)" dev "$interface" - sed -i "/^$(escape_search "$ip")(\s|$)/d" /etc/hosts - fi - - if [ -x /sbin/resolvconf ] && [ -L /etc/resolv.conf ] && [ -d /etc/resolvconf/update.d ]; then - # Automatic handling :-) - resolvconf -d "${interface}.udhcpc" - else - # Manual handling required :-( - rm -f -- "$THIS_RESOLV" - rebuild_resolv_conf - fi - ;; - - leasefail) - echo "$0: Lease failed: $message" >&2 - - ;; - - nak) - echo "$0: Received a NAK: $message" >&2 - - ;; - - *) - echo "$0: Unknown udhcpc command: $1" >&2 - exit 1 - - ;; -esac - -exit 0 - |
