kdhcp/setup_deveth

51 lines
943 B
Plaintext
Raw Permalink Normal View History

2023-05-05 07:13:46 +00:00
#!/usr/bin/env bash
set -euxo pipefail
ensure_dummy_loaded () {
if [ -z "$(lsmod | grep dummy)"]
then
sudo modprobe dummy
fi
}
maybe_add_device () {
DEVICE="${1}"
if [ -z "$(ip --brief link | grep ${DEVICE})"]
then
sudo ip link add ${DEVICE} type dummy
fi
}
add_address () {
DEVICE="${1}"
ADDR="${2}"
EXISTING="$(ip --brief addr show "${DEVICE}" | awk '{print $3}')"
if [ ! -z "${EXISTING}" ]
then
if [ "${EXISTING}" == "${ADDR}" ]
then
return
fi
sudo ip addr flush dev "${DEVICE}"
fi
sudo ip link set dev "${DEVICE}" up
sudo ip addr add "${ADDR}" dev "${DEVICE}"
}
flush_device () {
DEVICE="${1}"
sudo ip addr flush dev "${DEVICE}"
sudo ip link set dev "${DEVICE}" down
}
ensure_dummy_loaded
maybe_add_device deveth0
maybe_add_device deveth1
add_address deveth0 192.168.4.250/24
flush_device deveth1