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."
}
# 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
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
-
-
# 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 ))
fi
done
-uci commit
+uci_commitverbose "Renaming wifi-devices in /etc/config/meshwizard" meshwizard
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
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
done
uci_commitverbose "Setup rules, forwardings, advanced config and includes." firewall
+
+++ /dev/null
-#!/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
-
. /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)
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
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
}
. /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
# 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)
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
# 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
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
}
#!/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
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
##### 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
}
# overwrite defaults
bssid="$($dir/helpers/gen_bssid.sh $channel $community)"
+
ssid="$profile_ssid"
if [ "$profile_ssid_scheme" == "addchannel" ]; then
ssid="$ssid - ch$channel"
#!/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
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
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