Developing lightweight computation at the DSG edge

Commit d854fea4 authored by p4u's avatar p4u
Browse files

Split tl-wdr switch hook into two files (switch and network)

Changed stage to "firstboot" and add checks for knowing if the switch is already configured
Small changes in hooks system
parent 51446b97
......@@ -34,17 +34,9 @@ log() {
}
exechooks() {
local stage="$1"
stage=${stage:-anyboot}
local device="$(cat /tmp/sysinfo/board_name)"
local hooksdir="/etc/qmp/hooks/$device"
[ -n "$device" ] && [ -d "$hooksdir" ] && {
for h in $hooksdir/*; do
echo "Executing hook: $h"
sh $h $stage
done
}
local stage=${1:-anyboot}
. $QMP_DIR/qmp_common.sh
qmp_hooks_exec $stage
}
prepare_wifi() {
......@@ -55,8 +47,8 @@ prepare_wifi() {
# It is a quick hack, because each time ath9k is loaded the phyX counter increases
# and openwrt wifi scripts take the device namw (i.e wlan0) from this counter
# It only works for ath9k
rmmod ath9k
insmod ath9k
rmmod ath9k 2>/dev/null
insmod ath9k 2>/dev/null
sleep 1
local index=0
......
......@@ -2,16 +2,21 @@
# Stage = [birth|firstboot|anyboot|preconf|postconf]
STAGE="$1"
[ "$STAGE" == "birth" ] && {
[ "$STAGE" == "firstboot" ] && {
[ "$(uci -q get network.@switch[0].name)" == "eth0" ] && {
echo "Switch already configured"
exit 0
}
echo "Configuring TPlink WDR switch [INET|LAN|LAN|LAN|MESH]"
uci delete network.@switch[0]
uci -q delete network.@switch[0]
uci add network switch
uci delete network.@switch_vlan[2]
uci delete network.@switch_vlan[1]
uci delete network.@switch_vlan[0]
uci -q delete network.@switch_vlan[2]
uci -q delete network.@switch_vlan[1]
uci -q delete network.@switch_vlan[0]
uci add network switch_vlan > /dev/null
uci add network switch_vlan > /dev/null
......@@ -38,11 +43,4 @@ uci set network.@switch_vlan[2].ports="0t 5t"
uci set network.@switch_vlan[2].vid=12
uci commit network
uci set qmp.interfaces.lan_devices="eth0.1"
uci set qmp.interfaces.mesh_devices="eth0.12"
uci set qmp.interfaces.wan_devices="eth0.2"
uci set qmp.interfaces.no_vlan_devices="eth0.12"
uci set qmp.interfaces.ignore_devices="eth0"
uci commit qmp
}
#!/bin/sh
# Stage = [birth|firstboot|anyboot|preconf|postconf]
STAGE="$1"
[ "$STAGE" == "firstboot" ] && {
echo "Configuring TPlink WDR switch networking"
iseth=0
devs="$(uci get qmp.interfaces.lan_devices) \
$(uci get qmp.interfaces.wan_devices) \
$(uci get qmp.interfaces.mesh_devices) \
$(uci get qmp.interfaces.ignore_devices)"
for d in $devs
do
[ "$d" == "eth0" ] && iseth=1 && break
done
[ $iseth -eq 0 ] && {
echo "Device eth0 not configured, doing it..."
uci set qmp.interfaces.lan_devices="eth0.1"
uci set qmp.interfaces.mesh_devices="eth0.12"
uci set qmp.interfaces.wan_devices="eth0.2"
uci set qmp.interfaces.no_vlan_devices="eth0.12"
uci set qmp.interfaces.ignore_devices="eth0"
uci commit qmp
}
}
../scripts/switch_wdr_network.sh
\ No newline at end of file
......@@ -234,7 +234,11 @@ qmp_get_dev_from_wifi_mac() {
qmp_hooks_exec() {
local stage="$1"
local device="$(cat /tmp/sysinfo/board_name)"
local device="none"
[ -e /tmp/sysinfo/board_name ] && device="$(cat /tmp/sysinfo/board_name 2>/dev/null)" \
|| device=$(cat /proc/cpuinfo | grep vendor_id | cut -d: -f2 | tr -d ' ')
[ -z "$stage" -o -z "$device" ] && return 1
local hooksdir="/etc/qmp/hooks/$device"
......
......@@ -701,7 +701,7 @@ qmp_configure_prepare() {
}
qmp_configure_prepare_network() {
local toRemove="$(uci show network | egrep "network.(lan|wan_|mesh_).*=interface" | cut -d. -f2 | cut -d= -f1)"
local toRemove="$(uci show network | egrep "network.(lan|wan|mesh_).*=interface" | cut -d. -f2 | cut -d= -f1)"
echo "Removing network configuration for: $toRemove" | tr '\n' ' '
for i in $toRemove; do
uci del network.$i
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment