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() { ...@@ -236,10 +236,10 @@ qmp_get_dev_from_wifi_mac() {
qmp_hooks_exec() { qmp_hooks_exec() {
local stage="$1" local stage="$1"
local device="none" local device="none"
[ -e /tmp/sysinfo/board_name ] && device="$(cat /tmp/sysinfo/board_name 2>/dev/null)" \ [ -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 ' ') || device=$(cat /proc/cpuinfo | grep vendor_id | cut -d: -f2 | tr -d ' ')
[ -z "$stage" -o -z "$device" ] && return 1 [ -z "$stage" -o -z "$device" ] && return 1
local hooksdir="/etc/qmp/hooks/$device" local hooksdir="/etc/qmp/hooks/$device"
...@@ -255,7 +255,7 @@ qmp_hooks_exec() { ...@@ -255,7 +255,7 @@ qmp_hooks_exec() {
# ID/IP commands # 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 no parameter it returns the entire hash
# If parameter = 1 or 2, returns the first/second 8bit module 256 # If parameter = 1 or 2, returns the first/second 8bit module 256
qmp_get_crc16() { qmp_get_crc16() {
...@@ -267,7 +267,7 @@ qmp_get_crc16() { ...@@ -267,7 +267,7 @@ qmp_get_crc16() {
} }
# qmp_get_id [8bit] # qmp_get_id [8bit]
qmp_get_id() { qmp_get_id() {
local community_node_id="$(qmp_uci_get node.community_node_id)" local community_node_id="$(qmp_uci_get node.community_node_id)"
[ -z "$community_node_id" ] && \ [ -z "$community_node_id" ] && \
community_node_id="$(qmp_get_crc16)" community_node_id="$(qmp_get_crc16)"
......
...@@ -112,33 +112,33 @@ upgrade() { ...@@ -112,33 +112,33 @@ upgrade() {
hard_reboot() { hard_reboot() {
echo "System is gonna be rebooted now!" echo "System is gonna be rebooted now!"
echo 1 > /proc/sys/kernel/sysrq echo 1 > /proc/sys/kernel/sysrq
echo b > /proc/sysrq-trigger echo b > /proc/sysrq-trigger
} }
configure_all() { configure_all() {
configure_system configure_system
configure_wifi configure_wifi
configure_network configure_network
} }
safe_apply() { 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!" \ [ -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..." echo "Cannot found saved state, saving it..."
save_state save_state
} }
touch /tmp/qmp.safe.test touch /tmp/qmp.safe.test
echo "------------------------------------------------------------------------------------" 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" 180 seconds to remove it or the previous state will be recovered"
echo "------------------------------------------------------------------------------------" echo "------------------------------------------------------------------------------------"
read -p'Do you agree?[y,N] ' a read -p'Do you agree?[y,N] ' a
[ "$a" != "y" ] && return [ "$a" != "y" ] && return
configure_all configure_all
( sleep 180 ( sleep 180
[ -e "/tmp/qmp.safe.test" ] && { [ -e "/tmp/qmp.safe.test" ] && {
cp -f /etc/config/qmp /tmp/qmp.wrong cp -f /etc/config/qmp /tmp/qmp.wrong
...@@ -164,7 +164,7 @@ recover_state() { ...@@ -164,7 +164,7 @@ recover_state() {
help() { help() {
echo "Use: $0 <function> [params]" echo "Use: $0 <function> [params]"
echo "" echo ""
echo "Configuration:" echo "Configuration:"
echo " configure_all : Configure and apply all settings" echo " configure_all : Configure and apply all settings"
...@@ -173,13 +173,13 @@ help() { ...@@ -173,13 +173,13 @@ help() {
echo " configure_wifi : Configure all WiFi devices" echo " configure_wifi : Configure all WiFi devices"
echo " reset_wifi : Reset, rescan and configure all the WiFi devices" echo " reset_wifi : Reset, rescan and configure all the WiFi devices"
echo " configure_gw : Configure and apply gateways settings" echo " configure_gw : Configure and apply gateways settings"
echo "" echo ""
echo "Safe configuration:" echo "Safe configuration:"
echo " save_state : Saves current state of configuration files" echo " save_state : Saves current state of configuration files"
echo " recover_state : Recovers previous saved state" 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 " safe_apply : Performs a safe configure_all. If something wrong it comes back to old state"
echo "" echo ""
echo "Gateways:" echo "Gateways:"
echo " offer_default_gw [ipv4|ipv6] : Offers default gw to the network IPv4 or IPv6, both versions if no value" 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() { ...@@ -194,7 +194,7 @@ help() {
echo " enable_ns_ppt : Enable POE passtrought from NanoStation M2/5 devices. Be careful with this option!" 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 " 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 " hard_reboot : Performs a hard reboot (using kernel sysrq)"
echo "" echo ""
exit 0 exit 0
} }
......
...@@ -51,14 +51,14 @@ qmp_get_llocal_for_dev() { ...@@ -51,14 +51,14 @@ qmp_get_llocal_for_dev() {
# returns primary device # returns primary device
qmp_get_primary_device() { qmp_get_primary_device() {
local primary_mesh_device="$(uci get qmp.node.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 if ip link show dev eth0 > /dev/null; then
primary_mesh_device="eth0" primary_mesh_device="eth0"
else else
primary_mesh_device="$(ip link show | awk '!/lo:/&&/^[0-9]?:/{sub(/:$/,"",$2); print $2; exit}')" primary_mesh_device="$(ip link show | awk '!/lo:/&&/^[0-9]?:/{sub(/:$/,"",$2); print $2; exit}')"
fi 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" echo "$primary_mesh_device"
} }
...@@ -102,8 +102,8 @@ qmp_get_virtual_iface() { ...@@ -102,8 +102,8 @@ qmp_get_virtual_iface() {
return return
fi fi
for l in $(qmp_get_devices lan); do for l in $(qmp_get_devices lan); do
if [ "$l" == "$device" ]; then if [ "$l" == "$device" ]; then
viface="lan" viface="lan"
echo $viface echo $viface
return return
...@@ -117,7 +117,7 @@ qmp_get_virtual_iface() { ...@@ -117,7 +117,7 @@ qmp_get_virtual_iface() {
local id_char=$(echo $device | cut -c 1) local id_char=$(echo $device | cut -c 1)
# is wan # is wan
for w in $(qmp_get_devices wan); do for w in $(qmp_get_devices wan); do
if [ "$w" == "$device" ]; then if [ "$w" == "$device" ]; then
viface="wan_${id_char}${id_num}" viface="wan_${id_char}${id_num}"
echo $viface echo $viface
...@@ -126,21 +126,21 @@ qmp_get_virtual_iface() { ...@@ -126,21 +126,21 @@ qmp_get_virtual_iface() {
done done
# is mesh # is mesh
for w in $(qmp_get_devices mesh); do for w in $(qmp_get_devices mesh); do
if [ "$w" == "$device" ]; then if [ "$w" == "$device" ]; then
viface="mesh_${id_char}${id_num}" viface="mesh_${id_char}${id_num}"
break break
fi fi
done done
echo "$viface" echo "$viface"
} }
# arg1=<mesh|lan|wan>, returns the devices which have to be configured in such mode # arg1=<mesh|lan|wan>, returns the devices which have to be configured in such mode
qmp_get_devices() { qmp_get_devices() {
local devices="" local devices=""
if [ "$1" == "mesh" ]; then if [ "$1" == "mesh" ]; then
local brlan_enabled=0 local brlan_enabled=0
for dev in $(uci get qmp.interfaces.mesh_devices 2>/dev/null); do for dev in $(uci get qmp.interfaces.mesh_devices 2>/dev/null); do
...@@ -181,7 +181,7 @@ qmp_get_devices() { ...@@ -181,7 +181,7 @@ qmp_get_devices() {
# Scan and configure the network devices (lan, mesh and wan) # 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() { qmp_configure_smart_network() {
echo "---------------------------------------" echo "---------------------------------------"
echo "Starting smart networking configuration" echo "Starting smart networking configuration"
...@@ -193,16 +193,16 @@ qmp_configure_smart_network() { ...@@ -193,16 +193,16 @@ qmp_configure_smart_network() {
local dev="" local dev=""
local phydevs="" local phydevs=""
local ignore_devs="" local ignore_devs=""
[ "$force" != "force" ] && { [ "$force" != "force" ] && {
ignore_devs="$(qmp_uci_get interfaces.ignore_devices)" ignore_devs="$(qmp_uci_get interfaces.ignore_devices)"
} }
for dev in $(ls /sys/class/net/); do for dev in $(ls /sys/class/net/); do
[ -e /sys/class/net/$dev/device ] || [ dev == "eth0" ] && { [ -e /sys/class/net/$dev/device ] || [ dev == "eth0" ] && {
local id local id
local ignore=0 local ignore=0
# Check if device is in the ignore list # Check if device is in the ignore list
for id in $ignore_devs; do for id in $ignore_devs; do
[ "$id" == "$dev" ] && ignore=1 [ "$id" == "$dev" ] && ignore=1
...@@ -213,7 +213,7 @@ qmp_configure_smart_network() { ...@@ -213,7 +213,7 @@ qmp_configure_smart_network() {
done done
phydevs="$(echo -e "$phydevs" | grep -v -e ".*ap$" | grep -v "\\." | sort -u | tr -d ' ' \t)" 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) # if force is not enabled, we are not changing the existing lan/wan/mesh (only adding new ones)
[ "$force" != "force" ] && { [ "$force" != "force" ] && {
lan="$(qmp_uci_get interfaces.lan_devices)" lan="$(qmp_uci_get interfaces.lan_devices)"
...@@ -227,7 +227,7 @@ qmp_configure_smart_network() { ...@@ -227,7 +227,7 @@ qmp_configure_smart_network() {
local cdev local cdev
for dev in $phydevs; do 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" ] && { [ "$force" != "force" ] && {
cnt=0 cnt=0
# If it is already configured, doing nothing # If it is already configured, doing nothing
...@@ -242,7 +242,7 @@ qmp_configure_smart_network() { ...@@ -242,7 +242,7 @@ qmp_configure_smart_network() {
done done
[ $cnt -eq 1 ] && continue [ $cnt -eq 1 ] && continue
} }
# If not found before... # If not found before...
[ "$dev" == "eth0" ] && { [ "$dev" == "eth0" ] && {
lan="$lan eth0" lan="$lan eth0"
...@@ -268,12 +268,12 @@ qmp_configure_smart_network() { ...@@ -268,12 +268,12 @@ qmp_configure_smart_network() {
# if there is already LAN device and it is not wifi, use as WAN # if there is already LAN device and it is not wifi, use as WAN
[ -z "$wan" ] && wan="$dev" && continue [ -z "$wan" ] && wan="$dev" && continue
# else use as LAN and MESH # else use as LAN and MESH
lan="$dev $lan" lan="$dev $lan"
mesh="$dev $mesh" mesh="$dev $mesh"
done done
echo "Network devices found:" echo "Network devices found:"
echo "- LAN $lan" echo "- LAN $lan"
echo "- MESH $mesh" echo "- MESH $mesh"
...@@ -289,8 +289,8 @@ qmp_configure_smart_network() { ...@@ -289,8 +289,8 @@ qmp_configure_smart_network() {
qmp_attach_device_to_interface() { qmp_attach_device_to_interface() {
local device=$1 local device=$1
local interface=$2 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" echo "Attaching device $device to interface $interface"
# is it a wifi device? # is it a wifi device?
...@@ -327,7 +327,7 @@ qmp_configure_routerstationpro_switch() { ...@@ -327,7 +327,7 @@ qmp_configure_routerstationpro_switch() {
uci set network.mesh_ports_vid1.vid="1" uci set network.mesh_ports_vid1.vid="1"
uci set network.mesh_ports_vid1.device="eth1" uci set network.mesh_ports_vid1.device="eth1"
uci set network.mesh_ports_vid1.ports="0t 4" uci set network.mesh_ports_vid1.ports="0t 4"
for vid in $vids for vid in $vids
do do
uci set network.mesh_ports_vid$vid="switch_vlan" uci set network.mesh_ports_vid$vid="switch_vlan"
...@@ -618,7 +618,7 @@ qmp_configure_network() { ...@@ -618,7 +618,7 @@ qmp_configure_network() {
echo "-----------------------" echo "-----------------------"
qmp_configure_prepare_network $conf qmp_configure_prepare_network $conf
# LoopBack device # LoopBack device
uci set $conf.loopback="interface" uci set $conf.loopback="interface"
uci set $conf.loopback.ifname="lo" uci set $conf.loopback.ifname="lo"
...@@ -632,13 +632,13 @@ qmp_configure_network() { ...@@ -632,13 +632,13 @@ qmp_configure_network() {
qmp_configure_lan qmp_configure_lan
# MESH devices # MESH devices
qmp_configure_mesh qmp_configure_mesh
uci commit uci commit
} }
qmp_remove_qmp_bmx6_tunnels() qmp_remove_qmp_bmx6_tunnels()
{ {
if echo "$1" | grep -q "^qmp_" if echo "$1" | grep -q "^qmp_"
then then
uci delete bmx6.$1 uci delete bmx6.$1
...@@ -680,9 +680,9 @@ qmp_add_qmp_bmx6_tunnels() ...@@ -680,9 +680,9 @@ qmp_add_qmp_bmx6_tunnels()
local ignore local ignore
local t local t
config_get ignore "$section" ignore config_get ignore "$section" ignore
[ "$ignore" = "1" ] && return [ "$ignore" = "1" ] && return
local type="$(qmp_uci_get_raw gateways.$name.type)" local type="$(qmp_uci_get_raw gateways.$name.type)"
qmp_log Configuring gateway $name of type $type qmp_log Configuring gateway $name of type $type
[ -z "$name" ] && name="qmp_$gateway" || name="qmp_$name" [ -z "$name" ] && name="qmp_$gateway" || name="qmp_$name"
...@@ -695,7 +695,7 @@ qmp_add_qmp_bmx6_tunnels() ...@@ -695,7 +695,7 @@ qmp_add_qmp_bmx6_tunnels()
for t in \ for t in \
network \ network \
bandwidth bandwidth
do do
qmp_translate_configuration gateways $section $t $config $name qmp_translate_configuration gateways $section $t $config $name
done done
else else
...@@ -730,11 +730,11 @@ qmp_add_qmp_bmx6_tunnels() ...@@ -730,11 +730,11 @@ qmp_add_qmp_bmx6_tunnels()
srcType \ srcType \
gwId \ gwId \
ipMetric ipMetric
do do
qmp_translate_configuration gateways $section $t $config $name qmp_translate_configuration gateways $section $t $config $name
done done
fi fi
gateway="$(($gateway + 1))" gateway="$(($gateway + 1))"
} }
...@@ -773,9 +773,9 @@ qmp_configure_bmx6() { ...@@ -773,9 +773,9 @@ qmp_configure_bmx6() {
local community_node_id=$(qmp_get_id) 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 qmp_uci_test qmp.networks.mesh_protocol_vids
then then
local counter=1 local counter=1
...@@ -783,20 +783,20 @@ qmp_configure_bmx6() { ...@@ -783,20 +783,20 @@ qmp_configure_bmx6() {
for protocol_vid in $(uci get qmp.networks.mesh_protocol_vids); do for protocol_vid in $(uci get qmp.networks.mesh_protocol_vids); do
local protocol_name="$(echo $protocol_vid | awk -F':' '{print $1}')" local protocol_name="$(echo $protocol_vid | awk -F':' '{print $1}')"
if [ "$protocol_name" = "bmx6" ] ; then if [ "$protocol_name" = "bmx6" ] ; then
# Check if the current device is configured as no-vlan # Check if the current device is configured as no-vlan
local use_vlan=1 local use_vlan=1
for no_vlan_int in $(qmp_uci_get interfaces.no_vlan_devices); do for no_vlan_int in $(qmp_uci_get interfaces.no_vlan_devices); do
[ "$no_vlan_int" == "$dev" ] && use_vlan=0 [ "$no_vlan_int" == "$dev" ] && use_vlan=0
done done
# If vlan tagging # If vlan tagging
if [ $use_vlan -eq 1 ]; then if [ $use_vlan -eq 1 ]; then
local vid="$(echo $protocol_vid | awk -F':' '{print $2}')" local vid="$(echo $protocol_vid | awk -F':' '{print $2}')"
local ifname="$dev.$vid" local ifname="$dev.$vid"
# If not vlan tagging # If not vlan tagging
else else
local ifname="$dev" local ifname="$dev"
......
...@@ -44,7 +44,7 @@ qmp_set_gateway() ...@@ -44,7 +44,7 @@ qmp_set_gateway()
{ {
local name="$1" local name="$1"
shift shift
while [ $# -ge 2 ] while [ $# -ge 2 ]
do do
qmp_uci_set_raw gateways.$name.$1="$2" qmp_uci_set_raw gateways.$name.$1="$2"
...@@ -67,7 +67,7 @@ qmp_gw_search_default_ipv6() { ...@@ -67,7 +67,7 @@ qmp_gw_search_default_ipv6() {
} }
qmp_gw_offer_default_ipv4() { 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_set_gateway inet4_offer ignore 0 type offer network 0.0.0.0/0
qmp_gw_masq_wan 1 qmp_gw_masq_wan 1
} }
...@@ -78,13 +78,13 @@ qmp_gw_offer_default_ipv6() { ...@@ -78,13 +78,13 @@ qmp_gw_offer_default_ipv6() {
} }
qmp_gw_disable_default_ipv4() { 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_set_gateway inet_offer ignore 1
qmp_gw_masq_wan 0 qmp_gw_masq_wan 0
} }
qmp_gw_disable_default_ipv6() { qmp_gw_disable_default_ipv6() {
qmp_set_gateway inet6 ignore 1 qmp_set_gateway inet6 ignore 1
qmp_set_gateway inet6_offer ignore 1 qmp_set_gateway inet6_offer ignore 1
} }
...@@ -150,7 +150,7 @@ qmp_gw_masq_wan() { ...@@ -150,7 +150,7 @@ qmp_gw_masq_wan() {
fi fi
qmp_gw_add_interfaces_to_firewall_zone $cfg qmp_gw_add_interfaces_to_firewall_zone $cfg
uci commit firewall uci commit firewall
} }
......
...@@ -51,7 +51,7 @@ qmp_set_mss_clamping_and_masq() { ...@@ -51,7 +51,7 @@ qmp_set_mss_clamping_and_masq() {
} }
# Prepare config files # 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)" local toRemove="$(uci show network | egrep "network.(lan|wan|mesh_).*=interface" | cut -d. -f2 | cut -d= -f1)"
echo "Removing current network configuration" echo "Removing current network configuration"
for i in $toRemove; do for i in $toRemove; do
...@@ -101,8 +101,8 @@ qmp_publish_hna_bmx6() { ...@@ -101,8 +101,8 @@ qmp_publish_hna_bmx6() {
else else
uci set bmx6.$name_id=unicastHna uci set bmx6.$name_id=unicastHna
uci set bmx6.$name_id.unicastHna="$netid/$netmask" uci set bmx6.$name_id.unicastHna="$netid/$netmask"
fi fi