mirror of
https://github.com/rbenv/ruby-build.git
synced 2025-01-01 14:44:48 +01:00
ruby-package fetch --check
This commit is contained in:
parent
59269d1571
commit
4fbb207e0f
1 changed files with 53 additions and 15 deletions
|
@ -2,32 +2,70 @@
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "usage: ruby-package fetch PACKAGE" >&2
|
echo "usage: ruby-package fetch [--check] PACKAGE" >&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ -z "$1" ]; then
|
check() {
|
||||||
|
local url="$1"
|
||||||
|
|
||||||
|
set +e
|
||||||
|
curl -ILfs "$url" >/dev/null
|
||||||
|
local result="$?"
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [ "$result" -ne 0 ]; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
download() {
|
||||||
|
local url="$1"
|
||||||
|
local filename="$2"
|
||||||
|
|
||||||
|
set +e
|
||||||
|
curl -Lfs "$url" > "$filename"
|
||||||
|
local result="$?"
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [ "$result" -ne 0 ]; then
|
||||||
|
return 1
|
||||||
|
elif [ ! -f "$filename" ]; then
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
echo "$filename"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
check=""
|
||||||
|
if [ "$1" = "--check" ]; then
|
||||||
|
check=1
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
|
package="$1"
|
||||||
|
if [ -z "$package" ]; then
|
||||||
usage
|
usage
|
||||||
fi
|
fi
|
||||||
package_name="${1}.$(ruby-package platform).rubypackage"
|
|
||||||
|
package_name="${package}.$(ruby-package platform).rubypackage"
|
||||||
|
|
||||||
package_repo="${RUBY_PACKAGE_REPO%/}"
|
package_repo="${RUBY_PACKAGE_REPO%/}"
|
||||||
if [ -z "$ruby_package_repo" ]; then
|
if [ -z "$ruby_package_repo" ]; then
|
||||||
package_repo="https://github.com/downloads/sstephenson/ruby-packages"
|
package_repo="https://github.com/downloads/sstephenson/ruby-packages"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
url="${package_repo}/${package_name}"
|
package_url="${package_repo}/${package_name}"
|
||||||
filename="${TMPDIR}/${package_name}.$$"
|
|
||||||
|
|
||||||
set +e
|
if [ -n "$check" ]; then
|
||||||
curl -Lfs "$url" > "$filename"
|
check "$package_url" || {
|
||||||
result="$?"
|
echo "error: package \`$package' not found ($package_url)"
|
||||||
set -e
|
exit 1
|
||||||
|
} >&2
|
||||||
if [ "$result" -eq 22 ]; then
|
|
||||||
exit 3
|
|
||||||
elif [ ! -f "$filename" ]; then
|
|
||||||
exit 2
|
|
||||||
else
|
else
|
||||||
echo "$filename"
|
package_filename="${TMPDIR}/${package_name}.$$"
|
||||||
|
download "$package_url" "$package_filename" || {
|
||||||
|
echo "error: couldn't fetch package \`$package' ($package_url)"
|
||||||
|
exit 1
|
||||||
|
} >&2
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue