Skip to content

Commit 910a521

Browse files
committed
v0.0.4 - 优化参数解析和CDN加速
1 parent c1ba4bf commit 910a521

File tree

5 files changed

+65
-36
lines changed

5 files changed

+65
-36
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
run: |
2525
git config --global user.name 'github-actions'
2626
git config --global user.email 'github-actions@github.com'
27-
TAG="v0.0.3-$(date +'%Y%m%d%H%M%S')"
27+
TAG="v0.0.4-$(date +'%Y%m%d%H%M%S')"
2828
git tag $TAG
2929
git push origin $TAG
3030
env:

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,16 @@
2727

2828
## 使用
2929

30-
更新时间:2024.06.24
31-
32-
下载及安装
30+
下载、安装、更新
3331

3432
```shell
35-
curl https://raw.githubusercontent.com/oneclickvirt/disktest/main/disktest_install.sh -sSf | sh
33+
curl https://raw.githubusercontent.com/oneclickvirt/disktest/main/disktest_install.sh -sSf | bash
3634
```
3735

3836
3937

4038
```shell
41-
curl https://cdn.spiritlhl.net/https://raw.githubusercontent.com/oneclickvirt/disktest/main/disktest_install.sh -sSf | sh
39+
curl https://cdn.spiritlhl.net/https://raw.githubusercontent.com/oneclickvirt/disktest/main/disktest_install.sh -sSf | bash
4240
```
4341

4442
使用

cmd/main.go

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"flag"
55
"fmt"
66
"net/http"
7+
"os"
78
"runtime"
89
"strings"
910

