Skip to content

Instantly share code, notes, and snippets.

@stargieg
Created October 2, 2022 14:16
Show Gist options
  • Save stargieg/28635856c8a50d68d533c660de3560f3 to your computer and use it in GitHub Desktop.
Save stargieg/28635856c8a50d68d533c660de3560f3 to your computer and use it in GitHub Desktop.
#!/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