0
0
mirror of https://github.com/tj/n.git synced 2024-11-25 07:39:21 +01:00

Merge pull request #318 from AntSworD/for-PR

Allow more options for custom source mirrors.
This commit is contained in:
Nimit Kalra 2016-06-15 17:42:57 -05:00 committed by GitHub
commit 85ee3d6899

22
bin/n
View File

@ -358,7 +358,6 @@ erase_line() {
#
# Check if the HEAD response of <url> 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 <version>
#
@ -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