From 954256c24170ea0cc91544a7e77f6ac241114d03 Mon Sep 17 00:00:00 2001 From: Ycarus Date: Thu, 16 Aug 2018 16:58:15 +0200 Subject: [PATCH] Autoconfig of usb ethernet device --- .../files/etc/hotplug.d/usb/30-omr-cdc_ether | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 openmptcprouter/files/etc/hotplug.d/usb/30-omr-cdc_ether diff --git a/openmptcprouter/files/etc/hotplug.d/usb/30-omr-cdc_ether b/openmptcprouter/files/etc/hotplug.d/usb/30-omr-cdc_ether new file mode 100644 index 000000000..0a692f57e --- /dev/null +++ b/openmptcprouter/files/etc/hotplug.d/usb/30-omr-cdc_ether @@ -0,0 +1,39 @@ +#!/bin/sh +# This file come from https://github.com/ovh/overthebox-feeds/blob/db4de152f0a63e2b1764d68e29b465611ab324ab/overthebox/files/etc/hotplug.d/usb/30-otb-cdc_ether +# with small changes. + +[ "$ACTION" = "add" ] || exit 0 +[ "$DRIVER" = "cdc_ether" ] || exit 0 + +log() { + logger -t "hotplug-otb-cdc_ether" -p 6 "$*" || true +} + +dev_path=$(find "/sys/${DEVPATH%/*}" -type d -name 'eth*') +dev_name=${dev_path##*/} +[ "$dev_name" ] || { + log "Failed to find the network card for $DEVPATH" + exit 1 +} + +if grep "$dev_name" /etc/config/network; then + log "$dev_name already configured" + exit 0 +fi + +# Get the first wanX available +_id=1 +while uci -q get network.wan$_id >/dev/null; do _id=$((_id+1)); done + +uci -q batch <<-EOF +set network.wan${_id}=interface +set network.wan${_id}.proto=dhcp +set network.wan${_id}.ifname=$dev_name +commit network + +del_list firewall.wan.network=wan$_id +add_list firewall.wan.network=wan$_id +commit firewall +EOF + +log "wan$_id ($dev_name) interface configured"