diff options
author | Manuel Munz <munz@comuno.net> | 2015-05-30 17:01:02 +0200 |
---|---|---|
committer | Manuel Munz <munz@comuno.net> | 2015-05-30 17:01:02 +0200 |
commit | d447b7e9f27c05c9f091c95a296a04126234d16d (patch) | |
tree | 8a202ca8026168b514198f6bfb0bec63708ce322 /contrib | |
parent | 0eef4678714c05feb18c6b46551bc39cf3ce33ea (diff) |
add changes that were missing in the last commit
Diffstat (limited to 'contrib')
6 files changed, 153 insertions, 64 deletions
diff --git a/contrib/package/meshwizard/Makefile b/contrib/package/meshwizard/Makefile index 9d74fe547..6959c544c 100644 --- a/contrib/package/meshwizard/Makefile +++ b/contrib/package/meshwizard/Makefile @@ -4,7 +4,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=meshwizard -PKG_RELEASE:=0.1.1 +PKG_RELEASE:=0.3.0 PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/functions.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/functions.sh index 8abdf9f0e..8ace21853 100644 --- a/contrib/package/meshwizard/files/usr/bin/meshwizard/functions.sh +++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/functions.sh @@ -12,6 +12,21 @@ uci_remove_list_element() { done } +# string_contains(string, substring) +# +# Returns 0 if the specified string contains the specified substring, +# otherwise returns 1. +string_contains() { + string="$1" + substring="$2" + if test "${string#*$substring}" != "$string" + then + return 0 # $substring is in $string + else + return 1 # $substring is not in $string + fi +} + # Takes 2 arguments # $1 = text to be displayed in the output for this section # $2 = section (optional) @@ -29,11 +44,18 @@ set_defaults() { a="$(echo $option |cut -d '=' -f1)" b="$(echo $option |cut -d '=' -f2-)" b="${b//_/ }" - uci set $2.$a="$b" + string_contains "$a" "_LENGTH" && return + string_contains "$a" "_ITEM" && { + # special threatment for lists. use add_list and remove the + # item index (_ITEMx). + uci add_list $2.${a//_ITEM[0-9]*/}="$b" + } || { + uci set $2.$a="$b" + } done } -# 3 arguements: 1=config name 2=oldname 3=newname +# 3 arguments: 1=config name 2=oldname 3=newname section_rename() { uci -q rename $1.$2=$3 && msg_rename $1.$2 $1.$3 || msg_rename_error $1.$2 $1.$3 } @@ -57,3 +79,40 @@ msg_rename() { msg_rename_error() { echo " \033[1mWarning:\033[0m Could not rename $1 to $2." } + + +restore_factory_defaults() { + echo "+ Restore default config as requested with cleanup=1" + cp -f /rom/etc/config/* /etc/config/ + rm /etc/config/wireless + wifi detect > /etc/config/wireless + rm /etc/config/network + if [ -f /etc/init.d/defconfig ]; then + # legacy (AA) + /etc/init.d/defconfig start + [ -f /rom/etc/uci-defaults/network ] && sh /rom/etc/uci-defaults/network + else + sh /rom/etc/uci-defaults/02_network + fi +} + +is_in_list() { + # checks if an item is in a list + local list="$1" + local item="$2" + for word in $list; do + [ $word = "$item" ] && return 0 + done + return 1 +} + +add_to_list() { + local list="$1" + local item="$2" + is_in_list "$list" "$item" && echo $list + if [ -z "$list" ]; then + echo "$item" + else + echo "$list $item" + fi +} diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/read_defaults.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/read_defaults.sh index cb0d319a2..b6ffb62e4 100755 --- a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/read_defaults.sh +++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/read_defaults.sh @@ -1,35 +1,61 @@ #!/bin/sh -# This reads the settings we need to have to configure everything -# Argument $1: community +# These functions read the settings we need for configuration of the router -. /lib/functions.sh -community="$1" +read_defaults() { + # read default values from the 3 relevant config files and export them + # into the environment. Later loaded configs overwrite earlier ones. The + # The ordering here is from most generic to most specific: + # freifunk (most generic defaults) + # profile_* (community defaults) + # nodes custom config from meshwizard config file -# reads variables from uci files, parameter $1 is the section -get_var() { - uci -q show $1 | cut -d "." -f 2-100 |grep "\." | sed -e 's/^\([A-Za-z0-9_]*\)\./\1_/g' -e 's/=\(.*\)$/="\1"/g' -} - -handle_widgets() { - widgets="$widgets $1" -} -config_load freifunk -config_foreach handle_widgets widget -config_load profile_$community -config_foreach handle_widgets widget -echo "widgets=$widgets" + local community="$1" -# read default values from /etc/config/freifunk -for v in system wifi_device wifi_iface interface alias dhcp olsr_interface olsr_interfacedefaults zone_freifunk include $widgets; do - get_var freifunk.$v -done + config_cb() { + local type="$1" + local name="$2" + local allowed_section_types="widget" + local allowed_section_names=" + system + wifi_device + wifi_iface + interface + alias + dhcp + olsr_interface + olsr_interfacedefaults + profile + zone_freifunk + include + luci_splash + ipv6 + luci_main + contact + community + wan + lan + general + ipv6 + qos + " -# now read all values from the selected community profile, will override some values from the defaults before -for v in system wifi_device wifi_iface interface alias dhcp olsr_interface olsr_interfacedefaults profile zone_freifunk include luci_splash ipv6 $widgets; do - get_var profile_$community.$v -done + if [ "$type" = "widget" ]; then + widgets=$(add_to_list "$widgets" "$name") + fi -# read values from meshwizard -for v in system luci_main contact community wan lan general ipv6 qos; do - get_var meshwizard.$v -done + if ([ -n "$name" ] && is_in_list "$allowed_section_names" $name) \ + || is_in_list "$allowed_section_types" $type ; then + option_cb() { + local option="$1" + local value="$2" + export "${CONFIG_SECTION}_${option}"="$value" + } + else + option_cb() { return; } + fi + } + config_load freifunk + config_load profile_${community} + config_load meshwizard + export widgets="$widgets" +} diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/rename-wifi.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/rename-wifi.sh index ea200559e..e9139ed51 100755 --- a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/rename-wifi.sh +++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/rename-wifi.sh @@ -33,7 +33,7 @@ for i in `seq 0 $posIB`; do uci show meshwizard.netconfig | grep $IBwifi | while read line; do oldline=$(echo $line | cut -d "=" -f 1) uci set $oldline="" - newline=$(echo $line |sed "s/$IBwifi/$syswifi/g") + newline=$(echo $line |sed -e "s/$IBwifi/$syswifi/g" -e "s/'//g") uci set $newline done ;; diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_firewall.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_firewall.sh index bf4724112..52659457d 100755 --- a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_firewall.sh +++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_firewall.sh @@ -80,23 +80,30 @@ if [ ! "$no_masq_lan" == "1" ] && [ ! "$(uci -q get meshwizard.netconfig.lan_con fi -# Rules, Forwardings, advanced config and includes - -for config in freifunk profile_$community; do - - config_load $config - - for section in advanced include fw_rule fw_forwarding; do - handle_firewall() { - local options=$(uci show $config."$1") - options=$(echo "$options" | sed -e "s/fw_//g" -e "s/^$config/firewall/g") - for o in $options; do - uci set $o - done - } - config_foreach handle_firewall $section - done -done +# Rules, Forwardings, advanced config and includes from freifunk and +# profile_$community config files. + +add_fw_rules() { + config_cb() { + local type="$1" + local name="$2" + local allowed_section_types="advanced include fw_rule fw_forwarding" + if is_in_list "$allowed_section_types" $type ; then + uci set firewall.${name}="${type/fw_/}" + option_cb() { + local option="$1" + local value="$2" + uci set firewall.${CONFIG_SECTION}.${option}="$value" + } + else + option_cb() { return; } + fi + } + config_load freifunk + config_load profile_${community} +} +add_fw_rules + # If we use auto-ipv6-dhcp then allow 547/udp on the freifunk zone if [ "$ipv6_config" = "auto-ipv6-dhcpv6" ]; then diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/wizard.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/wizard.sh index 77c6cd95e..b666313e4 100755 --- a/contrib/package/meshwizard/files/usr/bin/meshwizard/wizard.sh +++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/wizard.sh @@ -9,15 +9,16 @@ # You may not use this file except in compliance with the License. # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -. /lib/functions.sh - echo " -/* Meshwizard 0.2.0 */ +/* Meshwizard 0.3.0 */ " # config export dir="/usr/bin/meshwizard" + +. /lib/functions.sh . $dir/functions.sh +. $dir/helpers/read_defaults.sh [ -f /proc/net/ipv6_route ] && export has_ipv6=1 # Check which packages we have installed @@ -28,30 +29,26 @@ opkg list_installed |grep luci-app-splash > /dev/null && export has_luci_splash= # Check whether we want to cleanup/restore uci config before setting new options cleanup=$(uci -q get meshwizard.general.cleanup) -[ "$cleanup" == 1 ] && $dir/helpers/restore_default_config.sh +[ "$cleanup" == 1 ] && restore_factory_defaults # Rename wifi interfaces $dir/helpers/rename-wifi.sh # Get community -community=$(uci -q get meshwizard.community.name || uci -q get freifunk.community.name) +community="$(uci -q get meshwizard.community.name || uci -q get freifunk.community.name)" [ -z "$community" ] && echo "Error: Community is not set in /etc/config/freifunk, aborting now." && exit 1 export community="$community" -echo $community + +# we need a list of widgets later on. It will be populated in read_defaults.sh +local widgets="" # Get a list of networks we need to setup networks=$(uci show meshwizard.netconfig | grep -v "netconfig=" | sed -e 's/meshwizard.netconfig\.\(.*\)\_.*/\1/' |sort|uniq) export networks [ -z "$networks" ] && echo "Error: No networks to setup could be found in /etc/config/meshwizard, aborting now." && exit 1 -# Read default values (first from /etc/config/freifunk, then from /etc/config/profile_$community -# then /etc/config/meshwizard -# last will overwrite first - -$dir/helpers/read_defaults.sh $community > /tmp/meshwizard.tmp -while read line; do - export "${line//\"/}" -done < /tmp/meshwizard.tmp +# Read defaults and node config +read_defaults $community # Do config $dir/helpers/initial_config.sh |