add changes that were missing in the last commit
This commit is contained in:
parent
0eef467871
commit
d447b7e9f2
6 changed files with 153 additions and 64 deletions
|
@ -4,7 +4,7 @@
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=meshwizard
|
PKG_NAME:=meshwizard
|
||||||
PKG_RELEASE:=0.1.1
|
PKG_RELEASE:=0.3.0
|
||||||
|
|
||||||
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
|
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,21 @@ uci_remove_list_element() {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# string_contains(string, substring)
|
||||||
|
#
|
||||||
|
# Returns 0 if the specified string contains the specified substring,
|
||||||
|
# otherwise returns 1.
|
||||||
|
string_contains() {
|
||||||
|
string="$1"
|
||||||
|
substring="$2"
|
||||||
|
if test "${string#*$substring}" != "$string"
|
||||||
|
then
|
||||||
|
return 0 # $substring is in $string
|
||||||
|
else
|
||||||
|
return 1 # $substring is not in $string
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Takes 2 arguments
|
# Takes 2 arguments
|
||||||
# $1 = text to be displayed in the output for this section
|
# $1 = text to be displayed in the output for this section
|
||||||
# $2 = section (optional)
|
# $2 = section (optional)
|
||||||
|
@ -29,11 +44,18 @@ set_defaults() {
|
||||||
a="$(echo $option |cut -d '=' -f1)"
|
a="$(echo $option |cut -d '=' -f1)"
|
||||||
b="$(echo $option |cut -d '=' -f2-)"
|
b="$(echo $option |cut -d '=' -f2-)"
|
||||||
b="${b//_/ }"
|
b="${b//_/ }"
|
||||||
uci set $2.$a="$b"
|
string_contains "$a" "_LENGTH" && return
|
||||||
|
string_contains "$a" "_ITEM" && {
|
||||||
|
# special threatment for lists. use add_list and remove the
|
||||||
|
# item index (_ITEMx).
|
||||||
|
uci add_list $2.${a//_ITEM[0-9]*/}="$b"
|
||||||
|
} || {
|
||||||
|
uci set $2.$a="$b"
|
||||||
|
}
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# 3 arguements: 1=config name 2=oldname 3=newname
|
# 3 arguments: 1=config name 2=oldname 3=newname
|
||||||
section_rename() {
|
section_rename() {
|
||||||
uci -q rename $1.$2=$3 && msg_rename $1.$2 $1.$3 || msg_rename_error $1.$2 $1.$3
|
uci -q rename $1.$2=$3 && msg_rename $1.$2 $1.$3 || msg_rename_error $1.$2 $1.$3
|
||||||
}
|
}
|
||||||
|
@ -57,3 +79,40 @@ msg_rename() {
|
||||||
msg_rename_error() {
|
msg_rename_error() {
|
||||||
echo " \033[1mWarning:\033[0m Could not rename $1 to $2."
|
echo " \033[1mWarning:\033[0m Could not rename $1 to $2."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
restore_factory_defaults() {
|
||||||
|
echo "+ Restore default config as requested with cleanup=1"
|
||||||
|
cp -f /rom/etc/config/* /etc/config/
|
||||||
|
rm /etc/config/wireless
|
||||||
|
wifi detect > /etc/config/wireless
|
||||||
|
rm /etc/config/network
|
||||||
|
if [ -f /etc/init.d/defconfig ]; then
|
||||||
|
# legacy (AA)
|
||||||
|
/etc/init.d/defconfig start
|
||||||
|
[ -f /rom/etc/uci-defaults/network ] && sh /rom/etc/uci-defaults/network
|
||||||
|
else
|
||||||
|
sh /rom/etc/uci-defaults/02_network
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
is_in_list() {
|
||||||
|
# checks if an item is in a list
|
||||||
|
local list="$1"
|
||||||
|
local item="$2"
|
||||||
|
for word in $list; do
|
||||||
|
[ $word = "$item" ] && return 0
|
||||||
|
done
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
add_to_list() {
|
||||||
|
local list="$1"
|
||||||
|
local item="$2"
|
||||||
|
is_in_list "$list" "$item" && echo $list
|
||||||
|
if [ -z "$list" ]; then
|
||||||
|
echo "$item"
|
||||||
|
else
|
||||||
|
echo "$list $item"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
|
@ -1,35 +1,61 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# This reads the settings we need to have to configure everything
|
# These functions read the settings we need for configuration of the router
|
||||||
# Argument $1: community
|
|
||||||
|
|
||||||
. /lib/functions.sh
|
read_defaults() {
|
||||||
community="$1"
|
# read default values from the 3 relevant config files and export them
|
||||||
|
# into the environment. Later loaded configs overwrite earlier ones. The
|
||||||
|
# The ordering here is from most generic to most specific:
|
||||||
|
# freifunk (most generic defaults)
|
||||||
|
# profile_* (community defaults)
|
||||||
|
# nodes custom config from meshwizard config file
|
||||||
|
|
||||||
# reads variables from uci files, parameter $1 is the section
|
local community="$1"
|
||||||
get_var() {
|
|
||||||
uci -q show $1 | cut -d "." -f 2-100 |grep "\." | sed -e 's/^\([A-Za-z0-9_]*\)\./\1_/g' -e 's/=\(.*\)$/="\1"/g'
|
config_cb() {
|
||||||
|
local type="$1"
|
||||||
|
local name="$2"
|
||||||
|
local allowed_section_types="widget"
|
||||||
|
local allowed_section_names="
|
||||||
|
system
|
||||||
|
wifi_device
|
||||||
|
wifi_iface
|
||||||
|
interface
|
||||||
|
alias
|
||||||
|
dhcp
|
||||||
|
olsr_interface
|
||||||
|
olsr_interfacedefaults
|
||||||
|
profile
|
||||||
|
zone_freifunk
|
||||||
|
include
|
||||||
|
luci_splash
|
||||||
|
ipv6
|
||||||
|
luci_main
|
||||||
|
contact
|
||||||
|
community
|
||||||
|
wan
|
||||||
|
lan
|
||||||
|
general
|
||||||
|
ipv6
|
||||||
|
qos
|
||||||
|
"
|
||||||
|
|
||||||
|
if [ "$type" = "widget" ]; then
|
||||||
|
widgets=$(add_to_list "$widgets" "$name")
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ([ -n "$name" ] && is_in_list "$allowed_section_names" $name) \
|
||||||
|
|| is_in_list "$allowed_section_types" $type ; then
|
||||||
|
option_cb() {
|
||||||
|
local option="$1"
|
||||||
|
local value="$2"
|
||||||
|
export "${CONFIG_SECTION}_${option}"="$value"
|
||||||
|
}
|
||||||
|
else
|
||||||
|
option_cb() { return; }
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
config_load freifunk
|
||||||
|
config_load profile_${community}
|
||||||
|
config_load meshwizard
|
||||||
|
export widgets="$widgets"
|
||||||
}
|
}
|
||||||
|
|
||||||
handle_widgets() {
|
|
||||||
widgets="$widgets $1"
|
|
||||||
}
|
|
||||||
config_load freifunk
|
|
||||||
config_foreach handle_widgets widget
|
|
||||||
config_load profile_$community
|
|
||||||
config_foreach handle_widgets widget
|
|
||||||
echo "widgets=$widgets"
|
|
||||||
|
|
||||||
# read default values from /etc/config/freifunk
|
|
||||||
for v in system wifi_device wifi_iface interface alias dhcp olsr_interface olsr_interfacedefaults zone_freifunk include $widgets; do
|
|
||||||
get_var freifunk.$v
|
|
||||||
done
|
|
||||||
|
|
||||||
# now read all values from the selected community profile, will override some values from the defaults before
|
|
||||||
for v in system wifi_device wifi_iface interface alias dhcp olsr_interface olsr_interfacedefaults profile zone_freifunk include luci_splash ipv6 $widgets; do
|
|
||||||
get_var profile_$community.$v
|
|
||||||
done
|
|
||||||
|
|
||||||
# read values from meshwizard
|
|
||||||
for v in system luci_main contact community wan lan general ipv6 qos; do
|
|
||||||
get_var meshwizard.$v
|
|
||||||
done
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ for i in `seq 0 $posIB`; do
|
||||||
uci show meshwizard.netconfig | grep $IBwifi | while read line; do
|
uci show meshwizard.netconfig | grep $IBwifi | while read line; do
|
||||||
oldline=$(echo $line | cut -d "=" -f 1)
|
oldline=$(echo $line | cut -d "=" -f 1)
|
||||||
uci set $oldline=""
|
uci set $oldline=""
|
||||||
newline=$(echo $line |sed "s/$IBwifi/$syswifi/g")
|
newline=$(echo $line |sed -e "s/$IBwifi/$syswifi/g" -e "s/'//g")
|
||||||
uci set $newline
|
uci set $newline
|
||||||
done
|
done
|
||||||
;;
|
;;
|
||||||
|
|
|
@ -80,23 +80,30 @@ if [ ! "$no_masq_lan" == "1" ] && [ ! "$(uci -q get meshwizard.netconfig.lan_con
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Rules, Forwardings, advanced config and includes
|
# Rules, Forwardings, advanced config and includes from freifunk and
|
||||||
|
# profile_$community config files.
|
||||||
|
|
||||||
for config in freifunk profile_$community; do
|
add_fw_rules() {
|
||||||
|
config_cb() {
|
||||||
|
local type="$1"
|
||||||
|
local name="$2"
|
||||||
|
local allowed_section_types="advanced include fw_rule fw_forwarding"
|
||||||
|
if is_in_list "$allowed_section_types" $type ; then
|
||||||
|
uci set firewall.${name}="${type/fw_/}"
|
||||||
|
option_cb() {
|
||||||
|
local option="$1"
|
||||||
|
local value="$2"
|
||||||
|
uci set firewall.${CONFIG_SECTION}.${option}="$value"
|
||||||
|
}
|
||||||
|
else
|
||||||
|
option_cb() { return; }
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
config_load freifunk
|
||||||
|
config_load profile_${community}
|
||||||
|
}
|
||||||
|
add_fw_rules
|
||||||
|
|
||||||
config_load $config
|
|
||||||
|
|
||||||
for section in advanced include fw_rule fw_forwarding; do
|
|
||||||
handle_firewall() {
|
|
||||||
local options=$(uci show $config."$1")
|
|
||||||
options=$(echo "$options" | sed -e "s/fw_//g" -e "s/^$config/firewall/g")
|
|
||||||
for o in $options; do
|
|
||||||
uci set $o
|
|
||||||
done
|
|
||||||
}
|
|
||||||
config_foreach handle_firewall $section
|
|
||||||
done
|
|
||||||
done
|
|
||||||
|
|
||||||
# If we use auto-ipv6-dhcp then allow 547/udp on the freifunk zone
|
# If we use auto-ipv6-dhcp then allow 547/udp on the freifunk zone
|
||||||
if [ "$ipv6_config" = "auto-ipv6-dhcpv6" ]; then
|
if [ "$ipv6_config" = "auto-ipv6-dhcpv6" ]; then
|
||||||
|
|
|
@ -9,15 +9,16 @@
|
||||||
# You may not use this file except in compliance with 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
|
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
. /lib/functions.sh
|
|
||||||
|
|
||||||
echo "
|
echo "
|
||||||
/* Meshwizard 0.2.0 */
|
/* Meshwizard 0.3.0 */
|
||||||
"
|
"
|
||||||
|
|
||||||
# config
|
# config
|
||||||
export dir="/usr/bin/meshwizard"
|
export dir="/usr/bin/meshwizard"
|
||||||
|
|
||||||
|
. /lib/functions.sh
|
||||||
. $dir/functions.sh
|
. $dir/functions.sh
|
||||||
|
. $dir/helpers/read_defaults.sh
|
||||||
[ -f /proc/net/ipv6_route ] && export has_ipv6=1
|
[ -f /proc/net/ipv6_route ] && export has_ipv6=1
|
||||||
|
|
||||||
# Check which packages we have installed
|
# Check which packages we have installed
|
||||||
|
@ -28,30 +29,26 @@ opkg list_installed |grep luci-app-splash > /dev/null && export has_luci_splash=
|
||||||
|
|
||||||
# Check whether we want to cleanup/restore uci config before setting new options
|
# Check whether we want to cleanup/restore uci config before setting new options
|
||||||
cleanup=$(uci -q get meshwizard.general.cleanup)
|
cleanup=$(uci -q get meshwizard.general.cleanup)
|
||||||
[ "$cleanup" == 1 ] && $dir/helpers/restore_default_config.sh
|
[ "$cleanup" == 1 ] && restore_factory_defaults
|
||||||
|
|
||||||
# Rename wifi interfaces
|
# Rename wifi interfaces
|
||||||
$dir/helpers/rename-wifi.sh
|
$dir/helpers/rename-wifi.sh
|
||||||
|
|
||||||
# Get community
|
# Get community
|
||||||
community=$(uci -q get meshwizard.community.name || 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
|
[ -z "$community" ] && echo "Error: Community is not set in /etc/config/freifunk, aborting now." && exit 1
|
||||||
export community="$community"
|
export community="$community"
|
||||||
echo $community
|
|
||||||
|
# we need a list of widgets later on. It will be populated in read_defaults.sh
|
||||||
|
local widgets=""
|
||||||
|
|
||||||
# Get a list of networks we need to setup
|
# 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)
|
networks=$(uci show meshwizard.netconfig | grep -v "netconfig=" | sed -e 's/meshwizard.netconfig\.\(.*\)\_.*/\1/' |sort|uniq)
|
||||||
export networks
|
export networks
|
||||||
[ -z "$networks" ] && echo "Error: No networks to setup could be found in /etc/config/meshwizard, aborting now." && exit 1
|
[ -z "$networks" ] && echo "Error: No networks to setup could be found in /etc/config/meshwizard, aborting now." && exit 1
|
||||||
|
|
||||||
# Read default values (first from /etc/config/freifunk, then from /etc/config/profile_$community
|
# Read defaults and node config
|
||||||
# then /etc/config/meshwizard
|
read_defaults $community
|
||||||
# last will overwrite first
|
|
||||||
|
|
||||||
$dir/helpers/read_defaults.sh $community > /tmp/meshwizard.tmp
|
|
||||||
while read line; do
|
|
||||||
export "${line//\"/}"
|
|
||||||
done < /tmp/meshwizard.tmp
|
|
||||||
|
|
||||||
# Do config
|
# Do config
|
||||||
$dir/helpers/initial_config.sh
|
$dir/helpers/initial_config.sh
|
||||||
|
|
Loading…
Reference in a new issue