From 55b2a8020ccf707fbdab08012836ad0409198a87 Mon Sep 17 00:00:00 2001 From: Jordan Sokolic Date: Fri, 14 Feb 2020 10:18:25 +0200 Subject: [PATCH] add some logging and turn off -x --- run.sh | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/run.sh b/run.sh index c41cbbc..6438dc9 100755 --- a/run.sh +++ b/run.sh @@ -1,5 +1,4 @@ #!/bin/bash -set -x CONTAINER='openwrt_1' IFACE=$1 @@ -12,6 +11,7 @@ function _usage { function _get_phy_from_dev { if [[ -f /sys/class/net/$IFACE/phy80211/name ]] ; then PHY=$(cat /sys/class/net/$IFACE/phy80211/name 2>/dev/null) + echo "* got '$PHY' for device '$IFACE'" else echo "$IFACE is not a valid phy80211 device" exit 1 @@ -32,32 +32,48 @@ function _get_dev_from_phy { } function _cleanup { - docker stop openwrt_1 - while [[ -z $IFACE_NEW ]]; do + echo "* cleaning up..." + echo "* stopping container" + docker stop openwrt_1 >/dev/null + echo -n "* restoring network interface name" + retries=10 + while [[ retries -ge 0 && -z $IFACE_NEW ]]; do _get_dev_from_phy $PHY sleep 1 + let "retries--" + echo -n '.' done + if [[ $retries -eq 0 ]]; then + echo "\nERROR: problem restoring interface name, you may need to restore it manually." + exit 1 + fi sudo ip link set dev $IFACE_NEW down sudo ip link set dev $IFACE_NEW name $IFACE + echo "ok" + echo -ne "* finished" } function main { test -z $IFACE && _usage _get_phy_from_dev + + echo "* setting interface '$IFACE' to unmanaged" nmcli dev set $IFACE managed no + echo "* starting container" docker run --rm \ --network=bridge \ -p8080:80 -d \ --cap-add NET_ADMIN \ --cap-add NET_RAW \ --hostname openwrt\ - --name $CONTAINER openwrt + --name $CONTAINER openwrt >/dev/null pid=$(docker inspect -f '{{.State.Pid}}' $CONTAINER) sudo iw phy "$PHY" set netns $pid + echo "* ready" }