fastest-mirror

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 0ffb72330147d536b09a539446aed86e4eab97cf
parent 2ca0e935a6717837788646a77c2ca25ac938268e
Author: vasyahacker <vasyahacker@noreply.git.openbsd.org.ru>
Date:   Tue, 26 Sep 2023 12:42:40 +0300

Добавить obsd-fastest-mirror.sh

Diffstat:
Aobsd-fastest-mirror.sh | 31+++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+), 0 deletions(-)

diff --git a/obsd-fastest-mirror.sh b/obsd-fastest-mirror.sh @@ -0,0 +1,30 @@ +#!/bin/sh +ping_timeout=1 +test_time=3 +tmpd=/tmp/mirrors-speed +urls=$(ftp -V -o - https://www.openbsd.org/ftp.html|grep -Eo '((http|https)://.*/OpenBSD/)'|uniq) +m_num=$(echo "$urls"|wc -l) +rm -rf $tmpd +mkdir $tmpd +_table="Mirror|Ping|MB/s" +_i=1 +for url in $urls +do + printf "Testing [%3d/%3d] %s" $((_i++)) "$m_num" "$url" + _url="${url}snapshots/ports.tar.gz" + _host="$(echo "$url" | sed -ne 's|.*://\([^/]*\)/.*|\1|p')" + _tmpf=$tmpd/$_host + _ping=$(ping -w $ping_timeout -c 1 "$_host" 2>/dev/null | sed -nE 's/.*time=([0-9.]+).*/\1/p') + [ -z "$(echo $_ping)" ] && _ping="0" + timeout $test_time ftp -MVo "$_tmpf" "$_url" >/dev/null 2>&1 + [ -s "$_tmpf" ] && { + _size=$(stat -f%z "$_tmpf" 2>/dev/null) + _speed=$(echo "scale=7; $_size / $test_time / 1024 / 1024" | bc) + } || _speed="0" + _row="$(printf "%s|%.3f|%f" "$url" "$_ping" "$_speed")" + _table="${_table}\n${_row}\n" + rm -f "$_tmpf" + printf "\033[2K\r" +done +echo "$_table" | sort -t'|' -n -k3 | column -t -s'|' +rm -rf $tmpd +\ No newline at end of file