-
Notifications
You must be signed in to change notification settings - Fork 16
/
speed-test.sh
73 lines (56 loc) · 2.48 KB
/
speed-test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/env bash
#
# lework
# Jenkins mirror update center speed test.
######################################################################################################
# environment configuration
######################################################################################################
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;36m'
PLAIN='\033[0m'
image_name="library/centos"
image_tag="latest"
declare -A mirrors
mirrors=(
[tencent]="https://mirrors.cloud.tencent.com/jenkins/"
[huawei]="https://mirrors.huaweicloud.com/jenkins/"
[tsinghua]="https://mirrors.tuna.tsinghua.edu.cn/jenkins/"
[ustc]="https://mirrors.ustc.edu.cn/jenkins/"
[bit]="https://mirrors.bit.edu.cn/jenkins/"
[aliyun]="https://mirrors.aliyun.com/jenkins/"
)
file="updates/current/plugin-versions.json"
######################################################################################################
# function
######################################################################################################
speed_test() {
local output=$(LANG=C wget --header="$3" -4O /dev/null -T300 "$1" 2>&1)
local speed=$(printf '%s' "$output" | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}')
local ipaddress=$(printf '%s' "$output" | awk -F'|' '/Connecting to .*\|([^\|]+)\|/ {print $2}'| tail -1)
local time=$(printf '%s' "$output" | awk -F= '/100% / {print $2}')
local size=$(printf '%s' "$output" | awk '/Length:/ {s=$3} END {gsub(/\(|\)/,"",s); print s}')
printf "${YELLOW}%-14s${GREEN}%-20s${BLUE}%-14s${PLAIN}%-20s${RED}%-14s${PLAIN}\n" "$2" "${ipaddress}" "${size}" "${time}" "${speed}"
}
######################################################################################################
# main
######################################################################################################
if [ ! -e '/usr/bin/wget' ]; then
echo "Error: wget command not found. You must be install wget command at first."
exit 1
fi
clear
echo -e "\n\nJenkins mirror update center speed test"
echo -e "\n[Mirror Site]"
for mirror in ${!mirrors[*]}; do
printf "${PLAIN}%-14s${GREEN}%-20s${PLAIN}\n" ${mirror} ": ${mirrors[$mirror]}"
done
echo -e "\n[Test]"
echo -e "Test File : ${YELLOW}${file}${PLAIN}\n"
printf "%-14s%-20s%-14s%-20s%-14s\n" "Site Name" "IPv4 address" "File Size" "Download Time" "Download Speed"
for mirror in ${!mirrors[*]}; do
speed_test "${mirrors[$mirror]}${file}" ${mirror}
done
echo