Skip to content

Commit

Permalink
same dist, jq output
Browse files Browse the repository at this point in the history
  • Loading branch information
ipitio committed Feb 13, 2024
1 parent e164b05 commit 0cb6ed0
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions advanced/Scripts/speedtestmod/speedtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ internet() {
stop=$(date -u --rfc-3339='seconds')
res="$(</tmp/speedtest_results)"
server_name=$(jq -r '.server.name' <<< "$res")
servers="$(curl 'https://www.speedtest.net/api/js/servers' --compressed -H 'Upgrade-Insecure-Requests: 1' -H 'DNT: 1' -H 'Sec-GPC: 1')"
server_dist=$(jq --arg id "$server_id" '.[] | select(.id == $id) | .distance' <<< "$servers")
if [ -z "$server_dist" ]; then
server_dist=-1
fi

if grep -q official <<< "$(/usr/bin/speedtest --version)"; then
download=$(jq -r '.download.bandwidth' <<< "$res" | awk '{$1=$1*8/1000/1000; print $1;}' | sed 's/,/./g')
Expand All @@ -48,11 +53,6 @@ internet() {
server_ping=$(jq -r '.ping.latency' <<< "$res")
share_url=$(jq -r '.result.url' <<< "$res")
server_id=$(jq -r '.server.id' <<< "$res")
servers="$(curl 'https://www.speedtest.net/api/js/servers' --compressed -H 'Upgrade-Insecure-Requests: 1' -H 'DNT: 1' -H 'Sec-GPC: 1')"
server_dist=$(jq --arg id "$server_id" '.[] | select(.id == $id) | .distance' <<< "$servers")
if [ -z "$server_dist" ]; then
server_dist=0
fi
else
download=$(jq -r '.download' <<< "$res" | awk '{$1=$1/1000/1000; print $1;}' | sed 's/,/./g')
upload=$(jq -r '.upload' <<< "$res" | awk '{$1=$1/1000/1000; print $1;}' | sed 's/,/./g')
Expand All @@ -61,10 +61,9 @@ internet() {
from_ip=$(jq -r '.client.ip' <<< "$res")
server_ping=$(jq -r '.ping' <<< "$res")
share_url=$(jq -r '.share' <<< "$res")
server_dist=$(jq -r '.server.d' <<< "$res")
fi

cat /tmp/speedtest_results
jq . /tmp/speedtest_results
sqlite3 /etc/pihole/speedtest.db "insert into speedtest values (NULL, '${start}', '${stop}', '${isp}', '${from_ip}', '${server_name}', ${server_dist}, ${server_ping}, ${download}, ${upload}, '${share_url}');"
mv -f "$FILE" /var/log/pihole/speedtest.log
exit 0
Expand Down

0 comments on commit 0cb6ed0

Please sign in to comment.