| #!/bin/bash |
| |
| # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| # This script generates the list of board overlays and variants. |
| |
| # Load common CrOS utilities. Inside the chroot this file is installed in |
| # /usr/lib/crosutils. Outside the chroot we find it relative to the scripts |
| # location. |
| common_paths="/usr/lib/crosutils $(dirname "$0")/../../../scripts" |
| |
| for path in ${common_paths} ; do |
| if [ -f "${path}/common.sh" ] ; then |
| COMMON_SH="${path}/common.sh" |
| break |
| fi |
| done |
| |
| if [ -z "${COMMON_SH}" ] ; then |
| echo "common.sh not found in search path (${common_paths})" |
| exit 1 |
| fi |
| |
| . "${COMMON_SH}" |
| |
| get_default_board |
| |
| # Flags |
| DEFINE_boolean all_boards "${FLAGS_FALSE}" \ |
| "Return paths to overlays for all boards. (Default: false)" |
| DEFINE_string board "$DEFAULT_BOARD" "The name of the board to set up." |
| DEFINE_string board_overlay "" "Location of the board overlay." |
| DEFINE_boolean primary_only ${FLAGS_FALSE} \ |
| "Only return the path to the board's primary overlay. (Default: false)" |
| DEFINE_boolean private ${FLAGS_TRUE} \ |
| "Include private overlays. (Default: true)" |
| DEFINE_boolean public ${FLAGS_TRUE} \ |
| "Include public overlays. (Default: true)" |
| DEFINE_string variant "" "Board variant." |
| |
| # Parse command line flags |
| FLAGS "$@" || exit 1 |
| eval set -- "${FLAGS_ARGV}" |
| |
| # Only now can we die on error. shflags functions leak non-zero error codes, |
| # so will die prematurely if 'set -e' is specified before now. |
| set -e |
| |
| public() { [ "$FLAGS_public" = "$FLAGS_TRUE" ]; } |
| private() { [ "$FLAGS_private" = "$FLAGS_TRUE" ]; } |
| |
| if [ "$FLAGS_all_boards" = "$FLAGS_TRUE" ] ; then |
| overlays= |
| public && overlays="$overlays ${SRC_ROOT}/overlays/*overlay*" |
| private && overlays="$overlays ${SRC_ROOT}/private-overlays/*overlay*" |
| for overlay in $overlays ; do |
| if [ -d "$overlay" ] ; then |
| echo $overlay |
| fi |
| done |
| exit 0 |
| fi |
| |
| if [ -z "$FLAGS_board" ] ; then |
| error "--board required." |
| exit 1 |
| fi |
| |
| if [[ $FLAGS_board =~ [_\ ] ]] ; then |
| error "--board name must not contain an underscore (_) or a space ( )." |
| exit 1 |
| fi |
| |
| if [[ $FLAGS_variant =~ [_\ ] ]] ; then |
| error "--variant name must not contain an underscore (_) or a space ( )." |
| exit 1 |
| fi |
| |
| # |
| # Check that the provided variant overlay name is valid. |
| # |
| if [ -n "$FLAGS_variant" ] ; then |
| VARIANT_NAME="overlay-variant-${FLAGS_board}-${FLAGS_variant}" |
| VARIANT_OVERLAY="${SRC_ROOT}/overlays/${VARIANT_NAME}" |
| PRIVATE_VARIANT_NAME="overlay-variant-${FLAGS_board}-${FLAGS_variant}-private" |
| PRIVATE_VARIANT_OVERLAY="${SRC_ROOT}/private-overlays/${PRIVATE_VARIANT_NAME}" |
| if [ ! -d "${VARIANT_OVERLAY}" ] && \ |
| [ ! -d "${PRIVATE_VARIANT_OVERLAY}" ] ; then |
| error "There is no variant overlay called '${FLAGS_variant}'" |
| exit 1 |
| fi |
| fi |
| |
| function is_primary_overlay() { |
| local directory=$1 |
| [ -f "${directory}/make.conf" ] || return 1 |
| [ -f "${directory}/toolchain.conf" ] || return 1 |
| return 0 |
| } |
| |
| BOARD_OVERLAY="${SRC_ROOT}/overlays/overlay-${FLAGS_board}" |
| PRIVATE_OVERLAY_NAME="overlay-${FLAGS_board}-private" |
| PRIVATE_BOARD_OVERLAY="${SRC_ROOT}/private-overlays/${PRIVATE_OVERLAY_NAME}" |
| |
| # |
| # Identify the primary board overlay or die. |
| # |
| if public && is_primary_overlay ${BOARD_OVERLAY}; then |
| PRIMARY_OVERLAY="${BOARD_OVERLAY}" |
| elif private && is_primary_overlay "${PRIVATE_BOARD_OVERLAY}"; then |
| PRIMARY_OVERLAY="${PRIVATE_BOARD_OVERLAY}" |
| fi |
| if [ ! -n "${PRIMARY_OVERLAY}" ]; then |
| error "There is no primary board overlay for ${FLAGS_board}" |
| exit 1 |
| fi |
| |
| # |
| # If only the primary overlay is needed, provide it and exit. |
| # |
| if [ "${FLAGS_primary_only}" -eq "${FLAGS_TRUE}" ]; then |
| echo "${PRIMARY_OVERLAY}" |
| exit 0 |
| fi |
| |
| # |
| # Check for chromeos-overlay. |
| # |
| CHROMEOS_OVERLAY="${SRC_ROOT}/private-overlays/chromeos-overlay" |
| |
| if private && [ -d "${CHROMEOS_OVERLAY}" ]; then |
| echo "${CHROMEOS_OVERLAY}" |
| fi |
| |
| # |
| # Check for chromeos-partner-overlay. |
| # |
| CHROMEOS_PARTNER_OVERLAY="${SRC_ROOT}/private-overlays/chromeos-partner-overlay" |
| |
| if private && [ -d "${CHROMEOS_PARTNER_OVERLAY}" ]; then |
| echo "${CHROMEOS_PARTNER_OVERLAY}" |
| fi |
| |
| # |
| # Check if there are any public board overlays. |
| # |
| if public && [ -d "${BOARD_OVERLAY}" ]; then |
| echo "${BOARD_OVERLAY}" |
| |
| # |
| # Add the public variant overlay if it exists. |
| # |
| if [ -n "$FLAGS_variant" ] ; then |
| if [ -d "$VARIANT_OVERLAY" ] ; then |
| echo "${VARIANT_OVERLAY}" |
| fi |
| fi |
| fi |
| |
| # |
| # Add any private overlays and private variant overlays for this board. |
| # |
| if private && [ -d "${SRC_ROOT}/private-overlays" ] ; then |
| OVERLAY_NAME="overlay-${FLAGS_board}-private" |
| PRIVATE_OVERLAY="${SRC_ROOT}/private-overlays/${OVERLAY_NAME}" |
| |
| if [ -d "${PRIVATE_OVERLAY}" ] ; then |
| echo "${PRIVATE_OVERLAY}" |
| fi |
| |
| # |
| # Add the private variant overlay if it exists. |
| # |
| if [ -n "$FLAGS_variant" ] ; then |
| if [ -d "${PRIVATE_VARIANT_OVERLAY}" ] ; then |
| echo "${PRIVATE_VARIANT_OVERLAY}" |
| fi |
| fi |
| fi |
| |
| # |
| # Finally, add in any user requested board overlays. |
| # |
| if [ -d "${FLAGS_board_overlay}" ] ; then |
| echo "${FLAGS_board_overlay}" |
| fi |