|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Copyright 2021, 2025 Delphix |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | + |
| 18 | +set -o xtrace |
| 19 | + |
| 20 | +BASEURL="https://artifactory.delphix.com/artifactory/linux-pkg/rust" |
| 21 | + |
| 22 | +function die() { |
| 23 | + echo "$(basename "$0"): $*" >&2 |
| 24 | + exit 1 |
| 25 | +} |
| 26 | + |
| 27 | +function usage() { |
| 28 | + echo "$(basename "$0"): $*" >&2 |
| 29 | + echo "Usage: $(basename "$0") <version> <prefix> <destdir> <cpu>" |
| 30 | + exit 2 |
| 31 | +} |
| 32 | + |
| 33 | +function cleanup() { |
| 34 | + [[ -n "$TEMP_DIR" ]] && [[ -d "$TEMP_DIR" ]] && rm -rf "$TEMP_DIR" |
| 35 | +} |
| 36 | + |
| 37 | +[[ $# -gt 3 ]] && usage "too many arguments specified" |
| 38 | +[[ $# -lt 3 ]] && usage "too few arguments specified" |
| 39 | + |
| 40 | +VERSION="$1" |
| 41 | +PREFIX="$2" |
| 42 | +DESTDIR="$3" |
| 43 | + |
| 44 | +RUST="rustc-${VERSION}-src" |
| 45 | + |
| 46 | +[[ -z "$VERSION" ]] && usage "version not specified." |
| 47 | +[[ -z "$PREFIX" ]] && usage "prefix not specified." |
| 48 | +[[ -z "$DESTDIR" ]] && usage "destdir not specified." |
| 49 | + |
| 50 | +# |
| 51 | +# The full path is required, so DESTDIR can be used after calling "pushd" below. |
| 52 | +# |
| 53 | +DESTDIR="$(readlink -f "$DESTDIR")" |
| 54 | +mkdir -p "${DESTDIR}" || die "'mkdir -p \"${DESTDIR}\"' failed" |
| 55 | + |
| 56 | +curl -v https://keybase.io/rust/pgp_keys.asc | gpg --import || |
| 57 | + die "failed to import GPG key" |
| 58 | + |
| 59 | +trap cleanup EXIT |
| 60 | + |
| 61 | +TEMP_DIR="$(mktemp -d -t delphix-rust.XXXXXXX)" |
| 62 | +[[ -d "$TEMP_DIR" ]] || die "failed to create temporary directory '$TEMP_DIR'" |
| 63 | +pushd "$TEMP_DIR" &>/dev/null || die "'pushd $TEMP_DIR' failed" |
| 64 | + |
| 65 | +wget -nv "${BASEURL}/${RUST}.tar.xz" || die "failed to download tarfile" |
| 66 | +wget -nv "${BASEURL}/${RUST}.tar.xz.asc" || die "failed to download signature" |
| 67 | +gpg --verify "${RUST}.tar.xz.asc" "${RUST}.tar.xz" || |
| 68 | + die "failed to verify signature" |
| 69 | + |
| 70 | +mkdir -p "${DESTDIR}${PREFIX}/rustc-${VERSION}" || |
| 71 | + die "failed to install; 'prefix=${PREFIX}' and 'destdir=${DESTDIR}'" |
| 72 | +tar -xvf "${RUST}.tar.xz" \ |
| 73 | + -C "${DESTDIR}${PREFIX}/rustc-${VERSION}" --strip-components 1 || |
| 74 | + die "failed to extract tarfile" |
| 75 | + |
| 76 | +popd &>/dev/null || die "'popd' failed" |
0 commit comments