blob: a7e16ec493e725c95550b869f9e8cf1566b01120 [file] [log] [blame]
#!/usr/bin/env bash
# Copyright 2015 The Vanadium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
# bootstrap_jiri initializes a root directory for jiri. The following
# directories and files will be created:
# <root_dir> - root directory (picked by user)
# <root_dir>/.jiri_root - root metadata directory
# <root_dir>/.jiri_root/bin/jiri - jiri binary
# The jiri sources are downloaded and built into a temp directory, which is
# always deleted when this script finishes. The <root_dir> is deleted on any
# failure.
set -euf -o pipefail
# Jiri repo, from which we will download the jiri script wrapper.
readonly JIRI_REPO_URL=""
# Google Storage bucket that contains prebuilt versions of jiri.
readonly GS_BUCKET_URL=""
# fatal prints an error message, followed by the usage string, and then exits.
fatal() {
bootstrap_jiri <root_dir>
A typical bootstrap workflow looks like this:
$ curl -s | bash -s myroot
$ export PATH=myroot/.jiri_root/bin:$PATH
$ cd myroot
$ jiri import manifest
$ jiri update'
echo "ERROR: $@${usage}" 1>&2
exit 1
readonly HOST_ARCH=$(uname -m)
if [ "$HOST_ARCH" == "aarch64" ]; then
readonly ARCH="arm64"
elif [ "$HOST_ARCH" == "x86_64" ]; then
readonly ARCH="amd64"
echo "Arch not supported: $HOST_ARCH"
exit 1
# toabs converts the possibly relative argument into an absolute path. Run in a
# subshell to avoid changing the caller's working directory.
toabs() (
cd $(dirname $1)
echo ${PWD}/$(basename $1)
# Check the <root_dir> argument is supplied.
if [[ $# -ne 1 ]]; then
fatal "need <root_dir> argument"
# Ensure <root_dir> doesn't already exist: this is important since we trap this script and
# rm -rf <root_dir> if anything fails.
mkdir -p "$(dirname $1)"
readonly ROOT_DIR="$(toabs $1)"
if [[ -e "${ROOT_DIR}" ]]; then
if ! [[ -z "$(ls -A "$ROOT_DIR")" ]]; then
fatal "${ROOT_DIR} is not empty"
# Remove the root_dir if this script fails so as to not leave the environment in a strange half-state.
trap "rm -rf ${ROOT_DIR}" INT TERM EXIT
# Make the output directories.
readonly BIN_DIR="${ROOT_DIR}/.jiri_root/bin"
mkdir -p "${BIN_DIR}"
# Determine and validate the version of jiri.
readonly HOST_OS=$(uname | tr '[:upper:]' '[:lower:]')
readonly TARGET="${HOST_OS}-${ARCH}"
readonly COMMIT_URL="${JIRI_REPO_URL}/+refs/heads/master?format=JSON"
readonly LOG_URL="${JIRI_REPO_URL}/+log/refs/heads/master?format=JSON"
readonly VERSION=$(curl -sSf "${COMMIT_URL}" | sed -n 's/.*"value": "\([0-9a-f]\{40\}\)"/\1/p')
readonly VERSIONS=$(curl -sSf "${LOG_URL}" | sed -n 's/.*"commit": "\([0-9a-f]\{40\}\)".*/\1/p')
for version in ${VERSIONS}; do
if curl --output /dev/null --silent --head --fail "${url}"; then
if [[ -z "${JIRI_URL}" ]]; then
echo "Cannot find prebuilt Jiri binary." 1>&2
exit 1
if ! curl -sf -o "${BIN_DIR}/jiri" "${JIRI_URL}"; then
echo "Failed downloading prebuilt Jiri binary." 1>&2
exit 1
chmod 755 "${BIN_DIR}/jiri"
if [ "$ARCH" == "arm64" ]; then
echo "WARNING: Jiri doesn't support timely updates for arch '$HOST_ARCH'. This or future binaries of Jiri might be out of date."
echo "Please add ${BIN_DIR} to your PATH"
trap - EXIT