David Burger | 234efd7 | 2020-02-26 17:34:47 -0700 | [diff] [blame] | 1 | #!/bin/bash |
Jack Neus | b371b95 | 2021-10-07 17:34:45 +0000 | [diff] [blame] | 2 | # Copyright 2021 The Chromium OS Authors. All rights reserved. |
David Burger | 234efd7 | 2020-02-26 17:34:47 -0700 | [diff] [blame] | 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
Jack Neus | b87c73b | 2021-11-10 20:20:18 +0000 | [diff] [blame] | 6 | find_checkout_root() { |
| 7 | path="$(dirname "$0")" |
Jack Neus | de61a36 | 2021-12-29 15:52:04 +0000 | [diff] [blame] | 8 | path="$(realpath "${path}")" |
Jack Neus | b87c73b | 2021-11-10 20:20:18 +0000 | [diff] [blame] | 9 | while [[ "${path}" != "/" && ! -d "${path}/.repo" ]] |
| 10 | do |
| 11 | path="$(dirname "${path}")" |
| 12 | done |
| 13 | echo "${path}" |
| 14 | } |
Jack Neus | b8b00c4 | 2021-07-28 15:07:38 +0000 | [diff] [blame] | 15 | |
Jack Neus | b87c73b | 2021-11-10 20:20:18 +0000 | [diff] [blame] | 16 | # Setup a project. |
Jack Neus | b371b95 | 2021-10-07 17:34:45 +0000 | [diff] [blame] | 17 | mkdir /tmp/setup_project 2>/dev/null |
| 18 | cipd install -force -root /tmp/setup_project \ |
| 19 | chromiumos/infra/setup_project/\$\{platform\} prod |
Jack Neus | de61a36 | 2021-12-29 15:52:04 +0000 | [diff] [blame] | 20 | echo "Done installing CIPD package." |
Jack Neus | b87c73b | 2021-11-10 20:20:18 +0000 | [diff] [blame] | 21 | |
Jack Neus | b371b95 | 2021-10-07 17:34:45 +0000 | [diff] [blame] | 22 | # If --checkout is not supplied, assume that this script is being run from |
Jack Neus | b87c73b | 2021-11-10 20:20:18 +0000 | [diff] [blame] | 23 | # a checkout. Find the root of the checkout. |
Jack Neus | b371b95 | 2021-10-07 17:34:45 +0000 | [diff] [blame] | 24 | if [[ "$*" != *"-checkout"* ]]; then |
Jack Neus | de61a36 | 2021-12-29 15:52:04 +0000 | [diff] [blame] | 25 | echo "--checkout not supplied, searching for checkout root." |
Jack Neus | b87c73b | 2021-11-10 20:20:18 +0000 | [diff] [blame] | 26 | checkout_root="$(find_checkout_root)" |
Jack Neus | de61a36 | 2021-12-29 15:52:04 +0000 | [diff] [blame] | 27 | echo "Found checkout root ${checkout_root}." |
Jack Neus | b87c73b | 2021-11-10 20:20:18 +0000 | [diff] [blame] | 28 | if [[ "${checkout_root}" != "/" ]]; then |
| 29 | set -- "$@" "-checkout=$(find_checkout_root)/" |
| 30 | else |
| 31 | echo "You are invoking setup_project.sh from outside of a CrOS checkout." |
| 32 | echo "Please specify the location of the checkout with -checkout." |
| 33 | fi |
Jack Neus | b371b95 | 2021-10-07 17:34:45 +0000 | [diff] [blame] | 34 | fi |
| 35 | /tmp/setup_project/setup_project setup-project "$@" |