@@ -15,40 +16,46 @@ func main() {
1516
http.Get("https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Foneclickvirt%2Fdisktest&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false")
1617
}()
1718
fmt.Println("项目地址:", "https://github.com/oneclickvirt/disktest")
18-
// go run main.go -l en -d multi
19-
// go run main.go -l en -d single -m fio
20-
var showVersion bool
21-
flag.BoolVar(&showVersion, "v", false, "show version")
22-
languagePtr := flag.String("l", "", "Language parameter (en or zh)")
23-
testMethodPtr := flag.String("m", "", "Specific Test Method (dd or fio)")
24-
multiDiskPtr := flag.String("d", "", "Enable multi disk check parameter (single or multi, default is single)")
25-
testPathPtr := flag.String("p", "", "Specific Test Disk Path (default is /root or C:)")
26-
flag.Parse()
19+
var showVersion, help bool
20+
var language, testMethod, testPath, multiDisk string
21+
disktestFlag := flag.NewFlagSet("disktest", flag.ContinueOnError)
22+
disktestFlag.BoolVar(&help, "h", false, "Show help information")
23+
disktestFlag.BoolVar(&showVersion, "v", false, "Show version")
24+
disktestFlag.StringVar(&language, "l", "", "Language parameter (en or zh)")
25+
disktestFlag.StringVar(&testMethod, "m", "", "Specific Test Method (dd or fio)")
26+
disktestFlag.StringVar(&multiDisk, "d", "", "Enable multi disk check parameter (single or multi, default is single)")
27+
disktestFlag.StringVar(&testPath, "p", "", "Specific Test Disk Path (default is /root or C:)")
28+
disktestFlag.Parse(os.Args[1:])
29+
if help {
30+
fmt.Printf("Usage: %s [options]\n", os.Args[0])
31+
disktestFlag.PrintDefaults()
32+
return
33+
}
2734
if showVersion {
2835
fmt.Println(disk.DiskTestVersion)
2936
return
3037
}
31-
var language, res, testMethod, testPath string
38+
var res string
3239
var isMultiCheck bool
33-
if *languagePtr == "" {
40+
if language == "" {
3441
language = "zh"
3542
} else {
36-
language = strings.ToLower(*languagePtr)
43+
language = strings.ToLower(language)
3744
}
38-
if *multiDiskPtr == "" || *multiDiskPtr == "single" {
45+
if multiDisk == "" || multiDisk == "single" {
3946
isMultiCheck = false
40-
} else if *multiDiskPtr == "multi" {
47+
} else if multiDisk == "multi" {
4148
isMultiCheck = true
4249
}
43-
if *testMethodPtr == "" || *testMethodPtr == "dd" {
50+
if testMethod == "" || testMethod == "dd" {
4451
testMethod = "dd"
45-
} else if *testMethodPtr == "fio" {
52+
} else if testMethod == "fio" {
4653
testMethod = "fio"
4754
}
48-
if *testPathPtr == "" {
55+
if testPath == "" {
4956
testPath = ""
50-
} else if *testPathPtr != "" {
51-
testPath = strings.TrimSpace(strings.ToLower(*testPathPtr))
57+
} else if testPath != "" {
58+
testPath = strings.TrimSpace(strings.ToLower(testPath))
5259
}
5360
if runtime.GOOS == "windows" {
5461
if testMethod != "winsat" && testMethod != "" {

disk/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package disk
22

3-
const DiskTestVersion = "v0.0.3"
3+
const DiskTestVersion = "v0.0.4"

disktest_install.sh

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,47 @@
11
#!/bin/bash
22
#From https://github.com/oneclickvirt/disktest
3-
#2024.06.24
3+
#2024.07.02
44

55
rm -rf /usr/bin/disktest
66
rm -rf disktest
77
os=$(uname -s)
88
arch=$(uname -m)
99

10+
check_cdn() {
11+
local o_url=$1
12+
for cdn_url in "${cdn_urls[@]}"; do
13+
if curl -sL -k "$cdn_url$o_url" --max-time 6 | grep -q "success" >/dev/null 2>&1; then
14+
export cdn_success_url="$cdn_url"
15+
return
16+
fi
17+
sleep 0.5
18+
done
19+
export cdn_success_url=""
20+
}
21+
22+
check_cdn_file() {
23+
check_cdn "https://raw.githubusercontent.com/spiritLHLS/ecs/main/back/test"
24+
if [ -n "$cdn_success_url" ]; then
25+
echo "CDN available, using CDN"
26+
else
27+
echo "No CDN available, no use CDN"
28+
fi
29+
}
30+
31+
cdn_urls=("https://cdn0.spiritlhl.top/" "http://cdn3.spiritlhl.net/" "http://cdn1.spiritlhl.net/" "http://cdn2.spiritlhl.net/")
32+
check_cdn_file
33+
1034
case $os in
1135
Linux)
1236
case $arch in
1337
"x86_64" | "x86" | "amd64" | "x64")
14-
wget -O disktest https://github.com/oneclickvirt/disktest/releases/download/output/disktest-linux-amd64
38+
wget -O disktest "${cdn_success_url}https://github.com/oneclickvirt/disktest/releases/download/output/disktest-linux-amd64"
1539
;;
1640
"i386" | "i686")
17-
wget -O disktest https://github.com/oneclickvirt/disktest/releases/download/output/disktest-linux-386
41+
wget -O disktest "${cdn_success_url}https://github.com/oneclickvirt/disktest/releases/download/output/disktest-linux-386"
1842
;;
1943
"armv7l" | "armv8" | "armv8l" | "aarch64" | "arm64")
20-
wget -O disktest https://github.com/oneclickvirt/disktest/releases/download/output/disktest-linux-arm64
44+
wget -O disktest "${cdn_success_url}https://github.com/oneclickvirt/disktest/releases/download/output/disktest-linux-arm64"
2145
;;
2246
*)
2347
echo "Unsupported architecture: $arch"
@@ -45,13 +69,13 @@ case $os in
4569
FreeBSD)
4670
case $arch in
4771
amd64)
48-
wget -O disktest https://github.com/oneclickvirt/disktest/releases/download/output/disktest-freebsd-amd64
72+
wget -O disktest "${cdn_success_url}https://github.com/oneclickvirt/disktest/releases/download/output/disktest-freebsd-amd64"
4973
;;
5074
"i386" | "i686")
51-
wget -O disktest https://github.com/oneclickvirt/disktest/releases/download/output/disktest-freebsd-386
75+
wget -O disktest "${cdn_success_url}https://github.com/oneclickvirt/disktest/releases/download/output/disktest-freebsd-386"
5276
;;
5377
"armv7l" | "armv8" | "armv8l" | "aarch64" | "arm64")
54-
wget -O disktest https://github.com/oneclickvirt/disktest/releases/download/output/disktest-freebsd-arm64
78+
wget -O disktest "${cdn_success_url}https://github.com/oneclickvirt/disktest/releases/download/output/disktest-freebsd-arm64"
5579
;;
5680
*)
5781
echo "Unsupported architecture: $arch"
@@ -62,13 +86,13 @@ case $os in
6286
OpenBSD)
6387
case $arch in
6488
amd64)
65-
wget -O disktest https://github.com/oneclickvirt/disktest/releases/download/output/disktest-openbsd-amd64
89+
wget -O disktest "${cdn_success_url}https://github.com/oneclickvirt/disktest/releases/download/output/disktest-openbsd-amd64"
6690
;;
6791
"i386" | "i686")
68-
wget -O disktest https://github.com/oneclickvirt/disktest/releases/download/output/disktest-openbsd-386
92+
wget -O disktest "${cdn_success_url}https://github.com/oneclickvirt/disktest/releases/download/output/disktest-openbsd-386"
6993
;;
7094
"armv7l" | "armv8" | "armv8l" | "aarch64" | "arm64")
71-
wget -O disktest https://github.com/oneclickvirt/disktest/releases/download/output/disktest-openbsd-arm64
95+
wget -O disktest "${cdn_success_url}https://github.com/oneclickvirt/disktest/releases/download/output/disktest-openbsd-arm64"
7296
;;
7397
*)
7498
echo "Unsupported architecture: $arch"

0 commit comments

Comments
 (0)