| #!/usr/bin/env bash |
| # Copyright 2016 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style |
| # license that can be found in the LICENSE file. |
| |
| set -euf -o pipefail |
| |
| readonly JIRI_REPO_URL="https://fuchsia.googlesource.com/jiri" |
| readonly GS_BUCKET_URL="https://fuchsia-build.storage.googleapis.com/jiri" |
| |
| # Accept the first argument as a list of OSes to build for. Possible values |
| # are valid GOOS strings from https://golang.org/doc/install/source#environment. |
| if [[ $# -eq 1 ]]; then |
| readonly TARGETS="${1}" |
| else |
| readonly TARGETS="linux darwin" |
| fi |
| |
| # Determine and validate the version of jiri. |
| readonly HOST_OS=$(uname | tr '[:upper:]' '[:lower:]') |
| readonly COMMIT_URL="${JIRI_REPO_URL}/+refs/heads/master?format=JSON" |
| readonly VERSION=$(curl -sSf "${COMMIT_URL}" | sed -n 's/.*"value": "\([0-9a-f]\{40\}\)"/\1/p') |
| if [[ -z ${VERSION} ]]; then |
| echo "Cannot determine the latest jiri version" 1>&2 |
| exit 1 |
| fi |
| |
| # Do all our work in a temporary directory, then rm it when we're done. |
| readonly TEMP_DIR="$(mktemp -d)" |
| trap "rm -rf -- "${TEMP_DIR}"" EXIT |
| |
| for target in ${TARGETS}; do |
| os=$(echo ${target} | sed 's/darwin/mac/') |
| mkdir -p "${TEMP_DIR}/jiri-${os}" |
| |
| # Download the jiri binary. |
| if ! curl -sf -o "${TEMP_DIR}/jiri-${os}/jiri" "${GS_BUCKET_URL}/${target}-amd64/${VERSION}"; then |
| echo "Failed downloading prebuilt jiri binary." 1>&2 |
| echo "${GS_BUCKET_URL}/${os}/${VERSION}" |
| exit 1 |
| fi |
| chmod 755 "${TEMP_DIR}/jiri-${os}/jiri" |
| |
| # Upload the jiri binary to CIPD |
| cipd create -name "fuchsia/tools/jiri/${os}-amd64" -in "${TEMP_DIR}/jiri-${os}" -ref latest -tag "git_repository:https://fuchsia.googlesource.com/jiri" -tag "git_revision:${VERSION}" |
| done |