Changeset 7610

Show
Ignore:
Timestamp:
10/06/11 20:38:12 (20 months ago)
Author:
soma
Message:

contrib/meshwizard: Various fixes and cleanups

Location:
luci/trunk/contrib/package/meshwizard/files/usr/bin/meshwizard
Files:
1 removed
11 modified

Legend:

Unmodified
Added
Removed
  • luci/trunk/contrib/package/meshwizard/files/usr/bin/meshwizard/functions.sh

    r7606 r7610  
    3434} 
    3535 
    36 # 1 argument: section to remove 
    37 section_cleanup() { 
    38     uci -q delete $1 && msg_cleanup $1 || msg_cleanup_error $1 
    39 } 
    40  
    4136# 3 arguements: 1=config name 2=oldname 3=newname 
    4237section_rename() { 
    4338    uci -q rename $1.$2=$3 && msg_rename $1.$2 $1.$3 || msg_rename_error $1.2 $1.$3 
    44 } 
    45  
    46 msg_cleanup() { 
    47     echo "    Cleanup: Removed section $1." 
    48 } 
    49  
    50 msg_cleanup_error() { 
    51     echo -e "    \033[1mWarning:\033[0m Cleanup of $1 failed." 
    5239} 
    5340 
  • luci/trunk/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/initial_config.sh

    r7606 r7610  
    33# It sets up the initial config for this node. 
    44 
    5  
    65. /etc/functions.sh 
    76. $dir/functions.sh 
    8  
    9 ### System config 
    107 
    118config_load system 
     
    2017 
    2118if [ -n "$(uci -q get meshwizard.community)" ]; then 
    22     echo "    + Setup community" 
    2319    set_defaults "community_" freifunk.community 
    2420    uci -q delete meshwizard.community 
    25     uci_commitverbose freifunk 
    2621fi 
     22[ -n "$profile_homepage" ] && uci set freifunk.community.homepage="$profile_homepage" 
     23uci_commitverbose "Setup community" freifunk 
    2724 
    2825if [ -n "$(uci -q get meshwizard.contact)" ]; then 
    29     echo "    + Setup contact" 
    3026    set_defaults "contact_" freifunk.contact 
    31     uci -q delete meshwizard.contact && uci_commitverbose freifunk 
     27    uci -q delete meshwizard.contact && uci_commitverbose "Setup contact" freifunk 
    3228fi 
    3329 
    3430if [ "$has_luci" == TRUE ]; then 
    35     echo "    + Setup luci" 
    3631    set_defaults "luci_main_" luci.main 
    37     uci -q delete meshwizard.luci_main && uci_commitverbose luci 
     32    uci -q delete meshwizard.luci_main && uci_commitverbose "Setup luci" luci 
    3833fi 
    39  
    40 uci commit 
    41  
    42  
  • luci/trunk/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/rename-wifi.sh

    r7208 r7610  
    33# E.g. wireless.IB_wifi0 would become wireless.wifi0 on madwifi and wireless.radio0 on mac80211 
    44 
     5. $dir/functions.sh 
     6 
    57posIB=-1 
    68 
    79IBwifis="$(uci show meshwizard.netconfig | grep -v 'netconfig=netconfig' | sed 's/meshwizard.netconfig\.\(IB_wifi.*\)_.*/\1/' |uniq)" 
     10[ -z "$(echo $IBwifis |grep IB_wifi)" ] && exit 
    811 
    912for w in $IBwifis; do 
     
    4144done 
    4245 
    43 uci commit 
     46uci_commitverbose "Renaming wifi-devices in /etc/config/meshwizard" meshwizard 
  • luci/trunk/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_dhcp.sh

    r7501 r7610  
    1010    config_get interface "$1" interface 
    1111    if [ "$interface" == "${netrenamed}dhcp" ]; then 
    12         if [ "$cleanup" == 1 ]; then 
    13             section_cleanup dhcp.$1 
    14         else 
    15             if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then 
    16                 section_rename dhcp $1 ${netrenamed}dhcp 
    17                         fi 
    18                 fi 
    19         fi 
     12        if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then 
     13            section_rename dhcp $1 ${netrenamed}dhcp 
     14        fi 
     15    fi 
    2016} 
    2117config_load dhcp 
     
    2420uci batch << EOF 
    2521set dhcp.${netrenamed}dhcp="dhcp" 
    26 set dhcp.${netrenamed}dhcp.leasetime="$dhcp_leasetime" 
    27 set dhcp.${netrenamed}dhcp.force="$dhcp_force" 
    2822set dhcp.${netrenamed}dhcp.interface="${netrenamed}dhcp" 
    2923EOF 
    3024 
     25set_defaults "dhcp_" dhcp.${netrenamed}dhcp 
     26 
    3127uci_commitverbose "Setup DHCP for $netrenamed" dhcp 
    3228 
  • luci/trunk/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_firewall.sh

    r7501 r7610  
    2828 
    2929    if [ "$2" == "zoneconf" ]; then 
    30         # clean zone 
    3130        if [ "$name" == "freifunk" ]; then 
    32             if [ "$cleanup" == 1 ]; then 
    33                 section_cleanup firewall.$1 
    34             else 
    35                 # rename section if unnamed 
    36                 if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then 
    37                     section_rename firewall $1 zone_freifunk 
    38                 fi 
     31            # rename section if unnamed 
     32            if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then 
     33                section_rename firewall $1 zone_freifunk 
    3934            fi 
    4035        else 
    41  
    42             if [ "$name" == "$netrenamed" ]; then 
    43                 section_cleanup firewall.$1 
    44             fi 
    4536            if [ -n "$netrenamed" -a -n "$(echo $network | grep $netrenamed)" ] && [ ! "$name" == "freifunk" ]; then 
    4637                echo "    Removed $netrenamed from firewall zone $name." 
     
    4940            fi 
    5041        fi 
    51     else 
    52         # clean fw_rule, fw_forwarding, include and advanced 
    53         for option in src tcp_ecn path; do 
    54             config_get $option $1 $option 
    55         done 
    56         if [ "$src" == "freifunk" -o "$path" == "/etc/firewall.freifunk" -o -n "$tcpecn" ]; then 
    57             section_cleanup firewall.$1 
    58         fi 
    5942    fi 
    6043} 
     
    6245config_foreach handle_fwzone zone zoneconf 
    6346 
    64 if [ "$cleanup" == 1 ]; then 
    65     for target in include advanced rule forwarding; do 
    66         config_foreach handle_fwzone $target 
    67     done 
    68 fi 
    69  
    7047# setup freifunk firewall zone 
    71  
    7248# add $netrenamed and if needed ${netrenamed}dhcp to the networks for this zone 
    7349config_get network zone_freifunk network 
     
    153129 
    154130uci_commitverbose "Setup rules, forwardings, advanced config and includes." firewall 
     131 
  • luci/trunk/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_network.sh

    r7501 r7610  
    55. /etc/functions.sh 
    66. $dir/functions.sh 
    7  
    8 # Delete the network interface section for $net 
    9 if [ "$cleanup" == 1 ]; then 
    10     section_cleanup network.$netrenamed 
    11 fi 
    127 
    138# Setup a (new) interface section for $net 
     
    2116set network.$netrenamed.proto="static" 
    2217set network.$netrenamed.ipaddr="$ipaddr" 
    23 set network.$netrenamed.netmask="$interface_netmask" 
    24 set network.$netrenamed.dns="$interface_dns" 
    2518EOF 
    26  
     19set_defaults "interface_" network.$netrenamed 
    2720uci_commitverbose "Setup interface $netrenamed" network 
    2821 
     
    3730    vap=$(uci -q get meshwizard.netconfig.${net}_vap) 
    3831 
    39     # Clean/rename config 
     32    # Rename config 
    4033    handle_dhcpalias() { 
    4134            config_get interface "$1" interface 
    4235            if [ "$interface" == "$netrenamed" ]; then 
    43                 if [ "$cleanup" == 1 ]; then 
    44                     section_cleanup network.$1 
    45                 else 
    46                     if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then 
    47                         section_rename network $1 ${netrenamed}dhcp 
    48                     fi 
     36                if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then 
     37                    section_rename network $1 ${netrenamed}dhcp 
    4938                fi 
    5039            fi 
  • luci/trunk/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_olsrd.sh

    r7501 r7610  
    88. $dir/functions.sh 
    99 
    10 # Clean or delete interface defaults 
     10# Rename interface defaults 
    1111handle_interfacedefaults() { 
    12     if [ "$cleanup" == 1 ]; then 
    13         section_cleanup olsrd.$1 
    14     else 
    15         if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then 
    16             section_rename olsrd $1 InterfaceDefaults 
    17          fi 
     12    if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then 
     13        section_rename olsrd $1 InterfaceDefaults 
    1814    fi 
    1915} 
    20  
    2116config_load olsrd 
    2217config_foreach handle_interfacedefaults InterfaceDefaults 
    2318 
    2419# Setup new InterfaceDefaults 
    25  
    2620uci set olsrd.InterfaceDefaults=InterfaceDefaults 
    2721set_defaults "olsr_interfacedefaults_" olsrd.InterfaceDefaults 
    2822uci_commitverbose "Setup olsr interface defaults" olsrd 
    2923 
    30 # Delete old interface for $netrenamed 
     24# Rename interface for $netrenamed 
    3125handle_interface() { 
    3226    config_get interface "$1" Interface 
    3327    if [ "$interface" == "$netrenamed" ]; then 
    34         if [ "$cleanup" == 1 ]; then 
    35             section_cleanup olsrd.$1 
    36         elif [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then 
     28        if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then 
    3729            section_rename olsrd $1 $netrenamed 
    3830        fi 
     
    5951dhcpinmesh="$($dir/helpers/check-range-in-range.sh $dhcprange $meshnet)" 
    6052 
     53# If it is setup hna for it 
    6154if [ "$dhcpinmesh" == 1 ]; then 
    6255    uci set olsrd.${netrenamed}clients="Hna4" 
     
    6861 
    6962 
    70 # Delete nameservice, dyngw and httpinfo plugins 
     63# Rename nameservice, dyngw and httpinfo plugins 
    7164 
    7265handle_plugin() { 
    7366        config_get library "$1" library 
    74     if [ "$cleanup" == 1 ]; then 
    75         case library in 
    76             olsrd_*) 
    77                 section_cleanup olsrd.$1 
    78         esac 
    79     elif [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then 
     67    if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then 
    8068        new="$(echo $library | cut -d '.' -f 1)" 
    8169        section_rename olsrd $1 $new 
     
    10694sharenet=$(uci -q get meshwizard.general.sharenet) 
    10795 
    108 if [ -n "$(uci -q get olsrd.dyngw_plain.library)" ]; then 
    109     section_cleanup olsrd.dyngw_plain 
    110 fi 
    111  
    11296if [ "$sharenet" == 1 ]; then 
    11397    uci set olsrd.dyngw_plain=LoadPlugin 
    11498    uci set olsrd.dyngw_plain.ignore=0 
    11599    uci set olsrd.dyngw_plain.library="olsrd_dyn_gw_plain.so.0.4" 
    116     uci_commitverbose "Setup olsrd_dyngw_plain plugin" 
     100    uci_commitverbose "Setup olsrd_dyngw_plain plugin" olsrd 
    117101fi 
    118102 
  • luci/trunk/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_splash.sh

    r7578 r7610  
    1515    config_get network "$1" network 
    1616    if [ "$network" == "${netrenamed}dhcp" ]; then 
    17         if [ "$cleanup" == 1 ]; then 
    18             section_cleanup luci_splash.$1 
    19         else 
    20             if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then 
    21                 section_rename luci_splash $1 ${netrenamed}dhcp 
    22             fi 
     17        if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then 
     18            section_rename luci_splash $1 ${netrenamed}dhcp 
    2319        fi 
    2420    fi 
  • luci/trunk/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_system.sh

    r7606 r7610  
    11#!/bin/sh 
    2 # Sets values from /etc/config/freifunk and/or the community profile in /etc/config/system 
    32 
    43. $dir/functions.sh 
    54 
    6 if [ -n "$(env | grep '^system_')" ]; then 
    7     env | grep "^system_" | sed "s/system_/uci set system.system./g" | while read line; do 
    8         eval $line 
    9     done 
    10 fi 
    11  
     5set_defaults "system_" system.system 
    126uci -q delete meshwizard.system && uci commit meshwizard 
    137uci_commitverbose "System config" system 
  • luci/trunk/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_wifi.sh

    r7501 r7610  
    1313config_get type $net type 
    1414 
    15 # Delete old wifi-device for $net 
     15# Rename wifi-device for $net 
    1616 
    1717handle_wifidevice() { 
    18     if [ "$1" == "$net" -a "$cleanup" == 1 ]; then 
    19         section_cleanup wireless.${net} 
    20     else 
    21         if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then 
    22             section_rename wireless $1 $net 
    23         fi 
     18    if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then 
     19        section_rename wireless $1 $net 
    2420    fi 
    2521} 
     
    4844##### wifi iface 
    4945 
    50 # Delete old wifi-iface for $net 
     46# Rename wifi-iface for $net 
    5147handle_interface() { 
    5248    config_get device "$1" device 
    5349    if [ "$device" == "$net" ]; then 
    54         if [ "$cleanup" == 1 ]; then 
    55             section_cleanup wireless.${net}_iface 
    56         else 
    57             if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then 
    58                 section_rename wireless $1 ${net}_iface 
    59             fi 
     50        if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then 
     51            section_rename wireless $1 ${net}_iface 
    6052        fi 
    6153    fi 
     
    7163# overwrite defaults 
    7264bssid="$($dir/helpers/gen_bssid.sh $channel $community)" 
     65 
    7366ssid="$profile_ssid" 
    7467if [ "$profile_ssid_scheme" == "addchannel" ]; then 
  • luci/trunk/contrib/package/meshwizard/files/usr/bin/meshwizard/wizard.sh

    r7606 r7610  
    11#!/bin/sh 
    2 # This script will take settings from /etc/config/meshwizard, /etc/config/freifunk and /etc/config/profile_<selected in freifunk> 
    3 # and setup the router to participate in wireless mesh networks 
     2 
     3# This collection of scripts will take settings from /etc/config/meshwizard, /etc/config/freifunk 
     4# and /etc/config/profile_<community> and setup the router to participate in wireless mesh networks 
     5 
     6# Copyright 2011 Manuel Munz <freifunk at somakoma dot de> 
     7 
     8# Licensed under the Apache License, Version 2.0 (the "License") 
     9# You may not use this file except in compliance with the License. 
     10# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
    411 
    512. /etc/functions.sh 
    613 
    714echo " 
    8 Meshwizard 0.0.3 
     15/* Meshwizard 0.0.4 */ 
    916" 
    1017 
     
    1219export dir="/usr/bin/meshwizard" 
    1320. $dir/functions.sh 
    14 debug=1 
    1521 
    1622# Check which packages we have installed 
     
    2026opkg list_installed |grep luci-app-splash > /dev/null && export has_luci_splash=TRUE 
    2127 
     28# Check whether we want to cleanup/restore uci config before setting new options 
     29cleanup=$(uci -q get meshwizard.general.cleanup) 
     30[ "$cleanup" == 1 ] && $dir/helpers/restore_default_config.sh 
     31 
    2232# Rename wifi interfaces 
    23     echo "+ Renaming wifi-devices in /etc/config/meshwizard" 
    24     $dir/helpers/rename-wifi.sh 
     33$dir/helpers/rename-wifi.sh 
    2534 
    2635# Get community 
    27 export community=$(uci -q get meshwizard.community.name) 
    28 [ -z "$community" ] && community=$(uci -q get freifunk.community.name) 
     36community=$(uci -q get meshwizard.community.name || uci -q get freifunk.community.name) 
    2937[ -z "$community" ] && echo "Error: Community is not set in /etc/config/freifunk, aborting now." && exit 1 
    30  
    31 # Check whether we want to cleanup uci config before setting new options or not 
    32 cleanup=$(uci -q get meshwizard.general.cleanup) 
    33  
    34 [ "$cleanup" == 1 ] && export cleanup=1 
     38export community="$community" 
    3539 
    3640# Get a list of networks we need to setup 
    3741networks=$(uci show meshwizard.netconfig | grep -v "netconfig=" | sed -e 's/meshwizard.netconfig\.\(.*\)\_.*/\1/' |sort|uniq) 
    3842export networks 
    39  
    4043[ -z "$networks" ] && echo "Error: No networks to setup could be found in /etc/config/meshwizard, aborting now." && exit 1 
    41  
    42 echo "    Community=$community 
    43     Network(s)=$networks" 
    4444 
    4545# Read default values (first from /etc/config/freifunk, then from /etc/config/profile_$community 
     
    5252done < /tmp/meshwizard.tmp 
    5353 
    54 # Firstboot/initial config 
    55     echo "+ Initial config" 
    56     $dir/helpers/initial_config.sh 
    57  
    58  
     54# Do config 
     55$dir/helpers/initial_config.sh 
    5956$dir/helpers/setup_dnsmasq.sh 
    6057$dir/helpers/setup_system.sh 
    61 $dir/helpers/setup_freifunk.sh 
    6258 
    6359# Configure found networks 
    6460for net in $networks; do 
    65  
     61    # radioX devices need to be renamed 
    6662    netrenamed="${net/radio/wireless}" 
    6763    export netrenamed 
    68  
    6964    $dir/helpers/setup_network.sh $net 
    7065    $dir/helpers/setup_wifi.sh $net