#!/bin/sh # # Copyright (C) 2018 holger@freifunk-berlin # taken from https://github.com/openwrt-mirror/openwrt/blob/95f36ebcd774a8e93ad2a1331f45d1a9da4fe8ff/target/linux/ar71xx/base-files/etc/uci-defaults/02_network#L83 # # This script should set a wan-Port if u want to share ur internet-connection. # It should run after wizard did the necessary settings (sharenet = yes) . /lib/functions.sh # what shall I do? AUTOCOMMIT="no" while getopts "c" option; do case "$option" in c) AUTOCOMMIT="yes" ;; *) echo "Invalid argument '-$OPTARG'." exit 1 ;; esac done shift $((OPTIND - 1)) echo "usage $0 -c [commit]" # checks if a list (result of a uci query; space-separated string) contains a given value _option_contains_() { local value=$2 local list=$1 local item for item in ${list}; do [[ "${item}" = "${value}" ]] && return 0 done return 1 } # redefines the assignment of the VLANs of the switch ports # e.g. eth0.1: from switchport 4 to port 5 (TPLink CPE) swap_port_switch() { local port1=$1 local port2=$2 local port_section="" local port1_section local port2_section is_interface_of() { local port=$2 local result_ports local result_vlan config_get result_ports $1 ports config_get result_vlan $1 vlan echo "checking interface $1" echo " vlan \"$result_vlan\" has ports \"$result_ports\"" _option_contains_ "${result_ports}" ${port} || { echo " -> not found"; port_section="$1 $port_section"; } } config_load "network" config_foreach is_interface_of "switch_vlan" $port1 port1_section=$port_section port_section="" config_foreach is_interface_of "switch_vlan" $port2 port2_section=$port_section port_section="" echo "---" echo "found port $port1 in config-section \"$port1_section\"" echo "found port $port2 in config-section \"$port2_section\"" echo "---" for section in $port1_section; do local current_ports=$(uci get network.$section.ports) local new_ports echo "change section $section" echo " current ports: $current_ports" echo " replacing $port1 with $port2" new_ports=$(echo $current_ports | tr $port2 $port1) uci set network.$section.ports="$new_ports" done for section in $port2_section; do local current_ports=$(uci get network.$section.ports) local new_ports echo "change section $section" echo " current ports: $current_ports" echo " replacing $port2 with $port1" new_ports=$(echo $current_ports | tr $port1 $port2) uci set network.$section.ports="$new_ports" done } # swaps the assignment of pyhsical ports of the device # e.g. eth0 <--> eth1 (NSM) swap_port_physical() { local port1=$1 local port2=$2 local port1_interfaces="" local port2_interfaces="" interfaces_of_dev() { local device=$1 lua <