contrib/meshwizard: Various fixes and cleanups
authorManuel Munz <freifunk@somakoma.de>
Thu, 6 Oct 2011 19:38:12 +0000 (19:38 +0000)
committerManuel Munz <freifunk@somakoma.de>
Thu, 6 Oct 2011 19:38:12 +0000 (19:38 +0000)
12 files changed:
contrib/package/meshwizard/files/usr/bin/meshwizard/functions.sh
contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/initial_config.sh
contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/rename-wifi.sh
contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_dhcp.sh
contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_firewall.sh
contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_freifunk.sh [deleted file]
contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_network.sh
contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_olsrd.sh
contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_splash.sh
contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_system.sh
contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_wifi.sh
contrib/package/meshwizard/files/usr/bin/meshwizard/wizard.sh

index fbb36ebe55a4f60d723dcfc8e119bc036462e94c..f8271498adae0ed34e73c9d6b7c36dfefbc95ecf 100644 (file)
@@ -33,24 +33,11 @@ set_defaults() {
        done
 }
 
-# 1 argument: section to remove
-section_cleanup() {
-       uci -q delete $1 && msg_cleanup $1 || msg_cleanup_error $1
-}
-
 # 3 arguements: 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
 }
 
-msg_cleanup() {
-       echo "    Cleanup: Removed section $1."
-}
-
-msg_cleanup_error() {
-       echo -e "    \033[1mWarning:\033[0m Cleanup of $1 failed."
-}
-
 msg_missing_value() {
        echo -e "    \033[1mWarning:\033[0m Configuration option for $2 is missing in $1."
 }
index 12b9148ab27821f12609218dbe85914f81e4d5e4..6c442e0a96313af511e8e9f340d5b8b55f43bdb3 100755 (executable)
@@ -2,12 +2,9 @@
 # This is only run once (usually after flashing an image from the imagebuilder)
 # It sets up the initial config for this node.
 
-
 . /etc/functions.sh
 . $dir/functions.sh
 
-### System config
-
 config_load system
 
 # Rename system config
