mirror of
https://git.proxmox.com/git/systemd
synced 2025-12-29 09:55:02 +00:00
Different cloud/desktop environments have different ways of including /etc/network/interfaces.d/, try to get along wit either and skip the test if interfaces.d/ does not get included at all.
57 lines
1.5 KiB
Bash
Executable File
57 lines
1.5 KiB
Bash
Executable File
#!/bin/sh
|
|
# check ifupdown integration for "allow-hotplug" interface
|
|
set -e
|
|
|
|
IFACE=sdtest42
|
|
|
|
if [ -e /sys/class/net/$IFACE ]; then
|
|
echo "SKIP: network interface $IFACE already exists"
|
|
exit 0
|
|
fi
|
|
|
|
# different kinds of installs/images have different conventions; e. g.
|
|
# cloud-init sources *.cfg, a Debian desktop sources only prefix-less files
|
|
if grep -q 'source-directory .*interfaces.d' /etc/network/interfaces; then
|
|
IFACE_CFG=/etc/network/interfaces.d/${IFACE}
|
|
elif grep -q 'source .*interfaces.d.*cfg' /etc/network/interfaces; then
|
|
IFACE_CFG=/etc/network/interfaces.d/${IFACE}.cfg
|
|
else
|
|
echo "SKIP: /etc/network/interfaces does not include interfaces.d/"
|
|
exit 0
|
|
fi
|
|
|
|
cat <<EOF > $IFACE_CFG
|
|
allow-hotplug $IFACE
|
|
iface $IFACE inet static
|
|
address 192.168.234.129
|
|
netmask 255.255.255.0
|
|
EOF
|
|
|
|
# these should trigger uevents and ifup@.service
|
|
ip link add name $IFACE type veth peer name v$IFACE
|
|
trap "ip link del dev $IFACE; rm $IFACE_CFG" EXIT INT QUIT PIPE
|
|
|
|
sleep 3
|
|
|
|
# $IFACE is configured in ifupdown, should succeed and be up
|
|
systemctl status -l ifup@${IFACE}.service
|
|
ifquery --state $IFACE
|
|
|
|
OUT=$(ip a show dev $IFACE)
|
|
if ! echo "$OUT" | grep -q 'inet 192.168.234.129/24'; then
|
|
echo "interface $IFACE not configured" >&2
|
|
echo "$OUT" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# v$IFACE is not configured in ifupdown, should be down
|
|
! ifquery --state v$IFACE
|
|
! systemctl status -l ifup@v${IFACE}.service
|
|
|
|
OUT=$(ip a show dev v$IFACE)
|
|
if echo "$OUT" | grep -q 'inet'; then
|
|
echo "interface $IFACE unexpectedly configured" >&2
|
|
echo "$OUT" >&2
|
|
exit 1
|
|
fi
|