|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +VERSION=${VERSION:-"v0.18.1"} |
| 4 | +# Expected SHA256 checksums taken from https://github.com/asdf-vm/asdf/releases/tag/v0.18.1 |
| 5 | +# When we change asdf versions, these must be changed |
| 6 | +sha256sum_expected_arm="sha256:1850faf576cab7acb321e99dd98d3fe0d4665e1331086ad9ed991aeec1dc9d36" |
| 7 | +sha256sum_expected_amd64="sha256:56141dc99eab75c140dcdd85cf73f3b82fed2485a8dccd4f11a4dc5cbcb6ea5c" |
| 8 | + |
| 9 | +if [ "$(id -u)" -ne 0 ]; then |
| 10 | + echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' |
| 11 | + exit 1 |
| 12 | +fi |
| 13 | + |
| 14 | +# Checks if packages are installed and installs them if not |
| 15 | +check_packages() { |
| 16 | + if ! dpkg -s "$@" > /dev/null 2>&1; then |
| 17 | + apt_get_update |
| 18 | + apt-get -y install --no-install-recommends "$@" |
| 19 | + fi |
| 20 | +} |
| 21 | + |
| 22 | +check_packages curl ca-certificates tar sha256sum |
| 23 | + |
| 24 | +install() { |
| 25 | + tmp_dir="$(mktemp -d)" |
| 26 | + trap 'rm -rf "${tmp_dir}"' EXIT |
| 27 | + |
| 28 | + download_file="${tmp_dir}/asdf.tar.gz" |
| 29 | + |
| 30 | + if [ "$TARGETARCH" = "arm64" ] || [ "$TARGETARCH" == "aarch64" ]; then |
| 31 | + download_url="https://github.com/asdf-vm/asdf/releases/download/${VERSION}/asdf-${VERSION}-linux-arm64.tar.gz" |
| 32 | + sha256sum_expected="${sha256sum_expected_arm}" |
| 33 | + else |
| 34 | + download_url="https://github.com/asdf-vm/asdf/releases/download/${VERSION}/asdf-${VERSION}-linux-amd64.tar.gz" |
| 35 | + sha256sum_expected="${sha256sum_expected_amd64}" |
| 36 | + fi |
| 37 | + curl -fsSL "${download_url}" -o "${download_file}" |
| 38 | + |
| 39 | + download_file_sha256sum=$(sha256sum "${download_file}" | awk '{print $1}') |
| 40 | + if [ "${download_file_sha256sum}" != "${sha256sum_expected#sha256:}" ]; then |
| 41 | + echo "SHA256 checksum mismatch for downloaded asdf archive" |
| 42 | + echo "Expected: ${sha256sum_expected}" |
| 43 | + echo "Actual: sha256:${download_file_sha256sum}" |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | + |
| 47 | + tar -xzf "${download_file}" -C "${tmp_dir}" |
| 48 | + mkdir -p /usr/bin |
| 49 | + mv "${tmp_dir}/asdf" /usr/bin/asdf |
| 50 | + chmod +x /usr/bin/asdf |
| 51 | +} |
| 52 | +echo "(*) Installing asdf..." |
| 53 | + |
| 54 | +install |
| 55 | + |
| 56 | +echo "Done!" |
0 commit comments