@@ -19,24 +16,18 @@ handle_system() {
 config_foreach handle_system system
 
 if [ -n "$(uci -q get meshwizard.community)" ]; then
-       echo "    + Setup community"
        set_defaults "community_" freifunk.community
        uci -q delete meshwizard.community
-       uci_commitverbose freifunk
 fi
+[ -n "$profile_homepage" ] && uci set freifunk.community.homepage="$profile_homepage"
+uci_commitverbose "Setup community" freifunk
 
 if [ -n "$(uci -q get meshwizard.contact)" ]; then
-       echo "    + Setup contact"
        set_defaults "contact_" freifunk.contact
-       uci -q delete meshwizard.contact && uci_commitverbose freifunk
+       uci -q delete meshwizard.contact && uci_commitverbose "Setup contact" freifunk
 fi
 
 if [ "$has_luci" == TRUE ]; then
-       echo "    + Setup luci"
        set_defaults "luci_main_" luci.main
-       uci -q delete meshwizard.luci_main && uci_commitverbose luci
+       uci -q delete meshwizard.luci_main && uci_commitverbose "Setup luci" luci
 fi
-
-uci commit
-
-
index aee15f5b74f6abf14a677828cd880f49e74cb244..872b36c466d011bba3f3a0895936bd5472f16733 100755 (executable)
@@ -2,9 +2,12 @@
 # This script renames IB_wifi_ interface names into real interface names used on this system.
 # E.g. wireless.IB_wifi0 would become wireless.wifi0 on madwifi and wireless.radio0 on mac80211
 
+. $dir/functions.sh
+
 posIB=-1
 
 IBwifis="$(uci show meshwizard.netconfig | grep -v 'netconfig=netconfig' | sed 's/meshwizard.netconfig\.\(IB_wifi.*\)_.*/\1/' |uniq)"
+[ -z "$(echo $IBwifis |grep IB_wifi)" ] && exit
 
 for w in $IBwifis; do
        posIB=$(( $posIB + 1 ))
@@ -40,4 +43,4 @@ for i in `seq 0 $posIB`; do
        fi
 done
 
-uci commit
+uci_commitverbose "Renaming wifi-devices in /etc/config/meshwizard" meshwizard
index 06f80d850b44444e3fd411d50f4fb9e5b4466636..51fb235c14ec3610e22c90c669607935562818eb 100755 (executable)
@@ -9,24 +9,20 @@ net="$1"
 handle_dnsmasq() {
        config_get interface "$1" interface
        if [ "$interface" == "${netrenamed}dhcp" ]; then
-               if [ "$cleanup" == 1 ]; then
-                       section_cleanup dhcp.$1
-               else
-                       if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
-                               section_rename dhcp $1 ${netrenamed}dhcp
-                        fi
-                fi
-        fi
+               if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
+                       section_rename dhcp $1 ${netrenamed}dhcp
+               fi
+       fi
 }
 config_load dhcp
 config_foreach handle_dnsmasq dhcp
 
 uci batch << EOF
 set dhcp.${netrenamed}dhcp="dhcp"
-set dhcp.${netrenamed}dhcp.leasetime="$dhcp_leasetime"
-set dhcp.${netrenamed}dhcp.force="$dhcp_force"
 set dhcp.${netrenamed}dhcp.interface="${netrenamed}dhcp"
 EOF
 
+set_defaults "dhcp_" dhcp.${netrenamed}dhcp
+
 uci_commitverbose "Setup DHCP for $netrenamed" dhcp
 
index e7e453d1c21ad665cd79c1aad8282bd7b0edb261..e3eb6a779361ef67f6e0d5526a31cf5257511d23 100755 (executable)
@@ -27,48 +27,24 @@ handle_fwzone() {
        config_get network "$1" network
 
        if [ "$2" == "zoneconf" ]; then
-               # clean zone
                if [ "$name" == "freifunk" ]; then
-                       if [ "$cleanup" == 1 ]; then
-                               section_cleanup firewall.$1
-                       else
-                               # rename section if unnamed
-                               if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
-                                       section_rename firewall $1 zone_freifunk
-                               fi
+                       # rename section if unnamed
+                       if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
+                               section_rename firewall $1 zone_freifunk
                        fi
                else
-
-                       if [ "$name" == "$netrenamed" ]; then
-                               section_cleanup firewall.$1
-                       fi
                        if [ -n "$netrenamed" -a -n "$(echo $network | grep $netrenamed)" ] && [ ! "$name" == "freifunk" ]; then
                                echo "    Removed $netrenamed from firewall zone $name."
                                network_new=$(echo $network | sed -e 's/'$netrenamed'//' -e 's/^ //' -e 's/  / /' -e 's/ $//')
                                uci set firewall.$1.network="$network_new"
                        fi
                fi
-       else
-               # clean fw_rule, fw_forwarding, include and advanced
-               for option in src tcp_ecn path; do
-                       config_get $option $1 $option
-               done
-               if [ "$src" == "freifunk" -o "$path" == "/etc/firewall.freifunk" -o -n "$tcpecn" ]; then
-                       section_cleanup firewall.$1
-               fi
        fi
 }
 
 config_foreach handle_fwzone zone zoneconf
 
-if [ "$cleanup" == 1 ]; then
-       for target in include advanced rule forwarding; do
-               config_foreach handle_fwzone $target
-       done
-fi
-
 # setup freifunk firewall zone
-
 # add $netrenamed and if needed ${netrenamed}dhcp to the networks for this zone
 config_get network zone_freifunk network
 
@@ -152,3 +128,4 @@ for config in freifunk profile_$community; do
 done
 
 uci_commitverbose "Setup rules, forwardings, advanced config and includes." firewall
+
diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_freifunk.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_freifunk.sh
deleted file mode 100755 (executable)
index e4bd87f..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/sh
-# Sets values in /etc/config/freifunk
-
-. $dir/functions.sh
-
-# Set community homepage
-
-if [ -n "$profile_homepage" ]; then
-       uci set freifunk.community.homepage="$profile_homepage"
-fi
-
-uci_commitverbose freifunk
-
index 493c701b2539210a15d5d98bf1cdb3d74187e28b..1492cbbb0d394d2b7afc9832020e00597f3c20f0 100755 (executable)
@@ -5,11 +5,6 @@ net="$1"
 . /etc/functions.sh
 . $dir/functions.sh
 
-# Delete the network interface section for $net
-if [ "$cleanup" == 1 ]; then
-       section_cleanup network.$netrenamed
-fi
-
 # Setup a (new) interface section for $net
 
 ipaddr=$(uci get meshwizard.netconfig.$net\_ip4addr)
@@ -20,10 +15,8 @@ uci batch << EOF
 set network.$netrenamed="interface"
 set network.$netrenamed.proto="static"
 set network.$netrenamed.ipaddr="$ipaddr"
-set network.$netrenamed.netmask="$interface_netmask"
-set network.$netrenamed.dns="$interface_dns"
 EOF
-
+set_defaults "interface_" network.$netrenamed
 uci_commitverbose "Setup interface $netrenamed" network
 
 # setup dhcp alias/interface
@@ -36,16 +29,12 @@ if [ "$net_dhcp" == 1 ]; then
        interface_ip="$(uci -q get meshwizard.netconfig.${net}_ip4addr)"
        vap=$(uci -q get meshwizard.netconfig.${net}_vap)
 
-       # Clean/rename config
+       # Rename config
        handle_dhcpalias() {
                        config_get interface "$1" interface
                        if [ "$interface" == "$netrenamed" ]; then
-                               if [ "$cleanup" == 1 ]; then
-                                       section_cleanup network.$1
-                               else
-                                       if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
-                                               section_rename network $1 ${netrenamed}dhcp
-                                       fi
+                               if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
+                                       section_rename network $1 ${netrenamed}dhcp
                                fi
                        fi
        }
index 06cc2e58c238208f6c2ef415d257fdd9449bfb75..ba11b5174a93dcf04f94ee9e68c8c0f56e579619 100755 (executable)
@@ -7,33 +7,25 @@ net=$1
 . /etc/functions.sh
 . $dir/functions.sh
 
-# Clean or delete interface defaults
+# Rename interface defaults
 handle_interfacedefaults() {
-       if [ "$cleanup" == 1 ]; then
-               section_cleanup olsrd.$1
-       else
-               if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
-                       section_rename olsrd $1 InterfaceDefaults
-                fi
+       if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
+               section_rename olsrd $1 InterfaceDefaults
        fi
 }
-
 config_load olsrd
 config_foreach handle_interfacedefaults InterfaceDefaults
 
 # Setup new InterfaceDefaults
-
 uci set olsrd.InterfaceDefaults=InterfaceDefaults
 set_defaults "olsr_interfacedefaults_" olsrd.InterfaceDefaults
 uci_commitverbose "Setup olsr interface defaults" olsrd
 
-# Delete old interface for $netrenamed
+# Rename interface for $netrenamed
 handle_interface() {
        config_get interface "$1" Interface
        if [ "$interface" == "$netrenamed" ]; then
-               if [ "$cleanup" == 1 ]; then
-                       section_cleanup olsrd.$1
-               elif [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
+               if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
                        section_rename olsrd $1 $netrenamed
                fi
        fi
@@ -58,6 +50,7 @@ uci -q delete olsrd.${netrenamed}clients
 # check if the dhcprange is inside meshnet
 dhcpinmesh="$($dir/helpers/check-range-in-range.sh $dhcprange $meshnet)"
 
+# If it is setup hna for it
 if [ "$dhcpinmesh" == 1 ]; then
        uci set olsrd.${netrenamed}clients="Hna4"
        eval $(sh $dir/helpers/ipcalc-cidr.sh $dhcprange)
@@ -67,16 +60,11 @@ if [ "$dhcpinmesh" == 1 ]; then
 fi
 
 
-# Delete nameservice, dyngw and httpinfo plugins
+# Rename nameservice, dyngw and httpinfo plugins
 
 handle_plugin() {
         config_get library "$1" library
-       if [ "$cleanup" == 1 ]; then
-               case library in
-                       olsrd_*)
-                               section_cleanup olsrd.$1
-               esac
-       elif [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
+       if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
                new="$(echo $library | cut -d '.' -f 1)"
                section_rename olsrd $1 $new
        fi              
@@ -105,14 +93,10 @@ uci_commitverbose "Setup olsr nameservice plugin" olsrd
 # If Sharing of Internet is enabled then enable dyngw_plain plugin
 sharenet=$(uci -q get meshwizard.general.sharenet)
 
-if [ -n "$(uci -q get olsrd.dyngw_plain.library)" ]; then
-       section_cleanup olsrd.dyngw_plain
-fi
-
 if [ "$sharenet" == 1 ]; then
        uci set olsrd.dyngw_plain=LoadPlugin
        uci set olsrd.dyngw_plain.ignore=0
        uci set olsrd.dyngw_plain.library="olsrd_dyn_gw_plain.so.0.4"
-       uci_commitverbose "Setup olsrd_dyngw_plain plugin"
+       uci_commitverbose "Setup olsrd_dyngw_plain plugin" olsrd
 fi
 
index f316798c2f1331b6595fda8f71dae77748ccf3d8..1d1e248593b64c37df0cbf6e35591a6a13113427 100755 (executable)
@@ -14,12 +14,8 @@ fi
 handle_splash() {
        config_get network "$1" network
        if [ "$network" == "${netrenamed}dhcp" ]; then
-               if [ "$cleanup" == 1 ]; then
-                       section_cleanup luci_splash.$1
-               else
-                       if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
-                               section_rename luci_splash $1 ${netrenamed}dhcp
-                       fi
+               if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
+                       section_rename luci_splash $1 ${netrenamed}dhcp
                fi
        fi
 }
index eb899d011bdeea2b37cd9b68bd7f8be121239a4a..e9ce953f1571197a5892674afb2b73ea04c54a48 100755 (executable)
@@ -1,13 +1,7 @@
 #!/bin/sh
-# Sets values from /etc/config/freifunk and/or the community profile in /etc/config/system
 
 . $dir/functions.sh
 
-if [ -n "$(env | grep '^system_')" ]; then
-       env | grep "^system_" | sed "s/system_/uci set system.system./g" | while read line; do
-               eval $line
-       done
-fi
-
+set_defaults "system_" system.system
 uci -q delete meshwizard.system && uci commit meshwizard
 uci_commitverbose "System config" system
index 1feff0d70eb1ff05ecd51b44326a51f911f56482..52db4d944eec5ac84ae0779bcbb08943bb146d10 100755 (executable)
@@ -12,15 +12,11 @@ net="$1"
 config_load wireless
 config_get type $net type
 
-# Delete old wifi-device for $net
+# Rename wifi-device for $net
 
 handle_wifidevice() {
-       if [ "$1" == "$net" -a "$cleanup" == 1 ]; then
-               section_cleanup wireless.${net}
-       else
-               if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
-                       section_rename wireless $1 $net
-               fi
+       if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
+               section_rename wireless $1 $net
        fi
 }
 config_foreach handle_wifidevice wifi-device
@@ -47,16 +43,12 @@ uci_commitverbose "Setup wifi device for $netrenamed" wireless
 
 ##### wifi iface
 
-# Delete old wifi-iface for $net
+# Rename wifi-iface for $net
 handle_interface() {
        config_get device "$1" device
        if [ "$device" == "$net" ]; then
-               if [ "$cleanup" == 1 ]; then
-                       section_cleanup wireless.${net}_iface
-               else
-                       if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
-                               section_rename wireless $1 ${net}_iface
-                       fi
+               if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
+                       section_rename wireless $1 ${net}_iface
                fi
        fi
 } 
@@ -70,6 +62,7 @@ set_defaults "wifi_iface_" wireless.$net\_iface
 
 # overwrite defaults
 bssid="$($dir/helpers/gen_bssid.sh $channel $community)"
+
 ssid="$profile_ssid"
 if [ "$profile_ssid_scheme" == "addchannel" ]; then
        ssid="$ssid - ch$channel"
index 113d9058f03fc34c2ba6efbd78ad92fcc100f989..4b330ddecad32676a476bb08ea722017b01df542 100755 (executable)
@@ -1,17 +1,23 @@
 #!/bin/sh
-# This script will take settings from /etc/config/meshwizard, /etc/config/freifunk and /etc/config/profile_<selected in freifunk>
-# and setup the router to participate in wireless mesh networks
+
+# This collection of scripts will take settings from /etc/config/meshwizard, /etc/config/freifunk
+# and /etc/config/profile_<community> and setup the router to participate in wireless mesh networks
+
+# Copyright 2011 Manuel Munz <freifunk at somakoma dot de>
+
+# Licensed under the Apache License, Version 2.0 (the "License")
+# 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
 
 . /etc/functions.sh
 
 echo "
-Meshwizard 0.0.3
+/* Meshwizard 0.0.4 */
 "
 
 # config
 export dir="/usr/bin/meshwizard"
 . $dir/functions.sh
-debug=1
 
 # Check which packages we have installed
 export has_luci=FALSE
@@ -19,29 +25,23 @@ opkg list_installed |grep luci-mod-admin > /dev/null && export has_luci=TRUE
 export has_luci_splash=FALSE
 opkg list_installed |grep luci-app-splash > /dev/null && export has_luci_splash=TRUE
 
+# 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
+
 # Rename wifi interfaces
-       echo "+ Renaming wifi-devices in /etc/config/meshwizard"
-       $dir/helpers/rename-wifi.sh
+$dir/helpers/rename-wifi.sh
 
 # Get community
-export community=$(uci -q get meshwizard.community.name)
-[ -z "$community" ] && community=$(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
-
-# Check whether we want to cleanup uci config before setting new options or not
-cleanup=$(uci -q get meshwizard.general.cleanup)
-
-[ "$cleanup" == 1 ] && export cleanup=1
+export community="$community"
 
 # 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
 
-echo "    Community=$community
-    Network(s)=$networks"
-
 # Read default values (first from /etc/config/freifunk, then from /etc/config/profile_$community
 # then /etc/config/meshwizard
 # last will overwrite first
@@ -51,21 +51,16 @@ while read line; do
        export "${line//\"/}"
 done < /tmp/meshwizard.tmp
 
-# Firstboot/initial config
-       echo "+ Initial config"
-       $dir/helpers/initial_config.sh
-
-
+# Do config
+$dir/helpers/initial_config.sh
 $dir/helpers/setup_dnsmasq.sh
 $dir/helpers/setup_system.sh
-$dir/helpers/setup_freifunk.sh
 
 # Configure found networks
 for net in $networks; do
-
+       # radioX devices need to be renamed
        netrenamed="${net/radio/wireless}"
        export netrenamed
-
        $dir/helpers/setup_network.sh $net
        $dir/helpers/setup_wifi.sh $net
        $dir/helpers/setup_olsrd.sh $net