v.io/jiri@v0.0.0-20160715023856-abfb8b131290/scripts/bootstrap_jiri (about) 1 #!/bin/bash 2 # Copyright 2015 The Vanadium Authors. All rights reserved. 3 # Use of this source code is governed by a BSD-style 4 # license that can be found in the LICENSE file. 5 6 # bootstrap_jiri initializes a root directory for jiri. The following 7 # directories and files will be created: 8 # <root_dir> - root directory (picked by user) 9 # <root_dir>/.jiri_root - root metadata directory 10 # <root_dir>/.jiri_root/bin/jiri - jiri binary 11 # <root_dir>/.jiri_root/scripts/jiri - jiri script 12 # 13 # The jiri sources are downloaded and built into a temp directory, which is 14 # always deleted when this script finishes. The <root_dir> is deleted on any 15 # failure. 16 17 set -euf -o pipefail 18 19 # fatal prints an error message, followed by the usage string, and then exits. 20 fatal() { 21 usage=' 22 23 Usage: 24 bootstrap_jiri <root_dir> 25 26 A typical bootstrap workflow looks like this: 27 28 $ curl -s https://raw.githubusercontent.com/vanadium/go.jiri/master/scripts/bootstrap_jiri | bash -s myroot 29 $ export PATH=myroot/.jiri_root/scripts:$PATH 30 $ cd myroot 31 $ jiri import public https://vanadium.googlesource.com/manifest 32 $ jiri update' 33 echo "ERROR: $@${usage}" 1>&2 34 exit 1 35 } 36 37 # toabs converts the possibly relative argument into an absolute path. Run in a 38 # subshell to avoid changing the caller's working directory. 39 toabs() ( 40 cd $(dirname $1) 41 echo ${PWD}/$(basename $1) 42 ) 43 44 # Check the <root_dir> argument is supplied and doesn't already exist. 45 if [[ $# -ne 1 ]]; then 46 fatal "need <root_dir> argument" 47 fi 48 mkdir -p $(dirname $1) 49 root_dir=$(toabs $1) 50 if [[ -e ${root_dir} ]]; then 51 fatal "${root_dir} already exists" 52 fi 53 # Check that go is on the PATH. 54 if ! go version >& /dev/null ; then 55 fatal 'ERROR: "go" tool not found, see https://golang.org/doc/install' 56 fi 57 58 trap "rm -rf ${root_dir}" INT TERM EXIT 59 60 # Make the output directories. 61 tmp_dir="${root_dir}/.jiri_root/tmp" 62 bin_dir="${root_dir}/.jiri_root/bin" 63 scripts_dir="${root_dir}/.jiri_root/scripts" 64 mkdir -p "${tmp_dir}" "${bin_dir}" "${scripts_dir}" 65 66 # Go get the jiri source files, build the jiri binary, and copy the jiri shim 67 # script from the sources. 68 GOPATH="${tmp_dir}" go get -d v.io/jiri/cmd/jiri 69 GOPATH="${tmp_dir}" go build -o "${bin_dir}/jiri" v.io/jiri/cmd/jiri 70 cp "${tmp_dir}/src/v.io/jiri/scripts/jiri" "${scripts_dir}/jiri" 71 72 # Clean up the tmp_dir. 73 rm -rf "${tmp_dir}" 74 75 echo "Please add ${scripts_dir} to your PATH." 76 trap - EXIT