Commit 912034bf authored by Mislav Marohnić's avatar Mislav Marohnić
Browse files

Merge branch 'shasum'

Fixes #548, closes #551
parents c79dcb37 a11107f3
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -148,8 +148,8 @@ $ cat fix1.patch fix2.patch | rbenv install --patch 1.9.3-p429

### Checksum verification

If you have the `md5`, `openssl`, or `md5sum` tool installed, ruby-build will
automatically verify the MD5 checksum of each downloaded package before
If you have the `shasum`, `openssl`, or `sha256sum` tool installed, ruby-build will
automatically verify the SHA2 checksum of each downloaded package before
installing it.

Checksums are optional and specified as anchors on the package URL in each
@@ -165,9 +165,9 @@ official URL specified in the definition file.
You can point ruby-build to another mirror by specifying the
`RUBY_BUILD_MIRROR_URL` environment variable--useful if you'd like to run your
own local mirror, for example. Package mirror URLs are constructed by joining
this variable with the MD5 checksum of the package file.
this variable with the SHA2 checksum of the package file.

If you don't have an MD5 program installed, ruby-build will skip the download
If you don't have an SHA2 program installed, ruby-build will skip the download
mirror and use official URLs instead. You can force ruby-build to bypass the
mirror by setting the `RUBY_BUILD_SKIP_MIRROR` environment variable.

+36 −6
Original line number Diff line number Diff line
@@ -166,14 +166,31 @@ make_package() {
  popd >&4
}

compute_sha2() {
  local output
  if type shasum &>/dev/null; then
    output="$(shasum -a 256 -b)" || return 1
    echo "${output% *}"
  elif type openssl &>/dev/null; then
    output="$(openssl dgst -sha256)" || return 1
    echo "${output##* }"
  elif type sha256sum &>/dev/null; then
    output="$(sha256sum --quiet)" || return 1
    echo "${output% *}"
  else
    return 1
  fi
}

compute_md5() {
  local output
  if type md5 &>/dev/null; then
    md5 -q
  elif type openssl &>/dev/null; then
    local output="$(openssl md5)"
    output="$(openssl md5)" || return 1
    echo "${output##* }"
  elif type md5sum &>/dev/null; then
    local output="$(md5sum -b)"
    output="$(md5sum -b)" || return 1
    echo "${output% *}"
  else
    return 1
@@ -181,8 +198,9 @@ compute_md5() {
}

verify_checksum() {
  # If there's no MD5 support, return success
  [ -n "$HAS_MD5_SUPPORT" ] || return 0
  # If there's no SHA2 support, return success
  [ -n "$HAS_SHA2_SUPPORT" ] || return 0
  local checksum_command="compute_sha2"

  # If the specified filename doesn't exist, return success
  local filename="$1"
@@ -192,8 +210,14 @@ verify_checksum() {
  local expected_checksum=`echo "$2" | tr [A-Z] [a-z]`
  [ -n "$expected_checksum" ] || return 0

  # If the checksum length is 32 chars, assume MD5, otherwise SHA2
  if [ "${#expected_checksum}" -eq 32 ]; then
    [ -n "$HAS_MD5_SUPPORT" ] || return 0
    checksum_command="compute_md5"
  fi

  # If the computed checksum is empty, return failure
  local computed_checksum=`echo "$(compute_md5 < "$filename")" | tr [A-Z] [a-z]`
  local computed_checksum=`echo "$($checksum_command < "$filename")" | tr [A-Z] [a-z]`
  [ -n "$computed_checksum" ] || return 1

  if [ "$expected_checksum" != "$computed_checksum" ]; then
@@ -989,11 +1013,17 @@ if [ -n "$RUBY_BUILD_SKIP_MIRROR" ]; then
  unset RUBY_BUILD_MIRROR_URL
fi

if echo test | compute_sha2 >/dev/null; then
  HAS_SHA2_SUPPORT=1
else
  unset HAS_SHA2_SUPPORT
  unset RUBY_BUILD_MIRROR_URL
fi

if echo test | compute_md5 >/dev/null; then
  HAS_MD5_SUPPORT=1
else
  unset HAS_MD5_SUPPORT
  unset RUBY_BUILD_MIRROR_URL
fi

SEED="$(date "+%Y%m%d%H%M%S").$$"
+3 −3
Original line number Diff line number Diff line
@@ -11,8 +11,8 @@ test_mirrored() {
  curl -qsSfIL "$RUBY_BUILD_MIRROR_URL/$1" >/dev/null 2>&1
}

compute_md5() {
  local output="$(openssl md5)"
compute_sha2() {
  local output="$(openssl dgst -sha256)"
  echo "${output##* }" | tr '[A-Z]' '[a-z]'
}

@@ -26,7 +26,7 @@ download_and_verify() {
  local file="$2"
  local expected="$3"
  download_package "$url" "$file"
  checksum="$(compute_md5 < "$file")"
  checksum="$(compute_sha2 < "$file")"
  if [ "$checksum" != "$expected" ]; then
    echo "Error: $url doesn't match its checksum $expected" >&2
    return 1
+2 −2
Original line number Diff line number Diff line
require_gcc
install_package "ruby-1.8.6-p383" "http://cache.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6-p383.tar.gz#4f49544d4a4d0d34e9d86c41e853db2e" auto_tcltk standard
install_package "rubygems-1.3.7" "http://production.cf.rubygems.org/rubygems/rubygems-1.3.7.tgz#e85cfadd025ff6ab689375adbf344bbe" ruby
install_package "ruby-1.8.6-p383" "http://cache.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6-p383.tar.gz#cea6c67f737727007ec89d1c93fd7d0dba035220f981706091b8642d7a43c03a" auto_tcltk standard
install_package "rubygems-1.3.7" "http://production.cf.rubygems.org/rubygems/rubygems-1.3.7.tgz#388b90ae6273f655507b10c8ba6bee9ea72e7d49c3e610025531cb8c3ba67c9d" ruby
+2 −2
Original line number Diff line number Diff line
require_gcc
install_package "ruby-1.8.6-p420" "http://cache.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6-p420.tar.gz#ca1eee44f842e93b5098bc5a2bb9a40b" auto_tcltk standard
install_package "rubygems-1.3.7" "http://production.cf.rubygems.org/rubygems/rubygems-1.3.7.tgz#e85cfadd025ff6ab689375adbf344bbe" ruby
install_package "ruby-1.8.6-p420" "http://cache.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6-p420.tar.gz#118e6f24afce8e8a10dced23635168e58da6c9121a21f120c82f425d40a1e321" auto_tcltk standard
install_package "rubygems-1.3.7" "http://production.cf.rubygems.org/rubygems/rubygems-1.3.7.tgz#388b90ae6273f655507b10c8ba6bee9ea72e7d49c3e610025531cb8c3ba67c9d" ruby
Loading