Skip to content
This repository was archived by the owner on May 9, 2018. It is now read-only.

Commit 45057f7

Browse files
committed
Merge pull request #1 from ZacharyDuBois/dev
Dev
2 parents bb85297 + a5c903e commit 45057f7

File tree

3 files changed

+44
-29
lines changed

3 files changed

+44
-29
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## v0.7.0
4+
5+
- Removes pointless output.
6+
- Add hidden option to disable color.
7+
- Add syntax in source.
8+
39
## v0.6.2
410

511
- Fix if at the end to determine if tracking is allowed or not.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# DigitalOcean Speed Test CLI
22

3-
*v0.6.2*
3+
*v0.7.0*
44

55
## Features
66

do-cli-speedtest

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
#!/bin/bash
22
# DigitalOcean Speed Test CLI
33
# https://github.com/ZacharyDuBois/DigitalOcean-Speed-Test-CLI
4-
version="v0.6.2"
4+
5+
##
6+
# Syntax
7+
# curl -s https://i.destroy.tokyo/dostcli | bash -s <testType> <disallowTracking> <disableColor>
8+
##
9+
version="v0.7.0"
510

611
##
712
# Variables
@@ -12,19 +17,34 @@ cdnTest="d2qm7ckles1o3d.cloudfront.net"
1217
userAgent="DigitalOcean Speed Test CLI $version - https://github.com/ZacharyDuBois/DigitalOcean-Speed-Test-CLI"
1318
testType=$1
1419
disallowTracking=$2
15-
20+
disableColor=$3
1621

1722
##
1823
# Message Types
1924
##
2025

21-
fail="[$(tput setaf 1) FAIL $(tput sgr0)]"
22-
ok="[$(tput setaf 2) OK $(tput sgr0)]"
23-
running="[$(tput setaf 3) ** $(tput sgr0)]"
24-
notice="[$(tput setaf 3)NOTICE$(tput sgr0)]"
25-
warn="[$(tput setaf 3) WARN $(tput sgr0)]"
26-
info="[$(tput setaf 6) INFO $(tput sgr0)]"
27-
finish="[$(tput setaf 4) DONE $(tput sgr0)]"
26+
if [[ $disableColor == "" ]] || [[ $disableColor == false ]]
27+
then
28+
fail="[$(tput setaf 1) FAIL $(tput sgr0)]"
29+
ok="[$(tput setaf 2) OK $(tput sgr0)]"
30+
running="[$(tput setaf 3) ** $(tput sgr0)]"
31+
notice="[$(tput setaf 3)NOTICE$(tput sgr0)]"
32+
warn="[$(tput setaf 3) WARN $(tput sgr0)]"
33+
info="[$(tput setaf 6) INFO $(tput sgr0)]"
34+
finish="[$(tput setaf 4) DONE $(tput sgr0)]"
35+
elif [[ $disableColor == true ]]
36+
then
37+
fail="[ FAIL ]"
38+
ok="[ OK ]"
39+
running="[ ** ]"
40+
notice="[NOTICE]"
41+
warn="[ WARN ]"
42+
info="[ INFO ]"
43+
finish="[ DONE ]"
44+
else
45+
echo "Unknown disableColor setting."
46+
exit 1
47+
fi
2848

2949
##
3050
# Startup Checks
@@ -62,9 +82,6 @@ echo
6282
# Download Test
6383
##
6484

