1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-03-09 15:40:03 +00:00

Small cleaning codes changes in OMR-Tracker scripts

This commit is contained in:
Ycarus (Yannick Chabanois) 2024-07-05 16:01:10 +02:00
parent 17f047fe01
commit e33bd66daf
3 changed files with 62 additions and 62 deletions

View file

@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
# shellcheck disable=SC1091,SC1090
# vim: set noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 :
@ -34,9 +34,10 @@ export OMR_TRACKER_INTERVAL_TRIES
export OMR_TRACKER_INTERVAL
export OMR_TRACKER_NO_BIND
dscp=56 # set DSCP CS7 (56) in outgoing packets
initial_hosts="$OMR_TRACKER_HOSTS"
initial_hosts6="$OMR_TRACKER_HOSTS6"
#dscp=56 # set DSCP CS7 (56) in outgoing packets
#initial_hosts="$OMR_TRACKER_HOSTS"
#initial_hosts6="$OMR_TRACKER_HOSTS6"
initial_timeout="$OMR_TRACKER_TIMEOUT"
wait_test=${OMR_TRACKER_WAIT_TEST:-0}
@ -102,15 +103,15 @@ _post_tracking() {
}
_ping_server() {
local servername=$1
local servername="$1"
[ -z "$servername" ] && return
local disabled=$(uci -q get openmptcprouter.$1.disabled)
local device=$2
local disabled=$(uci -q get openmptcprouter."$servername".disabled)
local device="$2"
if [ -n "$device" ] && [ "$disabled" != "1" ]; then
check_ping() {
serverip=$1
serverip="$1"
if [ -n "$serverip" ]; then
_ping $serverip $device "yes"
_ping "$serverip" "$device" "yes"
statusp=$?
if $(exit $statusp); then
serverip_ping=true
@ -119,21 +120,21 @@ _ping_server() {
fi
}
config_load openmptcprouter
config_list_foreach ${servername} ip check_ping
config_list_foreach "${servername}" ip check_ping
fi
}
_httping_server() {
local servername=$1
local servername="$1"
[ -z "$servername" ] && return
local disabled=$(uci -q get openmptcprouter.$1.disabled)
local port=$(uci -q get openmptcprouter.$1.port)
local device=$2
local disabled=$(uci -q get openmptcprouter."$servername".disabled)
local port=$(uci -q get openmptcprouter."$servername".port)
local device="$2"
if [ -n "$device" ] && [ "$disabled" != "1" ]; then
check_ping() {
serverip=$1
serverip="$1"
if [ -n "$serverip" ]; then
_httping "${serverip}:${port}" $device "yes" true
_httping "${serverip}:${port}" "$device" "yes" true
statusp=$?
if $(exit $statusp); then
serverip_ping=true
@ -142,15 +143,15 @@ _httping_server() {
fi
}
config_load openmptcprouter
config_list_foreach ${servername} ip check_ping
config_list_foreach "${servername}" ip check_ping
fi
}
_ping() {
local host=$1
local host="$1"
[ -z "$host" ] && return
local device=$2
local localip=$3
local device="$2"
local localip="$3"
if [ -n "$OMR_TRACKER_INTERFACE" ] && { [ "$OMR_TRACKER_NO_BIND" = "1" ] || [ "$(uci -q get network.$OMR_TRACKER_INTERFACE.proto)" = "3g" ] || [ "$(uci -q get network.$OMR_TRACKER_INTERFACE.proto)" = "qmi" ] || [ "$(uci -q get network.$OMR_TRACKER_INTERFACE.proto)" = "ncm" ]; }; then
ret=$(ping -I "${device}" \
-w "$OMR_TRACKER_TIMEOUT" \
@ -162,7 +163,7 @@ _ping() {
) && echo "$ret" | grep -sq " 0% packet loss" && {
if [ "$localip" = "yes" ]; then
OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n')
_update_rto "$OMR_TRACKER_LATENCY"
#_update_rto "$OMR_TRACKER_LATENCY"
fi
return
}
@ -184,7 +185,7 @@ _ping() {
latency=$(echo "$ret" | grep rtt | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n')
[ -n "$latency" ] && {
OMR_TRACKER_LATENCY="$latency"
_update_rto "$OMR_TRACKER_LATENCY"
#_update_rto "$OMR_TRACKER_LATENCY"
}
OMR_TRACKER_LOSS="$loss"
fi
@ -208,7 +209,7 @@ _httping() {
) && echo "$ret" | grep -sq "1 ok" && {
if [ "$localip" = "yes" ]; then
OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n')
_update_rto "$OMR_TRACKER_LATENCY"
#_update_rto "$OMR_TRACKER_LATENCY"
fi
return
}
@ -220,7 +221,7 @@ _httping() {
) && echo "$ret" | grep -sq "1 ok" && {
if [ "$localip" = "yes" ]; then
OMR_TRACKER_LATENCY=$(echo "$ret" | cut -d "/" -s -f5 | cut -d "." -f1 | tr -d '\n')
_update_rto "$OMR_TRACKER_LATENCY"
#_update_rto "$OMR_TRACKER_LATENCY"
fi
return
}
@ -238,7 +239,7 @@ _dns() {
one.one.one.one
) && echo "$ret" | grep -sq "1.1.1.1" && {
OMR_TRACKER_LATENCY=$(echo "$ret" | awk '/Query time/{print $4}')
_update_rto "$OMR_TRACKER_LATENCY"
#_update_rto "$OMR_TRACKER_LATENCY"
return
}
false
@ -267,8 +268,8 @@ while true; do
OMR_TRACKER_DEVICE_GATEWAY6=
serverip_ping=false
[ -z "$OMR_TRACKER_DEVICE" ] && {
network_get_device OMR_TRACKER_DEVICE $OMR_TRACKER_INTERFACE
[ -z "$OMR_TRACKER_DEVICE" ] && network_get_physdev OMR_TRACKER_DEVICE $OMR_TRACKER_INTERFACE
network_get_device OMR_TRACKER_DEVICE "$OMR_TRACKER_INTERFACE"
[ -z "$OMR_TRACKER_DEVICE" ] && network_get_physdev OMR_TRACKER_DEVICE "$OMR_TRACKER_INTERFACE"
[ -z "$OMR_TRACKER_DEVICE" ] && OMR_TRACKER_DEVICE=$(ifstatus "$OMR_TRACKER_INTERFACE" | jsonfilter -q -e '@["l3_device"]')
[ -z "$OMR_TRACKER_DEVICE" ] && OMR_TRACKER_DEVICE=$(ifstatus "${OMR_TRACKER_INTERFACE}_4" | jsonfilter -q -e '@["l3_device"]')
#[ -z "$OMR_TRACKER_DEVICE" ] && config_get OMR_TRACKER_DEVICE "$OMR_TRACKER_INTERFACE" device
@ -278,7 +279,7 @@ while true; do
if [ -n "$OMR_TRACKER_DEVICE" ] && [ -d "/sys/class/net/$OMR_TRACKER_DEVICE" ]; then
if [ -n "$(ip link show $OMR_TRACKER_DEVICE | grep 'state UP')" ] || [ -n "$(ip link show $OMR_TRACKER_DEVICE | grep 'state UNKNOWN')" ]; then
# retrieve iface ip and gateway
if ([ "$OMR_TRACKER_FAMILY" = "ipv4" ] || [ "$OMR_TRACKER_FAMILY" = "ipv4ipv6" ]) && [ "$OMR_TRACKER_INTERFACE_PROTO" != "dhcpv6" ]; then
if { [ "$OMR_TRACKER_FAMILY" = "ipv4" ] || [ "$OMR_TRACKER_FAMILY" = "ipv4ipv6" ]; } && [ "$OMR_TRACKER_INTERFACE_PROTO" != "dhcpv6" ]; then
OMR_TRACKER_DEVICE_IP=$(ip -4 -br addr ls dev "$OMR_TRACKER_DEVICE" | awk -F'[ /]+' '{print $3}')
if [ -z "$OMR_TRACKER_DEVICE_IP" ]; then
OMR_TRACKER_DEVICE_IP=$(ip -4 addr show dev "$OMR_TRACKER_DEVICE" | grep -m 1 inet | awk '{print $2}' | cut -d'/' -s -f1)