From 712620451cbcf34bf2c39b4185000b1ebd69acf8 Mon Sep 17 00:00:00 2001 From: Manuel Munz Date: Thu, 6 Oct 2011 19:38:12 +0000 Subject: [PATCH] contrib/meshwizard: Various fixes and cleanups --- .../files/usr/bin/meshwizard/functions.sh | 13 ------ .../bin/meshwizard/helpers/initial_config.sh | 17 ++----- .../usr/bin/meshwizard/helpers/rename-wifi.sh | 5 ++- .../usr/bin/meshwizard/helpers/setup_dhcp.sh | 16 +++---- .../bin/meshwizard/helpers/setup_firewall.sh | 31 ++----------- .../bin/meshwizard/helpers/setup_freifunk.sh | 13 ------ .../bin/meshwizard/helpers/setup_network.sh | 19 ++------ .../usr/bin/meshwizard/helpers/setup_olsrd.sh | 34 ++++---------- .../bin/meshwizard/helpers/setup_splash.sh | 8 +--- .../bin/meshwizard/helpers/setup_system.sh | 8 +--- .../usr/bin/meshwizard/helpers/setup_wifi.sh | 21 +++------ .../files/usr/bin/meshwizard/wizard.sh | 45 +++++++++---------- 12 files changed, 61 insertions(+), 169 deletions(-) delete mode 100755 contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_freifunk.sh diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/functions.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/functions.sh index fbb36ebe5..f8271498a 100644 --- a/contrib/package/meshwizard/files/usr/bin/meshwizard/functions.sh +++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/functions.sh @@ -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." } diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/initial_config.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/initial_config.sh index 12b9148ab..6c442e0a9 100755 --- a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/initial_config.sh +++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/initial_config.sh @@ -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 - - 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 aee15f5b7..872b36c46 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 @@ -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 diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_dhcp.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_dhcp.sh index 06f80d850..51fb235c1 100755 --- a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_dhcp.sh +++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_dhcp.sh @@ -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 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 e7e453d1c..e3eb6a779 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 @@ -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 index e4bd87f1c..000000000 --- a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_freifunk.sh +++ /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 - diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_network.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_network.sh index 493c701b2..1492cbbb0 100755 --- a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_network.sh +++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_network.sh @@ -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 } diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_olsrd.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_olsrd.sh index 06cc2e58c..ba11b5174 100755 --- a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_olsrd.sh +++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_olsrd.sh @@ -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 diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_splash.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_splash.sh index f316798c2..1d1e24859 100755 --- a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_splash.sh +++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_splash.sh @@ -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 } diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_system.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_system.sh index eb899d011..e9ce953f1 100755 --- a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_system.sh +++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_system.sh @@ -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 diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_wifi.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_wifi.sh index 1feff0d70..52db4d944 100755 --- a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_wifi.sh +++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_wifi.sh @@ -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" diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/wizard.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/wizard.sh index 113d9058f..4b330ddec 100755 --- a/contrib/package/meshwizard/files/usr/bin/meshwizard/wizard.sh +++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/wizard.sh @@ -1,17 +1,23 @@ #!/bin/sh -# This script will take settings from /etc/config/meshwizard, /etc/config/freifunk and /etc/config/profile_ -# 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_ and setup the router to participate in wireless mesh networks + +# Copyright 2011 Manuel Munz + +# 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 -- 2.25.1