Skip to content

Commit

Permalink
Merge branch 'configtools'
Browse files Browse the repository at this point in the history
This adds some commandline scripts to automate changing some configsettings.
Initially it was based on the idea of working on the conflicting settings
of the ethernet-ports for routers just participating in the network or
providing an uplink (freifunk-berlin/firmware#292).
  • Loading branch information
SvenRoederer committed Dec 27, 2019
2 parents f0a1a7c + fb29e35 commit 51fc952
Show file tree
Hide file tree
Showing 5 changed files with 734 additions and 0 deletions.
52 changes: 52 additions & 0 deletions addons/freifunk-berlin-configtools/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#
# Copyright (C) 2019 Freifunk Berlin
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

PKG_NAME:=freifunk-berlin-configtools
PKG_RELEASE:=1

PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)

include ../../freifunk-berlin-generic.mk

define Package/freifunk-berlin-configtools
SECTION:=freifunk-berlin
CATEGORY:=freifunk-berlin
TITLE:=Freifunk Berlin console configtools
URL:=http://github.com/freifunk-berlin/packages_berlin
PKGARCH:=all
endef

define Package/freifunk-berlin-configtools/description
some handy tools and scripts to handle Freifunk-Berlin configuration
endef

# directly taken from luci.mk
define Build/Prepare
for d in luasrc htdocs root src; do \
if [ -d ./$$$$d ]; then \
mkdir -p $(PKG_BUILD_DIR)/$$$$d; \
$(CP) ./$$$$d/* $(PKG_BUILD_DIR)/$$$$d/; \
fi; \
done
$(call Build/Prepare/Default)
endef

define Build/Configure
endef

define Build/Compile
endef

# taken from luci.mk
define Package/freifunk-berlin-configtools/install
$(INSTALL_DIR) $(1)/
$(CP) $(PKG_BUILD_DIR)/root/* $(1)/
endef

$(eval $(call BuildPackage,freifunk-berlin-configtools))
11 changes: 11 additions & 0 deletions addons/freifunk-berlin-configtools/ReadMe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
This folder contains some supporting-scripts that might help to ease some configuration-tasks.
The intention is that these scripts can be called directly from the shell or by the wizard. There is the parameter "-c" which tells the script to do the UCI-commit before finishing. The default is to not commit the changes, that helps for review and for calling by teh wizard.

## bandwidth-change.sh
a small script to setup / change the configuration for QoS, as these values should be kept in sync between several files

## make_batman-adv.sh
script to setup a BATMAN-adv bridge on all interfaces of the freifunk-zone

## sharenet-switch.sh
script to handle the problem described in https://github.com/freifunk-berlin/firmware/issues/292. This is a common problem on 1 LAN-port routers or PoE-powered routers to have the freifunk-lan on the port you want to have the WAN-zone.
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/bin/sh
# This program should change bandwidth settings on freifunk routers
# Copyright (C) 2018 holger@freifunk-berlin
# inspired by depricated https://github.com/freifunk-berlin/firmware-packages/commit/3a923a89e705da88bd44bb78d4ebfa6655b3960e
#
# we should check which tc is running, like opkg list-installed | grep simple-tc s.a. https://github.com/freifunk-berlin/firmware/issues/548
# only tc is not helpful with grep
# display current settings:
show_settings() {
echo "usage $0 -c [commit] -d [down/MBit] -u [up/Mbit]"
echo 'current settings'
usersBandwidthDown=$(uci get ffwizard.settings.usersBandwidthDown)
usersBandwidthUp=$(uci get ffwizard.settings.usersBandwidthUp)
echo " userdown $(( $usersBandwidthDown ))"
echo " userup $(( $usersBandwidthUp ))"
echo " qosdown $(uci get qos.ffuplink.download)"
echo " qosup $(uci get qos.ffuplink.upload)"
}

AUTOCOMMIT="no"
OPERATION="show"

while getopts "cd:u:" option; do
case "$option" in
d)
DOWNSPEED="${OPTARG}"
OPERATION="set"
;;
u)
UPSPEED="${OPTARG}"
OPERATION="set"
;;
c)
AUTOCOMMIT="yes"
;;
*)
echo "Invalid argument '-$OPTARG'."
exit 1
;;
esac
done
shift $((OPTIND - 1))

#if [ ${OPERATION} == "set" ]; then
# [ -z ${DOWNSPEED} ] && echo "value missing for desiredqosdown" && exit 1;
# [ -z ${UPSPEED} ] && echo "value missing for desiredqosup" && exit 1;
#fi

# should this script run?
if [ "$(uci get ffwizard.settings.sharenet 2> /dev/null)" == "0" ]; then
echo 'dont share my internet' && exit 0
elif [ "$(uci get ffwizard.settings.sharenet 2> /dev/null)" == "1" ]; then
echo 'share my internet'
else
echo 'sharenet value unknown' && exit 1
fi
# can we change olsrd file?
if [ -e /etc/config/olsrd ]; then
echo 'file olsrd found'
else
echo 'file olsrd not found' && exit 1
fi

show_settings

desiredqosdown=${DOWNSPEED}
desiredqosup=${UPSPEED}

echo desiredqosdown $desiredqosdown
echo desiredqosup $desiredqosup
# change olsrd-settings
if [ ${OPERATION} == "set" ]; then
qosolsrdown=$(($desiredqosdown * 1000));
qosolsrup=$(($desiredqosup * 1000));
uci set olsrd.@olsrd[0].SmartGatewaySpeed="${qosolsrup} ${qosolsrdown}";
uci set qos.ffuplink.download=$qosolsrdown;
uci set qos.ffuplink.upload=$qosolsrup;
uci set ffwizard.settings.usersBandwidthDown=$desiredqosdown;
uci set ffwizard.settings.usersBandwidthUp=$desiredqosup
fi
# shall I commit changes? Yes, when called by hand.
if [ ${AUTOCOMMIT} == "yes" ]; then
echo 'uci commit qos';
uci commit olsrd;
uci commit qos.ffuplink;
uci commit ffwizard.settings;
reload_config # 2 missing entries?
else
echo 'uci dont commit qos'

fi


exit 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh

. /lib/functions.sh

create_interface() {
MASTERIF=$1

uci set network.${MASTERIF}_bat=interface
uci set network.${MASTERIF}_bat.ifname='@${MASTERIF}'
uci set network.${MASTERIF}_bat.proto='batadv'
uci set network.${MASTERIF}_bat.mesh='bat0'
uci commit network.${MASTERIF}_bat
}

add_batman_iface() {
DSTBRIDGE=$1

ifnames="$(uci get network.${DSTBRIDGE}.ifname)"
list_contains ${ifnames} ${BATIF} || uci set network.${DSTBRIDGE}.ifname="${ifnames} ${BATIF}"
}

BATIF=bat0

create_interface wireless0
add_batman_iface dhcp
Loading

0 comments on commit 51fc952

Please sign in to comment.