Skip to content

Commit

Permalink
v0.0.4 - 优化参数解析和CDN加速
Browse files Browse the repository at this point in the history
  • Loading branch information
spiritLHLS committed Jul 2, 2024
1 parent c1ba4bf commit 910a521
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
run: |
git config --global user.name 'github-actions'
git config --global user.email '[email protected]'
TAG="v0.0.3-$(date +'%Y%m%d%H%M%S')"
TAG="v0.0.4-$(date +'%Y%m%d%H%M%S')"
git tag $TAG
git push origin $TAG
env:
Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,16 @@

## 使用

更新时间:2024.06.24

下载及安装
下载、安装、更新

```shell
curl https://raw.githubusercontent.com/oneclickvirt/disktest/main/disktest_install.sh -sSf | sh
curl https://raw.githubusercontent.com/oneclickvirt/disktest/main/disktest_install.sh -sSf | bash
```


```shell
curl https://cdn.spiritlhl.net/https://raw.githubusercontent.com/oneclickvirt/disktest/main/disktest_install.sh -sSf | sh
curl https://cdn.spiritlhl.net/https://raw.githubusercontent.com/oneclickvirt/disktest/main/disktest_install.sh -sSf | bash
```

使用
Expand Down
45 changes: 26 additions & 19 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"net/http"
"os"
"runtime"
"strings"

