add changes that were missing in the last commit
authorManuel Munz <munz@comuno.net>
Sat, 30 May 2015 15:01:02 +0000 (17:01 +0200)
committerManuel Munz <munz@comuno.net>
Mon, 22 Jun 2015 21:45:03 +0000 (23:45 +0200)
contrib/package/meshwizard/Makefile
contrib/package/meshwizard/files/usr/bin/meshwizard/functions.sh
contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/read_defaults.sh
contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/rename-wifi.sh
contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_firewall.sh
contrib/package/meshwizard/files/usr/bin/meshwizard/wizard.sh

index 9d74fe54795e24d33d51d009857102ff204daa00..6959c544cfb98130715017821e954b8801e6bc0d 100644 (file)
@@ -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)
 
index 8abdf9f0e772bb4fe20dcd24c56fe70116c733f5..8ace21853d3d1c615b8c5c4604cf056e42f5cbd9 100644 (file)
@@ -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
+}
index cb0d319a2d8bf61e67ad772ada9df36a917f3165..b6ffb62e4afdf733f79de37ef71790c8febafc14 100755 (executable)
@@ -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"
+}
index ea200559e751565e746c8f6fe0201f88880361d9..e9139ed510f186d6bd8d1fc5bcb552196f182775 100755 (executable)
@@ -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
                ;;
index bf47241122af4a079bb3c2d4b7ed995f23461ec4..52659457d17d5f23b29c23db05a34ae4f04db929 100755 (executable)
@@ -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
index 77c6cd95e90e4f977aed4546a58b2e23acc61c45..b666313e460e2a538eed8d8a10f3adfcf07c8953 100755 (executable)
@@ -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