about summary refs log tree commit diff
path: root/src/ci/docker/scripts/shared.sh
diff options
context:
space:
mode:
authorTshepang Mbambo <hopsi@tuta.io>2025-06-09 07:19:50 +0200
committerGitHub <noreply@github.com>2025-06-09 07:19:50 +0200
commit4967fd24dec0b178e8766c0d5ce6146d2fd2c152 (patch)
tree84784da83b710a97f9944b753c9d7717e37b631b /src/ci/docker/scripts/shared.sh
parent8290ab531ce162a920da5d3c625889697ff65375 (diff)
parent7565e75591c2ef184bc7a359b3a436a62d45358a (diff)
downloadrust-4967fd24dec0b178e8766c0d5ce6146d2fd2c152.tar.gz
rust-4967fd24dec0b178e8766c0d5ce6146d2fd2c152.zip
Merge pull request #2461 from rust-lang/rustc-pull
Rustc pull update
Diffstat (limited to 'src/ci/docker/scripts/shared.sh')
-rw-r--r--src/ci/docker/scripts/shared.sh34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/ci/docker/scripts/shared.sh b/src/ci/docker/scripts/shared.sh
index 9969659088d..6efdbb2070d 100644
--- a/src/ci/docker/scripts/shared.sh
+++ b/src/ci/docker/scripts/shared.sh
@@ -40,3 +40,37 @@ function retry {
     }
   done
 }
+
+download_tar_and_extract_into_dir() {
+  local url="$1"
+  local sum="$2"
+  local dir="$3"
+  local file=$(mktemp -u)
+
+  while :; do
+    if [[ -f "$file" ]]; then
+      if ! h="$(sha256sum "$file" | awk '{ print $1 }')"; then
+        printf 'ERROR: reading hash\n' >&2
+        exit 1
+      fi
+
+      if [[ "$h" == "$sum" ]]; then
+        break
+      fi
+
+      printf 'WARNING: hash mismatch: %s != expected %s\n' "$h" "$sum" >&2
+      rm -f "$file"
+    fi
+
+    printf 'Downloading: %s\n' "$url"
+    if ! curl -f -L -o "$file" "$url"; then
+       rm -f "$file"
+      sleep 1
+    fi
+  done
+
+  mkdir -p "$dir"
+  cd "$dir"
+  tar -xf "$file"
+  rm -f "$file"
+}