From a097b292e920d3efc0baeb60edbaab03af0ee923 Mon Sep 17 00:00:00 2001 From: Jordan Sokolic Date: Fri, 14 Feb 2020 12:24:19 +0200 Subject: [PATCH] configure on startup using rc.local --- .env | 17 +++++++++++++++++ Dockerfile | 1 + etc/config/wireless | 9 +-------- etc/rc.local | 20 ++++++++++++++++++++ run.sh | 24 ++++++++++++++++++------ 5 files changed, 57 insertions(+), 14 deletions(-) create mode 100644 .env create mode 100755 etc/rc.local diff --git a/.env b/.env new file mode 100644 index 0000000..523f1ee --- /dev/null +++ b/.env @@ -0,0 +1,17 @@ +# general +CONTAINER=openwrt_1 + +# docker network settings +NET_NAME=openwrt_net +NET_SUBNET=192.168.99.0/24 +NET_ADDR=192.168.99.2 +NET_GW=192.168.99.1 +# openwrt doesn't accept CIDR notation; must match NET_SUBNET +NET_NETMASK=255.255.255.0 + +# wifi settings +WIFI_SSID=test123 +WIFI_ENCRYPTION=psk2 +WIFI_KEY=12345678 +WIFI_HW_MODE=11a +WIFI_CHANNEL=36 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index b31eee0..2ed9ce6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,4 +11,5 @@ RUN opkg update && \ iperf3 COPY etc/config/network /etc/config/network COPY etc/config/wireless /etc/config/wireless +COPY etc/rc.local /etc/rc.local CMD [ "/sbin/init" ] \ No newline at end of file diff --git a/etc/config/wireless b/etc/config/wireless index 9da8cf8..e69d5a7 100644 --- a/etc/config/wireless +++ b/etc/config/wireless @@ -1,14 +1,7 @@ config 'wifi-device' 'radio0' option 'type' 'mac80211' - option 'macaddr' '18:d6:c7:1b:dc:95' - option 'hwmode' '11a' - option 'channel' '36' - option 'vhtmode' 'VHT20' config 'wifi-iface' 'wl0' option 'device' 'radio0' option 'network' 'lan' - option 'mode' 'ap' - option 'ssid' 'test123' - option 'encryption' 'psk2' - option 'key' '12345678' \ No newline at end of file + option 'mode' 'ap' \ No newline at end of file diff --git a/etc/rc.local b/etc/rc.local new file mode 100755 index 0000000..52bb5c3 --- /dev/null +++ b/etc/rc.local @@ -0,0 +1,20 @@ +# Put your custom commands here that should be executed once +# the system init finished. By default this file does nothing. + +/sbin/uci batch </dev/null - echo -n "* restoring network interface name" + echo "* deleting network" + docker network rm $NET_NAME >/dev/null + echo -n "* restoring network interface name.." retries=10 while [[ retries -ge 0 && -z $IFACE_NEW ]]; do _get_dev_from_phy $PHY @@ -43,13 +46,13 @@ function _cleanup { let "retries--" echo -n '.' done - if [[ $retries -eq 0 ]]; then - echo "\nERROR: problem restoring interface name, you may need to restore it manually." + if [[ $retries -lt 0 ]]; then + echo -e "\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 " ok" echo -ne "* finished" } @@ -61,10 +64,19 @@ function main { echo "* setting interface '$IFACE' to unmanaged" nmcli dev set $IFACE managed no + echo "* setting up docker network" + docker network create --driver bridge \ + --gateway $NET_GW \ + --subnet $NET_SUBNET \ + $NET_NAME + echo "* starting container" docker run --rm \ - --network=bridge \ + --network $NET_NAME \ + -p2222:22 \ -p8080:80 -d \ + --env-file .env \ + -e WIFI_PHY=$PHY \ --cap-add NET_ADMIN \ --cap-add NET_RAW \ --hostname openwrt\