Developing lightweight computation at the DSG edge

Commit b138aa42 authored by Simó Albert i Beltran's avatar Simó Albert i Beltran
Browse files

Remove tailing spaces of qMp shellscripts

sed -i -e "s/\s*$//g" packages/qmp-system/files/etc/qmp/*.sh
parent 90ee37c5
......@@ -236,10 +236,10 @@ qmp_get_dev_from_wifi_mac() {
qmp_hooks_exec() {
local stage="$1"
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"
......@@ -255,7 +255,7 @@ qmp_hooks_exec() {
# ID/IP commands
#########################
# Returns the crc16 from the mac of the primary mac device
# Returns the crc16 from the mac of the primary mac device
# If no parameter it returns the entire hash
# If parameter = 1 or 2, returns the first/second 8bit module 256
qmp_get_crc16() {
......@@ -267,7 +267,7 @@ qmp_get_crc16() {
}
# qmp_get_id [8bit]
qmp_get_id() {
qmp_get_id() {
local community_node_id="$(qmp_uci_get node.community_node_id)"
[ -z "$community_node_id" ] && \
community_node_id="$(qmp_get_crc16)"
......
......@@ -112,33 +112,33 @@ upgrade() {
hard_reboot() {
echo "System is gonna be rebooted now!"
echo 1 > /proc/sys/kernel/sysrq
echo b > /proc/sysrq-trigger
echo b > /proc/sysrq-trigger
}
configure_all() {
configure_system
configure_wifi
configure_network
configure_network
}
safe_apply() {
[ -e "/tmp/qmp.save.tar.gz" ] && echo "Found saved state at /tmp/qmp.save.tar.gz. Make sure you want to use it!" \
|| {
|| {
echo "Cannot found saved state, saving it..."
save_state
}
touch /tmp/qmp.safe.test
echo "------------------------------------------------------------------------------------"
echo "File /tmp/qmp.safe.test has been created, after configuring the system you will have
echo "File /tmp/qmp.safe.test has been created, after configuring the system you will have
180 seconds to remove it or the previous state will be recovered"
echo "------------------------------------------------------------------------------------"
read -p'Do you agree?[y,N] ' a
[ "$a" != "y" ] && return
configure_all
( sleep 180
[ -e "/tmp/qmp.safe.test" ] && {
cp -f /etc/config/qmp /tmp/qmp.wrong
......@@ -164,7 +164,7 @@ recover_state() {
help() {
echo "Use: $0 <function> [params]"
echo ""
echo "Configuration:"
echo " configure_all : Configure and apply all settings"
......@@ -173,13 +173,13 @@ help() {
echo " configure_wifi : Configure all WiFi devices"
echo " reset_wifi : Reset, rescan and configure all the WiFi devices"
echo " configure_gw : Configure and apply gateways settings"
echo ""
echo "Safe configuration:"
echo " save_state : Saves current state of configuration files"
echo " recover_state : Recovers previous saved state"
echo " safe_apply : Performs a safe configure_all. If something wrong it comes back to old state"
echo ""
echo "Gateways:"
echo " offer_default_gw [ipv4|ipv6] : Offers default gw to the network IPv4 or IPv6, both versions if no value"
......@@ -194,7 +194,7 @@ help() {
echo " enable_ns_ppt : Enable POE passtrought from NanoStation M2/5 devices. Be careful with this option!"
echo " upgrade [URL] : Upgrade system. By default to the last version, but image url can be provided to force"
echo " hard_reboot : Performs a hard reboot (using kernel sysrq)"
echo ""
exit 0
}
......
......@@ -51,14 +51,14 @@ qmp_get_llocal_for_dev() {
# returns primary device
qmp_get_primary_device() {
local primary_mesh_device="$(uci get qmp.node.primary_device)"
[ -z "$primary_mesh_device" ] &&
[ -z "$primary_mesh_device" ] &&
{
if ip link show dev eth0 > /dev/null; then
primary_mesh_device="eth0"
else
primary_mesh_device="$(ip link show | awk '!/lo:/&&/^[0-9]?:/{sub(/:$/,"",$2); print $2; exit}')"
fi
[ -z "$primary_mesh_device" ] && echo "CRITICAL: No primary network device found, please define qmp.node.primary_device"
[ -z "$primary_mesh_device" ] && echo "CRITICAL: No primary network device found, please define qmp.node.primary_device"
}
echo "$primary_mesh_device"
}
......@@ -102,8 +102,8 @@ qmp_get_virtual_iface() {
return
fi
for l in $(qmp_get_devices lan); do
if [ "$l" == "$device" ]; then
for l in $(qmp_get_devices lan); do
if [ "$l" == "$device" ]; then
viface="lan"
echo $viface
return
......@@ -117,7 +117,7 @@ qmp_get_virtual_iface() {
local id_char=$(echo $device | cut -c 1)
# is wan
for w in $(qmp_get_devices wan); do
for w in $(qmp_get_devices wan); do
if [ "$w" == "$device" ]; then
viface="wan_${id_char}${id_num}"
echo $viface
......@@ -126,21 +126,21 @@ qmp_get_virtual_iface() {
done
# is mesh
for w in $(qmp_get_devices mesh); do
for w in $(qmp_get_devices mesh); do
if [ "$w" == "$device" ]; then
viface="mesh_${id_char}${id_num}"
break
fi
done
echo "$viface"
echo "$viface"
}
# arg1=<mesh|lan|wan>, returns the devices which have to be configured in such mode
qmp_get_devices() {
local devices=""
if [ "$1" == "mesh" ]; then
if [ "$1" == "mesh" ]; then
local brlan_enabled=0
for dev in $(uci get qmp.interfaces.mesh_devices 2>/dev/null); do
......@@ -181,7 +181,7 @@ qmp_get_devices() {
# Scan and configure the network devices (lan, mesh and wan)
# if $1 is set to "force", it rescan all devices
# if $1 is set to "force", it rescan all devices
qmp_configure_smart_network() {
echo "---------------------------------------"
echo "Starting smart networking configuration"
......@@ -193,16 +193,16 @@ qmp_configure_smart_network() {
local dev=""
local phydevs=""
local ignore_devs=""
[ "$force" != "force" ] && {
ignore_devs="$(qmp_uci_get interfaces.ignore_devices)"
}
for dev in $(ls /sys/class/net/); do
[ -e /sys/class/net/$dev/device ] || [ dev == "eth0" ] && {
local id
local id
local ignore=0
# Check if device is in the ignore list
for id in $ignore_devs; do
[ "$id" == "$dev" ] && ignore=1
......@@ -213,7 +213,7 @@ qmp_configure_smart_network() {
done
phydevs="$(echo -e "$phydevs" | grep -v -e ".*ap$" | grep -v "\\." | sort -u | tr -d ' ' \t)"
# if force is not enabled, we are not changing the existing lan/wan/mesh (only adding new ones)
[ "$force" != "force" ] && {
lan="$(qmp_uci_get interfaces.lan_devices)"
......@@ -227,7 +227,7 @@ qmp_configure_smart_network() {
local cdev
for dev in $phydevs; do
# If force is enabled, do not check if the device is already configured
# If force is enabled, do not check if the device is already configured
[ "$force" != "force" ] && {
cnt=0
# If it is already configured, doing nothing
......@@ -242,7 +242,7 @@ qmp_configure_smart_network() {
done
[ $cnt -eq 1 ] && continue
}
# If not found before...
[ "$dev" == "eth0" ] && {
lan="$lan eth0"
......@@ -268,12 +268,12 @@ qmp_configure_smart_network() {
# if there is already LAN device and it is not wifi, use as WAN
[ -z "$wan" ] && wan="$dev" && continue
# else use as LAN and MESH
lan="$dev $lan"
mesh="$dev $mesh"
done
echo "Network devices found:"
echo "- LAN $lan"
echo "- MESH $mesh"
......@@ -289,8 +289,8 @@ qmp_configure_smart_network() {
qmp_attach_device_to_interface() {
local device=$1
local interface=$2
local intype="$(qmp_uci_get_raw network.$interface.type)"
local intype="$(qmp_uci_get_raw network.$interface.type)"
echo "Attaching device $device to interface $interface"
# is it a wifi device?
......@@ -327,7 +327,7 @@ qmp_configure_routerstationpro_switch() {
uci set network.mesh_ports_vid1.vid="1"
uci set network.mesh_ports_vid1.device="eth1"
uci set network.mesh_ports_vid1.ports="0t 4"
for vid in $vids
do
uci set network.mesh_ports_vid$vid="switch_vlan"
......@@ -618,7 +618,7 @@ qmp_configure_network() {
echo "-----------------------"
qmp_configure_prepare_network $conf
# LoopBack device
uci set $conf.loopback="interface"
uci set $conf.loopback.ifname="lo"
......@@ -632,13 +632,13 @@ qmp_configure_network() {
qmp_configure_lan
# MESH devices
qmp_configure_mesh
uci commit
}
qmp_remove_qmp_bmx6_tunnels()
{
{
if echo "$1" | grep -q "^qmp_"
then
uci delete bmx6.$1
......@@ -680,9 +680,9 @@ qmp_add_qmp_bmx6_tunnels()
local ignore
local t
config_get ignore "$section" ignore
[ "$ignore" = "1" ] && return
local type="$(qmp_uci_get_raw gateways.$name.type)"
qmp_log Configuring gateway $name of type $type
[ -z "$name" ] && name="qmp_$gateway" || name="qmp_$name"
......@@ -695,7 +695,7 @@ qmp_add_qmp_bmx6_tunnels()
for t in \
network \
bandwidth
do
do
qmp_translate_configuration gateways $section $t $config $name
done
else
......@@ -730,11 +730,11 @@ qmp_add_qmp_bmx6_tunnels()
srcType \
gwId \
ipMetric
do
do
qmp_translate_configuration gateways $section $t $config $name
done
fi
gateway="$(($gateway + 1))"
}
......@@ -773,9 +773,9 @@ qmp_configure_bmx6() {
local community_node_id=$(qmp_get_id)
if qmp_uci_test qmp.interfaces.mesh_devices &&
if qmp_uci_test qmp.interfaces.mesh_devices &&
qmp_uci_test qmp.networks.mesh_protocol_vids
then
local counter=1
......@@ -783,20 +783,20 @@ qmp_configure_bmx6() {
for protocol_vid in $(uci get qmp.networks.mesh_protocol_vids); do
local protocol_name="$(echo $protocol_vid | awk -F':' '{print $1}')"
if [ "$protocol_name" = "bmx6" ] ; then
# Check if the current device is configured as no-vlan
local use_vlan=1
for no_vlan_int in $(qmp_uci_get interfaces.no_vlan_devices); do
[ "$no_vlan_int" == "$dev" ] && use_vlan=0
done
# If vlan tagging
if [ $use_vlan -eq 1 ]; then
local vid="$(echo $protocol_vid | awk -F':' '{print $2}')"
local ifname="$dev.$vid"
# If not vlan tagging
else
local ifname="$dev"
......
......@@ -44,7 +44,7 @@ qmp_set_gateway()
{
local name="$1"
shift
while [ $# -ge 2 ]
do
qmp_uci_set_raw gateways.$name.$1="$2"
......@@ -67,7 +67,7 @@ qmp_gw_search_default_ipv6() {
}
qmp_gw_offer_default_ipv4() {
qmp_set_gateway inet4 ignore 1
qmp_set_gateway inet4 ignore 1
qmp_set_gateway inet4_offer ignore 0 type offer network 0.0.0.0/0
qmp_gw_masq_wan 1
}
......@@ -78,13 +78,13 @@ qmp_gw_offer_default_ipv6() {
}
qmp_gw_disable_default_ipv4() {
qmp_set_gateway inet4 ignore 1
qmp_set_gateway inet4 ignore 1
qmp_set_gateway inet_offer ignore 1
qmp_gw_masq_wan 0
}
qmp_gw_disable_default_ipv6() {
qmp_set_gateway inet6 ignore 1
qmp_set_gateway inet6 ignore 1
qmp_set_gateway inet6_offer ignore 1
}
......@@ -150,7 +150,7 @@ qmp_gw_masq_wan() {
fi
qmp_gw_add_interfaces_to_firewall_zone $cfg
uci commit firewall
}
......
......@@ -51,7 +51,7 @@ qmp_set_mss_clamping_and_masq() {
}
# Prepare config files
qmp_configure_prepare_network() {
qmp_configure_prepare_network() {
local toRemove="$(uci show network | egrep "network.(lan|wan|mesh_).*=interface" | cut -d. -f2 | cut -d= -f1)"
echo "Removing current network configuration"
for i in $toRemove; do
......@@ -101,8 +101,8 @@ qmp_publish_hna_bmx6() {
else
uci set bmx6.$name_id=unicastHna
uci set bmx6.$name_id.unicastHna="$netid/$netmask"
fi
fi
uci commit bmx6
bmx6 -c --test -u $netid/$netmask > /dev/null
......@@ -126,7 +126,7 @@ qmp_unpublish_hna_bmx6() {
else
uci delete bmx6.$1
fi
uci commit
bmx6 -c --configReload
}
......@@ -142,13 +142,13 @@ qmp_radvd_enable_dev() {
break
fi
done
if [ -z "$cfg" ]; then
if [ -z "$cfg" ]; then
echo "Cannot find radvd config for $dev. Addind new one"
cfg="$(uci add radvd interface)"
uci set radvd.$cfg.interface=$dev
fi
uci set radvd.$cfg.ignore=0
uci set radvd.$cfg.AdvSendAdvert=1
uci set radvd.$cfg.AdvManagedFlag=1
......@@ -179,7 +179,7 @@ qmp_radvd_enable_prefix() {
return
fi
done
# If the configuration is not found, creating new one"
if [ -z "$cfg" ]; then
cfg=$(uci add radvd prefix)
......@@ -217,7 +217,7 @@ qmp_radvd_enable_route() {
return
fi
done
# If the configuration is not found, creating new one"
if [ -z "$cfg" ]; then
cfg=$(uci add radvd route)
......@@ -241,7 +241,7 @@ qmp_configure_lan_v6() {
local dev="$(qmp_uci_get node.primary_device)"
if [ -z "$dev" ]; then
if [ -z "$dev" ]; then
lanid="$(cat /var/log/*.log | md5sum | awk '{print $1}' | cut -c1-4)"
else
lanid="$(qmp_get_id)"
......@@ -266,7 +266,7 @@ qmp_configure_lan_v6() {
qmp_radvd_enable_prefix lan $ulan_ip
qmp_radvd_enable_route lan fc00::/7
/etc/init.d/radvd restart
echo "Done"
}
......@@ -276,7 +276,7 @@ qmp_configure_lan() {
local dns="$(qmp_uci_get networks.dns)"
local lan_mask="$(qmp_uci_get networks.lan_netmask)"
local lan_addr="$(qmp_uci_get networks.lan_address)"
# If the lan address is empty in the configuration
[ -z "$lan_addr" ] && {
[ $(qmp_uci_get roaming.ignore) -eq 0 ] && {
......@@ -302,7 +302,7 @@ qmp_configure_lan() {
qmp_uci_set networks.lan_address $lan_addr
qmp_uci_set networks.lan_netmask $lan_mask
fi
# Configure DHCP
qmp_configure_dhcp
......@@ -344,12 +344,12 @@ qmp_configure_wan() {
qmp_configure_mesh() {
local counter=1
if qmp_uci_test qmp.interfaces.mesh_devices &&
if qmp_uci_test qmp.interfaces.mesh_devices &&
qmp_uci_test qmp.networks.mesh_protocol_vids; then
for dev in $(qmp_get_devices mesh); do
echo "Configuring "$dev" for Meshing"
# Check if the current device is configured as no-vlan
local use_vlan=1
for no_vlan_int in $(qmp_uci_get interfaces.no_vlan_devices 2>/dev/null); do
......@@ -358,23 +358,23 @@ qmp_configure_mesh() {
local protocol_vids="$(qmp_uci_get networks.mesh_protocol_vids 2>/dev/null)"
[ -z "$protocol_vids" ] && protocol_vids="bmx6:12"
local primary_mesh_device="$(qmp_get_primary_device)"
for protocol_vid in $protocol_vids; do
local protocol_name="$(echo $protocol_vid | awk -F':' '{print $1}')"
local vid="$(echo $protocol_vid | awk -F':' '{print $2}')"
# virtual interface
local viface=$(qmp_get_virtual_iface $dev)
# put typical IPv6 prefix (2002::), otherwise ipv6 calc assumes mapped or embedded ipv4 address
local ip6_suffix="2002::${counter}${vid}"
# Since all interfaces are defined somewhere (LAN, WAN or with Rescue IP),
# in case of not use vlan tag, device definition is not needed.
local ip6_suffix="2002::${counter}${vid}"
# Since all interfaces are defined somewhere (LAN, WAN or with Rescue IP),
# in case of not use vlan tag, device definition is not needed.
[ $use_vlan -eq 1 ] || [ $vid -gt 0 ] && qmp_set_vlan $viface $vid
# Configure IPv6 address only if mesh_prefix48 is defined (bmx6 does not need it)
if qmp_uci_test qmp.networks.${protocol_name}_mesh_prefix48; then
local ip6="$(qmp_get_ula96 $(uci get qmp.networks.${protocol_name}_mesh_prefix48):: $primary_mesh_device $ip6_suffix 128)"
......@@ -386,7 +386,7 @@ qmp_configure_mesh() {
qmp_uci_set_raw network.${viface}_$vid.auto=1
fi
done
qmp_configure_rescue_ip_device "$dev" "$viface"
counter=$(( $counter + 1 ))
done
......@@ -398,14 +398,14 @@ qmp_configure_mesh() {
qmp_configure_rescue_ip_device() {
local dev="$1"
local viface="$2"
if qmp_is_in "$dev" $(qmp_get_devices wan) || [ "$dev" == "br-lan" ]; then
# If it is WAN or LAN
qmp_configure_rescue_ip $dev ${viface}_rescue
qmp_attach_device_to_interface $dev ${viface}_rescue
elif qmp_is_in "$dev" $(qmp_get_devices mesh) && [ "$dev" != "br-lan" ]; then
# If it is only mesh device
qmp_configure_rescue_ip $dev
qmp_configure_rescue_ip $dev
qmp_attach_device_to_interface $dev $viface
fi
}
......@@ -413,15 +413,15 @@ qmp_configure_rescue_ip_device() {
qmp_configure_rescue_ip() {
local device=$1
[ -z "$device" ] && return 1
local rip="$(qmp_get_rescue_ip $device)"
[ -z "$rip" ] && { echo "Cannot get rescue IP for device $device"; return 1; }
local viface="${2:-$(qmp_get_virtual_iface $device)}"
echo "Rescue IP for device $device/$viface is $rip"
echo "Rescue IP for device $device/$viface is $rip"
local conf="network"
uci set $conf.${viface}="interface"
#qmp_attach_viface_to_interface $viface $conf ${viface}
uci set $conf.${viface}.proto="static"
......@@ -437,7 +437,7 @@ qmp_get_rescue_ip() {
local rprefix=$(qmp_uci_get networks.rescue_prefix24 2>/dev/null)
rprefix=${rprefix:-169.254}
# if device is virtual, get the ifname
if qmp_uci_test network.$device.ifname; then
local devvirt="$(qmp_uci_get_raw network.$device.ifname | tr -d @)"
......@@ -453,7 +453,7 @@ qmp_get_rescue_ip() {
fi
mac=${mac:-FF:FF:FF:FF:FF:FF}
#local xoctet=$(printf "%d\n" 0x$(echo $mac | cut -d: -f5))
local yoctet=$(printf "%d\n" 0x$(echo $mac | cut -d: -f6))
local rip="$rprefix.$yoctet.1"
......@@ -469,7 +469,7 @@ qmp_configure_dhcp() {
local limit=253
local leasetime="$(qmp_uci_get non_overlapping.qmp_leasetime)"
leasetime=${leasetime:-1h}
# If DHCP non overlapping enabled, configuring it (this is the layer3 roaming)
if [ "$(qmp_uci_get non_overlapping.ignore)" == "0" ]; then
echo "Configuring DHCP non-overlapping (roaming mode)"
......@@ -516,7 +516,7 @@ qmp_bmx6_reload() {
restart_bmx6=true
fi
fi
if $restart_bmx6
then
/etc/init.d/bmx6 restart
......
......@@ -40,15 +40,15 @@ qmp_configure_system() {
local community_node_id=$(qmp_get_id_hostname)
qmp_uci_set node.community_node_id $community_node_id
fi
# check if community_node_id is hexadecimal and get last 4 characters
community_node_id="$(echo -n $community_node_id | tr -cd 'ABCDEFabcdef0123456789' | tail -c 4)"
[ $(echo -n $community_node_id | wc -c) -lt 4 ] && {
qmp_log "Warning, community_node_id not defined properly, using failsafe 0000"
community_node_id=0000
}