Created
October 2, 2022 14:16
-
-
Save stargieg/28635856c8a50d68d533c660de3560f3 to your computer and use it in GitHub Desktop.
convert network config to DSA https://openwrt.org/releases/21.02/notes-21.02.0#new_network_configuration_syntax_and_boardjson_change
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
. /lib/functions.sh | |
. /usr/share/libubox/jshn.sh | |
. /etc/openwrt_release | |
uci_add_list() { | |
local PACKAGE="$1" | |
local CONFIG="$2" | |
local OPTION="$3" | |
local VALUE="$4" | |
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} add_list "$PACKAGE.$CONFIG.$OPTION=$VALUE" | |
} | |
log() { | |
logger -s -t convert $@ | |
} | |
setup_ether() { | |
local cfg="$1" | |
local type | |
local ifname | |
type=$(uci_get network $cfg type) | |
ifname=$(uci_get network $cfg ifname) | |
if [ "$type" == "bridge" ] ; then | |
uci_remove network $cfg type | |
uci_set network $cfg device "br-$cfg" | |
uci_add network device ; cfg_dev="$CONFIG_SECTION" | |
uci_set network $cfg_dev type "bridge" | |
uci_set network $cfg_dev name "br-$cfg" | |
for i in $ifname ; do | |
log "$cfg $ifname" | |
uci_add_list network $cfg_dev ports "$i" | |
done | |
uci_remove network $cfg ifname | |
else | |
if [ -n "$ifname" ] ; then | |
log "$cfg $ifname" | |
uci_set network $cfg device "$ifname" | |
uci_remove network $cfg ifname | |
fi | |
fi | |
} | |
case $DISTRIB_RELEASE in | |
22.03.*) | |
config_load network | |
config_foreach setup_ether interface | |
uci_commit network | |
;; | |
*) | |
log "Wrong version $DISTRIB_RELEASE needs 22.03.*" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment