diff options
Diffstat (limited to 'automated')
-rwxr-xr-x | automated/utils/vland/get_vland_interface.sh | 56 | ||||
-rwxr-xr-x | automated/utils/vland/get_vland_mac.sh | 11 |
2 files changed, 67 insertions, 0 deletions
diff --git a/automated/utils/vland/get_vland_interface.sh b/automated/utils/vland/get_vland_interface.sh new file mode 100755 index 0000000..fcca95a --- /dev/null +++ b/automated/utils/vland/get_vland_interface.sh @@ -0,0 +1,56 @@ +#!/bin/sh + +set -e + +get_vland_entry() { + lava-vland-names | grep "^${1}" | cut -d , -f 2 +} + +get_vland_sys_path() { + vland_entries=$(get_vland_entry "${1}") + if [ -z "${vland_entries}" ]; then + echo "No valid vland name given" >&2 + echo "Alternatives are:" >&2 + get_vland_names >&2 + exit 1 + fi + lava-vland-self | grep -F "${vland_entries}" | cut -d , -f 3- +} + +get_vland_interface() { + sys_path=$(get_vland_sys_path "${1}") + find "${sys_path}" -maxdepth 1 -mindepth 1 -type d | sed -e 's|.*/||g' +} + +get_vland_names() { + lava-vland-names | cut -d , -f 1 | grep -v "^$" +} + +## +# Main entry point + +vland_name=${1} + +if [ -z "$(which lava-vland-names 2>/dev/null)" ]; then + echo "Not in LAVA" + exit 1 +fi + +if [ -n "${vland_name}" ]; then + ret=$(get_vland_interface "${vland_name}") + if [ -n "${ret}" ]; then + echo "${ret}" + exit 0 + fi + echo "No such vland: $vland_name" >&2 + exit 1 +fi + +if [ "$(get_vland_names|wc -l)" -ne 1 ]; then + echo "More then one vland name available" >&2 + echo "Alternatives are:" >&2 + get_vland_names >&2 + exit 1 +else + get_vland_interface "$(get_vland_names)" +fi diff --git a/automated/utils/vland/get_vland_mac.sh b/automated/utils/vland/get_vland_mac.sh new file mode 100755 index 0000000..cb96939 --- /dev/null +++ b/automated/utils/vland/get_vland_mac.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +set -e + +vland_name="${1}" + +iface=$("$(readlink -f "$(dirname "$0")")"/get_vland_interface.sh "${vland_name}") +if [ -z "${iface}" ]; then + exit 1 +fi +cat /sys/class/net/"${iface}"/address |