refactor: replace wget --spider with web_check; return PASS or FAIL

This commit is contained in:
Martin Wimpress 2024-04-23 06:37:31 +01:00 committed by Martin Wimpress
parent 4efd5f7d93
commit f7a6ec0245
1 changed files with 15 additions and 15 deletions

View File

@ -436,7 +436,7 @@ function test_isos() {
check_it() { check_it() {
validate_release releases_"${OS}" validate_release releases_"${OS}"
URL=$(get_"${OS}" "${OPTION}" | cut_1) URL=$(get_"${OS}" "${OPTION}" | cut_1)
GOOD=$(timeout 3 wget -q --spider "${URL}" && echo 'OK' || echo 'ERROR!') GOOD=$(web_check "${URL}" && echo 'PASS' || echo 'FAIL')
} }
for OS in $(os_support); do for OS in $(os_support); do
@ -457,24 +457,24 @@ function test_isos() {
# skipping because of microsoft # skipping because of microsoft
"languages_${OS}" "languages_${OS}"
for OPTION in "${LANGS[@]}"; do for OPTION in "${LANGS[@]}"; do
GOOD='ERROR!' GOOD='FAIL'
done done
elif [[ "${OS}" == *"ubuntu"* ]]; then elif [[ "${OS}" == *"ubuntu"* ]]; then
URL=$(get_"${OS}" ) URL=$(get_"${OS}" )
GOOD=$(timeout 3 wget -q --spider "${URL}" && echo 'OK' || echo 'ERROR!') GOOD=$(web_check "${URL}" && echo 'PASS' || echo 'FAIL')
elif [[ "${OS}" == *"ubuntu-server"* ]]; then elif [[ "${OS}" == *"ubuntu-server"* ]]; then
URL="$(get_ubuntu-server)" URL="$(get_ubuntu-server)"
GOOD=$(timeout 3 wget -q --spider "${URL}" && echo 'OK' || echo 'ERROR!') GOOD=$(web_check "${URL}" && echo 'PASS' || echo 'FAIL')
else else
validate_release releases_"${OS}" validate_release releases_"${OS}"
URL=$(get_"${OS}" "${RELEASE}" | cut_1) URL=$(get_"${OS}" "${RELEASE}" | cut_1)
GOOD=$(timeout 3 wget -q --spider "${URL}" && echo 'OK' || echo 'ERROR!') GOOD=$(web_check "${URL}" && echo 'PASS' || echo 'FAIL')
fi fi
if [[ "${GOOD}" == "OK" ]]; then if [[ "${GOOD}" == "PASS" ]]; then
echo "OK - ${OS} ${RELEASE} ${OPTION} ${URL}" echo "PASS - ${OS} ${RELEASE} ${OPTION} ${URL}"
else else
echo "ERROR - ${OS} ${RELEASE} ${OPTION} ${URL}" echo "FAIL - ${OS} ${RELEASE} ${OPTION} ${URL}"
fi fi
done done
done done
@ -1252,7 +1252,7 @@ function web_get() {
exit 0 exit 0
elif [ "${just}" == 'test' ]; then elif [ "${just}" == 'test' ]; then
echo -n "Testing if $(echo "${URL}" | rev | cut -d'/' -f1 | rev) is available... " echo -n "Testing if $(echo "${URL}" | rev | cut -d'/' -f1 | rev) is available... "
wget -q --spider "${URL}" && echo 'Sucessfull' || echo 'ERROR!' web_check "${URL}" && echo 'PASS' || echo 'FAIL'
exit 0 exit 0
elif [ "${just}" == 'download' ]; then elif [ "${just}" == 'download' ]; then
DIR="$(pwd)" DIR="$(pwd)"
@ -1326,7 +1326,7 @@ function zsync_get() {
echo "${URL}" echo "${URL}"
exit 0 exit 0
elif [ "${just}" == 'test' ]; then elif [ "${just}" == 'test' ]; then
wget --spider "${URL}" web_check "${URL}"
exit 0 exit 0
elif command -v zsync &>/dev/null; then elif command -v zsync &>/dev/null; then
if [ -n "${3}" ]; then if [ -n "${3}" ]; then
@ -2148,8 +2148,8 @@ function get_macos() {
echo -e "Recovery URL (inaccessible through normal browser):\n${downloadLink}\nChunklist (used for verifying the Recovery Image):\n${chunkListLink}\nFirmware URLs:\n${OpenCore_qcow2}\n${OVMF_CODE}\n${OVMF_VARS}" echo -e "Recovery URL (inaccessible through normal browser):\n${downloadLink}\nChunklist (used for verifying the Recovery Image):\n${chunkListLink}\nFirmware URLs:\n${OpenCore_qcow2}\n${OVMF_CODE}\n${OVMF_VARS}"
exit 0 exit 0
elif [ "${just}" == 'test' ]; then elif [ "${just}" == 'test' ]; then
wget --spider --header "Host: oscdn.apple.com" --header "Connection: close" --header "User-Agent: InternetRecovery/1.0" --header "Cookie: AssetToken=${downloadSession}" "${downloadLink}" web_check "${downloadLink}" --header "Host: oscdn.apple.com" --header "Connection: close" --header "User-Agent: InternetRecovery/1.0" --header "Cookie: AssetToken=${downloadSession}"
wget --spider --header "Host: oscdn.apple.com" --header "Connection: close" --header "User-Agent: InternetRecovery/1.0" --header "Cookie: AssetToken=${chunkListSession}" "${chunkListLink}" web_check "${chunkListLink}" --header "Host: oscdn.apple.com" --header "Connection: close" --header "User-Agent: InternetRecovery/1.0" --header "Cookie: AssetToken=${chunkListSession}"
exit 0 exit 0
elif [ "${just}" == 'download' ]; then elif [ "${just}" == 'download' ]; then
echo "Downloading macOS ${RELEASE} from ${downloadLink}" echo "Downloading macOS ${RELEASE} from ${downloadLink}"
@ -2604,7 +2604,7 @@ function get_ubuntu-server() {
else else
URL="https://releases.ubuntu.com/${RELEASE}" URL="https://releases.ubuntu.com/${RELEASE}"
fi fi
if wget -q --spider "${URL}/SHA256SUMS"; then if web_check "${URL}/SHA256SUMS"; then
DATA=$(web_pipe "${URL}/SHA256SUMS" | grep 'live-server' | grep amd64 | grep iso) DATA=$(web_pipe "${URL}/SHA256SUMS" | grep 'live-server' | grep amd64 | grep iso)
ISO=$(cut -d'*' -f2 <<<${DATA}) ISO=$(cut -d'*' -f2 <<<${DATA})
HASH=$(cut_1 <<<${DATA}) HASH=$(cut_1 <<<${DATA})
@ -2654,7 +2654,7 @@ function get_ubuntu() {
else else
URL="https://cdimage.ubuntu.com/${OS}/releases/${RELEASE}/release" URL="https://cdimage.ubuntu.com/${OS}/releases/${RELEASE}/release"
fi fi
if wget -q --spider "${URL}/SHA256SUMS"; then if web_check "${URL}/SHA256SUMS"; then
DATA=$(web_pipe "${URL}/SHA256SUMS" | grep 'desktop\|dvd\|install' | grep amd64 | grep iso | grep -v "+mac") DATA=$(web_pipe "${URL}/SHA256SUMS" | grep 'desktop\|dvd\|install' | grep amd64 | grep iso | grep -v "+mac")
ISO=$(cut -d'*' -f2 <<<${DATA} | sed '1q;d') ISO=$(cut -d'*' -f2 <<<${DATA} | sed '1q;d')
HASH=$(cut_1 <<<${DATA} | sed '1q;d') HASH=$(cut_1 <<<${DATA} | sed '1q;d')
@ -3332,7 +3332,7 @@ function download_windows_workstation() {
echo -e " Windows ${RELEASE} Download (valid for 24 hours):\n${iso_download_link}" echo -e " Windows ${RELEASE} Download (valid for 24 hours):\n${iso_download_link}"
exit 0 exit 0
elif [ "${just}" == 'test' ]; then elif [ "${just}" == 'test' ]; then
wget --spider "${iso_download_link}" web_check "${iso_download_link}"
exit 0 exit 0
fi fi