diff --git a/bin/n b/bin/n index 42216f5..89957c4 100755 --- a/bin/n +++ b/bin/n @@ -358,7 +358,6 @@ erase_line() { # # Check if the HEAD response of is 200. # - is_ok() { if command -v curl > /dev/null; then $GET -Is $1 | head -n 1 | grep 200 > /dev/null @@ -367,6 +366,25 @@ is_ok() { fi } +# +# Check if the OSS(Object Storage Service) mirror is ok. +# +is_oss_ok() { + if command -v curl > /dev/null; then + if $GET -Is $1 | head -n 1 | grep 302 > /dev/null; then + is_oss_ok $GET -Is $1 | grep Location | awk -F ': ' '{print $2}' + else + $GET -Is $1 | head -n 1 | grep 200 > /dev/null + fi + else + if $GET -S --spider 2>&1 $1 | head -n 1 | grep 302 > /dev/null; then + is_oss_ok $GET -S --spider 2>&1 $1 | grep Location | awk -F ': ' '{print $2}' + else + $GET -S --spider 2>&1 $1 | head -n 1 | grep 200 > /dev/null + fi + fi +} + # # Determine tarball url for # @@ -510,7 +528,7 @@ install() { log install ${BINS[$DEFAULT]}-v$version local url=$(tarball_url $version) - is_ok $url || abort "invalid version $version" + is_ok $url || is_oss_ok $url || abort "invalid version $version" log mkdir $dir mkdir -p $dir