blob: 2f77826049afc4df55f55463963876d2f33a50f7 [file] [log] [blame]
Mike Frysinger078af0b2018-08-16 14:56:49 -04001#!/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.
9error() {
10 echo "ERROR: $*" >&2
11}
12
13# Show an error message and exit.
14die() {
15 error "$*"
16 exit 1
17}
18
19if [[ -z "${CONTRIB_DIR}" ]]; then
20 die "Scripts must set CONTRIB_DIR first"
21fi
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.
25source "${CONTRIB_DIR}/shflags" || die "Could not load shflags"
26
27# Path to the repo checkout.
28GCLIENT_ROOT="/mnt/host/source"
29SRC_ROOT="${GCLIENT_ROOT}/src"
30
31# Whether we're executing inside the cros_sdk chroot.
32is_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.
38assert_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}