mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-02-15 03:51:51 +00:00
39 lines
984 B
Bash
39 lines
984 B
Bash
#!/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"
|