diff --git a/disktest_install.sh b/disktest_install.sh index 11481a0..2f30e2b 100644 --- a/disktest_install.sh +++ b/disktest_install.sh @@ -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 @@ -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