Expand All @@ -15,40 +16,46 @@ func main() {
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")
}()
fmt.Println("项目地址:", "https://github.com/oneclickvirt/disktest")
// go run main.go -l en -d multi
// go run main.go -l en -d single -m fio
var showVersion bool
flag.BoolVar(&showVersion, "v", false, "show version")
languagePtr := flag.String("l", "", "Language parameter (en or zh)")
testMethodPtr := flag.String("m", "", "Specific Test Method (dd or fio)")
multiDiskPtr := flag.String("d", "", "Enable multi disk check parameter (single or multi, default is single)")
testPathPtr := flag.String("p", "", "Specific Test Disk Path (default is /root or C:)")
flag.Parse()
var showVersion, help bool
var language, testMethod, testPath, multiDisk string
disktestFlag := flag.NewFlagSet("disktest", flag.ContinueOnError)
disktestFlag.BoolVar(&help, "h", false, "Show help information")
disktestFlag.BoolVar(&showVersion, "v", false, "Show version")
disktestFlag.StringVar(&language, "l", "", "Language parameter (en or zh)")
disktestFlag.StringVar(&testMethod, "m", "", "Specific Test Method (dd or fio)")
disktestFlag.StringVar(&multiDisk, "d", "", "Enable multi disk check parameter (single or multi, default is single)")
disktestFlag.StringVar(&testPath, "p", "", "Specific Test Disk Path (default is /root or C:)")
disktestFlag.Parse(os.Args[1:])
if help {
fmt.Printf("Usage: %s [options]\n", os.Args[0])
disktestFlag.PrintDefaults()
return
}
if showVersion {
fmt.Println(disk.DiskTestVersion)
return
}
var language, res, testMethod, testPath string
var res string
var isMultiCheck bool
if *languagePtr == "" {
if language == "" {
language = "zh"
} else {
language = strings.ToLower(*languagePtr)
language = strings.ToLower(language)
}
if *multiDiskPtr == "" || *multiDiskPtr == "single" {
if multiDisk == "" || multiDisk == "single" {
isMultiCheck = false
} else if *multiDiskPtr == "multi" {
} else if multiDisk == "multi" {
isMultiCheck = true
}
if *testMethodPtr == "" || *testMethodPtr == "dd" {
if testMethod == "" || testMethod == "dd" {
testMethod = "dd"
} else if *testMethodPtr == "fio" {
} else if testMethod == "fio" {
testMethod = "fio"
}
if *testPathPtr == "" {
if testPath == "" {
testPath = ""
} else if *testPathPtr != "" {
testPath = strings.TrimSpace(strings.ToLower(*testPathPtr))
} else if testPath != "" {
testPath = strings.TrimSpace(strings.ToLower(testPath))
}
if runtime.GOOS == "windows" {
if testMethod != "winsat" && testMethod != "" {
Expand Down
2 changes: 1 addition & 1 deletion disk/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package disk

const DiskTestVersion = "v0.0.3"
const DiskTestVersion = "v0.0.4"
44 changes: 34 additions & 10 deletions disktest_install.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,47 @@
#!/bin/bash
#From https://github.com/oneclickvirt/disktest
#2024.06.24
#2024.07.02

rm -rf /usr/bin/disktest
rm -rf disktest
os=$(uname -s)
arch=$(uname -m)

check_cdn() {
local o_url=$1
for cdn_url in "${cdn_urls[@]}"; do
if curl -sL -k "$cdn_url$o_url" --max-time 6 | grep -q "success" >/dev/null 2>&1; then
export cdn_success_url="$cdn_url"
return
fi
sleep 0.5
done
export cdn_success_url=""
}

check_cdn_file() {
check_cdn "https://raw.githubusercontent.com/spiritLHLS/ecs/main/back/test"
if [ -n "$cdn_success_url" ]; then
echo "CDN available, using CDN"
else
echo "No CDN available, no use CDN"
fi
}

cdn_urls=("https://cdn0.spiritlhl.top/" "http://cdn3.spiritlhl.net/" "http://cdn1.spiritlhl.net/" "http://cdn2.spiritlhl.net/")
check_cdn_file

case $os in
Linux)
case $arch in
"x86_64" | "x86" | "amd64" | "x64")
wget -O disktest https://github.com/oneclickvirt/disktest/releases/download/output/disktest-linux-amd64
wget -O disktest "${cdn_success_url}https://github.com/oneclickvirt/disktest/releases/download/output/disktest-linux-amd64"
;;
"i386" | "i686")
wget -O disktest https://github.com/oneclickvirt/disktest/releases/download/output/disktest-linux-386
wget -O disktest "${cdn_success_url}https://github.com/oneclickvirt/disktest/releases/download/output/disktest-linux-386"
;;
"armv7l" | "armv8" | "armv8l" | "aarch64" | "arm64")
wget -O disktest https://github.com/oneclickvirt/disktest/releases/download/output/disktest-linux-arm64
wget -O disktest "${cdn_success_url}https://github.com/oneclickvirt/disktest/releases/download/output/disktest-linux-arm64"
;;
*)
echo "Unsupported architecture: $arch"
Expand Down Expand Up @@ -45,13 +69,13 @@ case $os in
FreeBSD)
case $arch in
amd64)
wget -O disktest https://github.com/oneclickvirt/disktest/releases/download/output/disktest-freebsd-amd64
wget -O disktest "${cdn_success_url}https://github.com/oneclickvirt/disktest/releases/download/output/disktest-freebsd-amd64"
;;
"i386" | "i686")
wget -O disktest https://github.com/oneclickvirt/disktest/releases/download/output/disktest-freebsd-386
wget -O disktest "${cdn_success_url}https://github.com/oneclickvirt/disktest/releases/download/output/disktest-freebsd-386"
;;
"armv7l" | "armv8" | "armv8l" | "aarch64" | "arm64")
wget -O disktest https://github.com/oneclickvirt/disktest/releases/download/output/disktest-freebsd-arm64
wget -O disktest "${cdn_success_url}https://github.com/oneclickvirt/disktest/releases/download/output/disktest-freebsd-arm64"
;;
*)
echo "Unsupported architecture: $arch"
Expand All @@ -62,13 +86,13 @@ case $os in
OpenBSD)
case $arch in
amd64)
wget -O disktest https://github.com/oneclickvirt/disktest/releases/download/output/disktest-openbsd-amd64
wget -O disktest "${cdn_success_url}https://github.com/oneclickvirt/disktest/releases/download/output/disktest-openbsd-amd64"
;;
"i386" | "i686")
wget -O disktest https://github.com/oneclickvirt/disktest/releases/download/output/disktest-openbsd-386
wget -O disktest "${cdn_success_url}https://github.com/oneclickvirt/disktest/releases/download/output/disktest-openbsd-386"
;;
"armv7l" | "armv8" | "armv8l" | "aarch64" | "arm64")
wget -O disktest https://github.com/oneclickvirt/disktest/releases/download/output/disktest-openbsd-arm64
wget -O disktest "${cdn_success_url}https://github.com/oneclickvirt/disktest/releases/download/output/disktest-openbsd-arm64"
;;
*)
echo "Unsupported architecture: $arch"
Expand Down

0 comments on commit 910a521

Please sign in to comment.