65-
echo "$info All test files are not saved so you don't have to worry about disk space :P"
66-
echo "$running Starting download speedtest..."
67-
6885
# Determine the testType.
6986
if [[ $testType == "100mb" ]] || [[ $testType == "" ]]
7087
then
@@ -90,16 +107,17 @@ then
90107
echo "$fail You need curl to enable tracking."
91108
exit 1
92109
fi
93-
echo "$notice You have selected not to opt out of tracking. Tracking only counts the number of tests and the test type (and the IP will be logged in the access log, etc)."
94-
echo "$notice The tracking URL is not called until the very end of the test. If you would like to opt out now, you can simply cancel this script and re-run it with the disallowTracking variable set. See README.md on Github for more information."
110+
echo "$notice By default, you are opted-in for just basic tracking (Which test type you picked)."
111+
echo "$notice The tracking URI is not called until the end. To opt-out, kill this script and look for the propor command on the GitHub README.md."
95112
elif [[ $disallowTracking == true ]]
96113
then
97-
echo "$info You have selected to opt out of tracking. The tracking URI should not be called at the end."
114+
echo "$info You have selected to opt-out of tracking."
98115
else
99116
echo "$fail Unknown disallowTracking option."
100117
exit 1
101118
fi
102119

120+
echo "$running Starting download test..."
103121
downloadTest() {
104122
name=$1
105123
hostname=$2
@@ -112,7 +130,6 @@ downloadTest() {
112130
scheme="http://"
113131
fi
114132

115-
echo "$running Running $name download speed test from $scheme$hostname/$downloadFile..."
116133
speedRaw=$( wget -O /dev/null --user-agent "'$userAgent'" $scheme$hostname/$downloadFile 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}' )
117134
speed="$(tput setaf 2)$speedRaw$(tput sgr0)"
118135
echo "$ok $name Speed: $speed."
@@ -123,33 +140,27 @@ do
123140
downloadTest "$(echo "$dataCenter" | awk -F'.' '{ print $1 }' | awk -F'-' '{ print $2 }' | tr '[:lower:]' '[:upper:]')" "$dataCenter" false
124141
done
125142

126-
echo "$info Starting CDN test. Test runs twice to ensure file is in the edge location."
143+
echo "$info Starting CDN (AWS Cloudfront) test. Test runs twice to ensure file is in the edge location."
127144
downloadTest "CDN Test 1x" "$cdnTest" true
128145
downloadTest "CDN Test 2x" "$cdnTest" true
129146

130-
echo "$ok Download Speedtest."
131-
132-
133147
##
134148
# Latency Test
135149
##
136150

137151
echo "$running Starting latency test..."
138-
echo "$info This test each datacenter 10 times."
139-
echo "$info If there is any packet loss, it will be printed."
152+
echo "$info 10 Packets are sent. Packetloss will be shown if any."
140153

141154
pingTest() {
142155
name=$1
143156
hostname=$2
144-
echo "$running Running $name latency test on $hostname..."
145157
pingRaw=$(ping -qc 10 -i .5 $hostname)
146158
avgPingRaw="$(echo "$pingRaw" | awk -F'/' '/^(rtt|round-trip)/ { print $5 }')"
147159
avgPing="$(tput setaf 2)"$avgPingRaw"ms$(tput sgr0)"
148160
echo "$ok $name Average Latency: $avgPing."
149-
pkLossRaw="$(echo "$pingRaw" | awk -F',' '/packet loss/ { print $3 }' | awk -F' ' '{ print $1 }')"
150-
if ! [[ "$pkLossRaw" =~ ^(0\.0\%|0\%) ]]
161+
pkLoss="$(echo "$pingRaw" | awk -F',' '/packet loss/ { print $3 }' | awk -F' ' '{ print $1 }')"
162+
if ! [[ "$pkLoss" =~ ^(0\.0\%|0\%) ]]
151163
then
152-
pkLoss=$(tput setaf 2)$pkLossRaw$(tput sgr0)
153164
echo "$warn $name Packet Loss: $pkLoss."
154165
fi
155166
}
@@ -159,8 +170,6 @@ do
159170
pingTest "$(echo "$dataCenter" | awk -F'.' '{ print $1 }' | awk -F'-' '{ print $2 }' | tr '[:lower:]' '[:upper:]')" "$dataCenter"
160171
done
161172

162-
echo "$ok Latency test."
163-
164173
if [[ $disallowTracking == false ]] || [[ $disallowTracking == "" ]]
165174
then
166175
echo "$running Calling tracking URL."

0 commit comments

Comments
 (0)