@@ -33,8 +33,40 @@ mirrors=(
33
33
# function
34
34
# #####################################################################################################
35
35
36
+ function shutdown() {
37
+ tput cnorm # reset cursor
38
+ ps -ef | grep " $0 " | awk ' {print $2}' | xargs kill -9 ' {}' > /dev/null 2>&1
39
+ }
40
+
41
+ trap shutdown EXIT
42
+
43
+ function spinner() {
44
+ # make sure we use non-unicode character type locale
45
+ # (that way it works for any locale as long as the font supports the characters)
46
+ local LC_CTYPE=C
47
+ speed_test " $@ " &
48
+ sleep 1
49
+
50
+ local pid=$( ps -ef | grep -E ' [w]get.*-4O /dev/null -T300' | awk ' {print $2}' ) # Process Id of the previous running command
51
+
52
+ local spin=' ◐◓◑◒'
53
+ local charwidth=3
54
+
55
+ local i=0
56
+ tput civis # cursor invisible
57
+ while kill -0 $pid 2> /dev/null; do
58
+ local i=$(( (i + $charwidth ) % ${# spin} ))
59
+ printf " %s" " ${spin: $i : $charwidth } "
60
+
61
+ echo -en " \033[1D"
62
+ sleep .1
63
+ done
64
+ tput cnorm
65
+ wait
66
+ }
67
+
36
68
speed_test () {
37
- local output=$( LANG=C wget --header=" $3 " -4O /dev/null -T300 " $1 " 2>&1 )
69
+ local output=$( LANG=C wget ${3 : + " --header=" } " $3 " -4O /dev/null -T300 " $1 " 2>&1 )
38
70
local speed=$( printf ' %s' " $output " | awk ' /\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
39
71
local ipaddress=$( printf ' %s' " $output " | awk -F' |' ' /Connecting to .*\|([^\|]+)\|/ {print $2}' | tail -1)
40
72
local time=$( printf ' %s' " $output " | awk -F= ' /100% / {print $2}' )
@@ -62,7 +94,7 @@ echo -e "\n\nDocker Hub mirror site speed test"
62
94
63
95
echo -e " \n[Mirror Site]"
64
96
for mirror in ${! mirrors[*]} ; do
65
- printf " ${PLAIN} %-14s${GREEN} %-20s${PLAIN} \n" ${mirror} " : ${mirrors[$mirror]} "
97
+ printf " ${PLAIN} %-14s${GREEN} %-20s${PLAIN} \n" ${mirror} " : ${mirrors[$mirror]} "
66
98
done
67
99
printf " ${PLAIN} %-14s${GREEN} %-20s${PLAIN} \n" " docker" " : https://registry-1.docker.io"
68
100
@@ -71,7 +103,7 @@ echo -e "Test Image : ${YELLOW}${image_name}:${image_tag}${PLAIN}"
71
103
72
104
docker_token=$( curl -fsSL " https://auth.docker.io/token?service=registry.docker.io&scope=repository:${image_name} :pull" | awk ' -F"' ' {print $4}' )
73
105
image_manifests=$( curl -fsSL -H " Authorization: Bearer ${docker_token} " " https://registry-1.docker.io/v2/${image_name} /manifests/${image_tag} " | awk -F' "' ' /"blobSum":/ {print $4}' )
74
- image_layer=$( echo $image_manifests | tr ' ' ' \n' | sort -u| head -1 )
106
+ image_layer=$( echo $image_manifests | tr ' ' ' \n' | sort -u| head -1)
75
107
echo -e " Download layer : ${YELLOW}${image_layer}${PLAIN} \n"
76
108
77
109
printf " %-14s%-20s%-14s%-20s%-14s\n" " Site Name" " IPv4 address" " File Size" " Download Time" " Download Speed"
@@ -80,7 +112,9 @@ for mirror in ${!mirrors[*]}; do
80
112
image_manifests=$( curl -s " ${mirror} /v2/library/${image_name} /manifests/${image_tag} " | awk -F' "' ' /"blobSum":/ {print $4}' )
81
113
image_layer=$( echo $resp | tr ' ' ' \n' | sort -u | head -1)
82
114
fi
83
- speed_test " ${mirrors[$mirror]} /v2/${image_name} /blobs/${image_layer} " ${mirror}
115
+ spinner " ${mirrors[$mirror]} /v2/${image_name} /blobs/${image_layer} " ${mirror}
84
116
done
85
- speed_test " https://registry-1.docker.io/v2/${image_name} /blobs/${image_layer} " " docker" " Authorization: Bearer $docker_token "
117
+
118
+ spinner " https://registry-1.docker.io/v2/${image_name} /blobs/${image_layer} " " docker" " Authorization: Bearer $docker_token "
86
119
echo
120
+
0 commit comments