Skip to content

Commit

Permalink
Update disktest_install.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
spiritLHLS authored Aug 5, 2024
1 parent 5f4c92e commit e5d00bc
Showing 1 changed file with 54 additions and 72 deletions.
126 changes: 54 additions & 72 deletions disktest_install.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
#From https://github.com/oneclickvirt/disktest
#2024.07.02
#2024.08.05

rm -rf /usr/bin/disktest
rm -rf disktest
Expand Down Expand Up @@ -31,80 +31,62 @@ check_cdn_file() {
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 "${cdn_success_url}https://github.com/oneclickvirt/disktest/releases/download/output/disktest-linux-amd64"
;;
"i386" | "i686")
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 "${cdn_success_url}https://github.com/oneclickvirt/disktest/releases/download/output/disktest-linux-arm64"
;;
*)
echo "Unsupported architecture: $arch"
exit 1
;;
esac
;;
Darwin)
case $arch in
"x86_64" | "x86" | "amd64" | "x64")
wget -O disktest https://github.com/oneclickvirt/disktest/releases/download/output/disktest-darwin-amd64
;;
"i386" | "i686")
wget -O disktest https://github.com/oneclickvirt/disktest/releases/download/output/disktest-darwin-386
;;
"armv7l" | "armv8" | "armv8l" | "aarch64" | "arm64")
wget -O disktest https://github.com/oneclickvirt/disktest/releases/download/output/disktest-darwin-arm64
;;
*)
echo "Unsupported architecture: $arch"
exit 1
;;
esac
;;
FreeBSD)
case $arch in
amd64)
wget -O disktest "${cdn_success_url}https://github.com/oneclickvirt/disktest/releases/download/output/disktest-freebsd-amd64"
;;
"i386" | "i686")
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 "${cdn_success_url}https://github.com/oneclickvirt/disktest/releases/download/output/disktest-freebsd-arm64"
;;
*)
echo "Unsupported architecture: $arch"
exit 1
;;
download_file() {
local url="$1"
local output="$2"

if ! wget -O "$output" "$url"; then
echo "wget failed, trying curl..."
if ! curl -L -o "$output" "$url"; then
echo "Both wget and curl failed. Unable to download the file."
return 1
fi
fi
return 0
}

get_disktest_url() {
local os="$1"
local arch="$2"

case $os in
Linux|FreeBSD|OpenBSD)
os_lower=$(echo $os | tr '[:upper:]' '[:lower:]')
case $arch in
"x86_64"|"x86"|"amd64"|"x64") arch_name="amd64" ;;
"i386"|"i686") arch_name="386" ;;
"armv7l"|"armv8"|"armv8l"|"aarch64"|"arm64") arch_name="arm64" ;;
*) echo "Unsupported architecture: $arch" && return 1 ;;
esac
echo "${cdn_success_url}https://github.com/oneclickvirt/disktest/releases/download/output/disktest-${os_lower}-${arch_name}"
;;
Darwin)
case $arch in
"x86_64"|"x86"|"amd64"|"x64") arch_name="amd64" ;;
"i386"|"i686") arch_name="386" ;;
"armv7l"|"armv8"|"armv8l"|"aarch64"|"arm64") arch_name="arm64" ;;
*) echo "Unsupported architecture: $arch" && return 1 ;;
esac
echo "https://github.com/oneclickvirt/disktest/releases/download/output/disktest-darwin-${arch_name}"
;;
*)
echo "Unsupported operating system: $os"
return 1
;;
esac
;;
OpenBSD)
case $arch in
amd64)
wget -O disktest "${cdn_success_url}https://github.com/oneclickvirt/disktest/releases/download/output/disktest-openbsd-amd64"
;;
"i386" | "i686")
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 "${cdn_success_url}https://github.com/oneclickvirt/disktest/releases/download/output/disktest-openbsd-arm64"
;;
*)
echo "Unsupported architecture: $arch"
}

url=$(get_disktest_url "$os" "$arch")
if [ $? -eq 0 ]; then
if download_file "$url" "disktest"; then
echo "Successfully downloaded disktest"
else
echo "Failed to download disktest"
exit 1
;;
esac
;;
*)
echo "Unsupported operating system: $os"
fi
else
exit 1
;;
esac
fi

chmod 777 disktest
cp disktest /usr/bin/disktest

0 comments on commit e5d00bc

Please sign in to comment.