1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-02-13 11:01:50 +00:00
openmptcprouter-feeds/openmptcprouter/files/bin/omr-test-speed-server
Ycarus (Yannick Chabanois) 6cbb420ffa Fixes for test speed scripts
2023-08-08 21:55:28 +02:00

55 lines
No EOL
2.2 KiB
Bash
Executable file

#!/bin/sh
SERVER=$1
INTERFACE=$2
[ "$3" = "upload" ] && UPLOAD=$3
[ "$3" = "fasttest" ] && FASTTEST=$3
[ "$4" = "upload" ] && UPLOAD=$4
[ "$4" = "fasttest" ] && FASTTEST=$4
[ -z "$SERVER" ] && SERVER="vps"
KEY=$(uci -q get openmptcprouter.$SERVER.token)
HOST=$(uci -q get openmptcprouter.$SERVER.ip | awk '{print $1}')
PORT=$(uci -q get openmptcprouter.$SERVER.port)
MP=false
if [ -n "$KEY" ] && [ -n "$HOST" ] && [ -n "$PORT" ]; then
trap : HUP INT TERM
[ -z "$FASTTEST" ] && echo "Disable SQM bandwidth limit on $INTERFACE"
[ -n "$(tc qdisc | grep $INTERFACE | grep bandwidth)" ] && {
export SQM_VERBOSITY_MIN=10
export SQM_VERBOSITY_MAX=0
export SQM_SYSLOG=1
/etc/init.d/sqm stop $INTERFACE 2>&1 >/dev/null
#tc qdisc delete dev $INTERFACE root 2>&1 >/dev/null
#tc qdisc delete dev ifb4$INTERFACE root 2>&1 >/dev/null
}
[ -z "$FASTTEST" ] && echo "Download test via server ${SERVER}:"
if [ -n "$INTERFACE" ]; then
#if [ "$(multipath ${INTERFACE} | grep default)" ]; then
# MP=true
# /etc/init.d/omr-tracker stop 2>&1 >/dev/null
# multipath ${INTERFACE} off
#fi
if [ -n "$FASTTEST" ]; then
if [ -n "$UPLOAD" ]; then
avg_speed=$(curl -k --max-time 30 -o /dev/null -qfsS -w '%{speed_upload}' -X POST -d @/boot/vmlinuz -d @/boot/vmlinuz --interface $INTERFACE -H "Authorization: Bearer ${KEY}" https://${HOST}:${PORT}/speedtest 2>/dev/null)
echo -n "$avg_speed"
else
avg_speed=$(curl -k --max-time 30 -o /dev/null -qfsS -w '%{speed_download}' --interface $INTERFACE -H "Authorization: Bearer ${KEY}" https://${HOST}:${PORT}/speedtest 2>/dev/null)
echo -n "$avg_speed"
fi
else
if [ -n "$UPLOAD" ]; then
curl -k -o /dev/null -X POST -d @/boot/vmlinuz -d @/boot/vmlinuz --interface $INTERFACE -H "Authorization: Bearer ${KEY}" https://${HOST}:${PORT}/speedtest || echo
else
curl -k -o /dev/null --interface $INTERFACE -H "Authorization: Bearer ${KEY}" https://${HOST}:${PORT}/speedtest || echo
fi
fi
#if [ $MP ]; then
# multipath ${INTERFACE} on
# /etc/init.d/omr-tracker start & 2>&1 >/dev/null
#fi
else
curl -k -o /dev/null -H "Authorization: Bearer ${KEY}" https://${HOST}:${PORT}/speedtest || echo
fi
[ -z "$FASTTEST" ] && echo "Restart SQM on $INTERFACE"
/etc/init.d/sqm start $INTERFACE 2>&1 >/dev/null
fi