Mike Frysinger | 078af0b | 2018-08-16 14:56:49 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Copyright 2018 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | # Random helper utilities that scripts might want. |
| 7 | |
| 8 | # Show an error message. |
| 9 | error() { |
| 10 | echo "ERROR: $*" >&2 |
| 11 | } |
| 12 | |
| 13 | # Show an error message and exit. |
| 14 | die() { |
| 15 | error "$*" |
| 16 | exit 1 |
| 17 | } |
| 18 | |
| 19 | if [[ -z "${CONTRIB_DIR}" ]]; then |
| 20 | die "Scripts must set CONTRIB_DIR first" |
| 21 | fi |
| 22 | |
| 23 | # Load the shflags helper library. Any script using us will probably have |
| 24 | # command line flags, and they should be using shflags to parse them. |
| 25 | source "${CONTRIB_DIR}/shflags" || die "Could not load shflags" |
| 26 | |
| 27 | # Path to the repo checkout. |
| 28 | GCLIENT_ROOT="/mnt/host/source" |
| 29 | SRC_ROOT="${GCLIENT_ROOT}/src" |
| 30 | |
| 31 | # Whether we're executing inside the cros_sdk chroot. |
| 32 | is_inside_chroot() { |
| 33 | [[ -f "/etc/cros_chroot_version" ]] |
| 34 | } |
| 35 | |
| 36 | # Fail unless we're inside the chroot. This guards against messing up your |
| 37 | # workstation. |
| 38 | assert_inside_chroot() { |
| 39 | if ! is_inside_chroot; then |
| 40 | die "This script must be run inside the chroot. Run this first: cros_sdk" |
| 41 | fi |
| 42 | } |