OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 | 2 |
3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 # Prints the path to the most recently built image to stdout. | 7 # Prints the path to the most recently built image to stdout. |
8 | 8 |
9 # Load common constants. This should be the first executable line. | 9 # --- BEGIN COMMON.SH BOILERPLATE --- |
10 # The path to common.sh should be relative to your script's location. | 10 # Load common CrOS utilities. Inside the chroot this file is installed in |
11 . "$(dirname "$0")/common.sh" | 11 # /usr/lib/crosutils. Outside the chroot we find it relative to the script's |
| 12 # location. |
| 13 find_common_sh() { |
| 14 local common_paths=(/usr/lib/crosutils $(dirname "$(readlink -f "$0")")) |
| 15 local path |
| 16 |
| 17 SCRIPT_ROOT= |
| 18 for path in "${common_paths[@]}"; do |
| 19 if [ -r "${path}/common.sh" ]; then |
| 20 SCRIPT_ROOT=${path} |
| 21 break |
| 22 fi |
| 23 done |
| 24 } |
| 25 |
| 26 find_common_sh |
| 27 . "${SCRIPT_ROOT}/common.sh" || (echo "Unable to load common.sh" && exit 1) |
| 28 # --- END COMMON.SH BOILERPLATE --- |
12 | 29 |
13 get_default_board | 30 get_default_board |
14 | 31 |
15 DEFINE_string board "$DEFAULT_BOARD" \ | 32 DEFINE_string board "$DEFAULT_BOARD" \ |
16 "The name of the board to check for images." | 33 "The name of the board to check for images." |
17 | 34 |
18 # Parse command line flags | 35 # Parse command line flags |
19 FLAGS "$@" || exit 1 | 36 FLAGS "$@" || exit 1 |
20 eval set -- "${FLAGS_ARGV}" | 37 eval set -- "${FLAGS_ARGV}" |
21 | 38 |
22 # Check on the board that they are trying to set up. | 39 # Check on the board that they are trying to set up. |
23 if [ -z "$FLAGS_board" ] ; then | 40 if [ -z "$FLAGS_board" ] ; then |
24 die "Error: --board required." | 41 die "Error: --board required." |
25 fi | 42 fi |
26 | 43 |
27 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" | 44 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" |
28 | 45 |
29 # If there are no images, return nothing | 46 # If there are no images, return nothing |
30 [ -d $IMAGES_DIR ] || exit 0 | 47 [ -d $IMAGES_DIR ] || exit 0 |
31 | 48 |
32 # Use latest link if it exists, otherwise most recently changed dir | 49 # Use latest link if it exists, otherwise most recently changed dir |
33 if [ -L ${IMAGES_DIR}/latest ] ; then | 50 if [ -L ${IMAGES_DIR}/latest ] ; then |
34 DEFAULT_FROM="${IMAGES_DIR}/`readlink ${IMAGES_DIR}/latest`" | 51 DEFAULT_FROM="${IMAGES_DIR}/`readlink ${IMAGES_DIR}/latest`" |
35 else | 52 else |
36 DEFAULT_FROM="${IMAGES_DIR}/`ls -t $IMAGES_DIR | head -1`" | 53 DEFAULT_FROM="${IMAGES_DIR}/`ls -t $IMAGES_DIR | head -1`" |
37 fi | 54 fi |
38 | 55 |
39 echo $DEFAULT_FROM | 56 echo $DEFAULT_FROM |
OLD | NEW |