configure on startup using rc.local

pull/1/head
Jordan Sokolic 2020-02-14 12:24:19 +02:00
parent 55b2a8020c
commit a097b292e9
5 changed files with 57 additions and 14 deletions

17
.env 100644
View File

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

View File

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

View File

@ -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'
option 'mode' 'ap'

20
etc/rc.local 100755
View File

@ -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 <<EOF
set network.lan.ipaddr=$NET_ADDR
set network.lan.gateway=$NET_GW
set network.lan.netmask=$NET_NETMASK
set wireless.radio0.phy=$WIFI_PHY
set wireless.radio0.hwmode=$WIFI_HW_MODE
set wireless.radio0.channel=$WIFI_CHANNEL
set wireless.wl0.ssid=$WIFI_SSID
set wireless.wl0.encryption=$WIFI_ENCRYPTION
set wireless.wl0.key=$WIFI_KEY
EOF
/sbin/uci commit
/etc/init.d/network restart
exit 0

24
run.sh
View File

@ -1,6 +1,7 @@
#!/bin/bash
set -x
CONTAINER='openwrt_1'
source .env
IFACE=$1
function _usage {
@ -35,7 +36,9 @@ function _cleanup {
echo "* cleaning up..."
echo "* stopping container"
docker stop openwrt_1 >/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\