contrib/meshwizard: Various fixes and cleanups
[project/luci.git] / contrib / package / meshwizard / files / usr / bin / meshwizard / wizard.sh
index 113d905..4b330dd 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