v2ray/speedtest/speedtest/scripts/speedtest_config.sh
2018-12-07 22:59:10 +08:00

59 lines
1.6 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/sh
eval `dbus export speedtest`
source /jffs/softcenter/scripts/base.sh
version="0.2.3"
dbus set speedtest_version=$version
#定义更新相关地址
UPDATE_VERSION_URL="https://raw.githubusercontent.com/paldier/softcenter/master/speedtest/version"
UPDATE_TAR_URL="https://raw.githubusercontent.com/paldier/softcenter/master/speedtest/speedtest.tar.gz"
#检查版本
check_version(){
speedtest_version_web1=$(curl -s $UPDATE_VERSION_URL | sed -n 1p)
if [ ! -z $speedtest_version_web1 ];then
dbus set speedtest_version_web=$speedtest_version_web1
fi
}
##测速主逻辑开始
#检查是否在运行
speedtest_is_run=$(ps | grep "/jffs/softcenter/bin/speedtest" | grep -v grep)
#判断测速是否正在进行,确保只有一个测速进程
if [ ! -z "$speedtest_is_run" ]; then
exit 0
fi
#定义测速变量(1、正在测速0、测速完成)
dbus set speedtest_status=1
dbus ram speedtest_download=0
dbus ram speedtest_upload=0
check_version
#定义测速脚本
SPEEDTEST_CLI=`/jffs/softcenter/bin/speedtest 1 2 1 2 2>/dev/null`
echo "$SPEEDTEST_CLI" | while
#/jffs/softcenter/bin/speedtest 1 2 1 2 2>/dev/null | while
read line
do
download=$(echo $line | awk -F 'Download = ' '{print $2}' | grep -oE "[0-9]{1,5}[\.][0-9]{1,2}" | head -n 1)
upload=$(echo $line | awk -F 'Upload = ' '{print $2}' | grep -oE "[0-9]{1,5}[\.][0-9]{1,2}" | head -n 1)
if [[ ! -z $download ]]; then
#echo "download : "$download
dbus ram speedtest_download=$download
fi
if [[ ! -z $upload ]]; then
#echo "upload : "$upload
dbus ram speedtest_upload=$upload
fi
done;
#完成测速
dbus set speedtest_status=0