add some logging and turn off -x

pull/1/head
Jordan Sokolic 2020-02-14 10:18:25 +02:00
parent af6ad2f6ee
commit 55b2a8020c
1 changed files with 20 additions and 4 deletions

24
run.sh
View File

@ -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"
}