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 # Script to convert the output of build_image.sh to a usb image. | 7 # Script to convert the output of build_image.sh to a usb image. |
8 | 8 |
9 # Load common constants. This should be the first executable line. | 9 # Load common constants. This should be the first executable line. |
10 # The path to common.sh should be relative to your script's location. | 10 # The path to common.sh should be relative to your script's location. |
11 . "$(dirname "$0")/common.sh" | 11 . "$(dirname "$0")/common.sh" |
12 | 12 |
13 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images" | |
14 # Default to the most recent image | |
15 DEFAULT_FROM="${IMAGES_DIR}/$(ls -t $IMAGES_DIR 2>&-| head -1)" | |
16 | |
17 # Script can be run either inside or outside the chroot. | |
18 if [ $INSIDE_CHROOT -eq 1 ] | |
19 then | |
20 # Inside the chroot, so output to usb.img in the same dir as the other | |
21 # images. | |
22 DEFAULT_TO="${DEFAULT_FROM}/usb.img" | |
23 DEFAULT_TO_HELP="Destination file for USB image." | |
24 AUTOTEST_SRC=/usr/local/autotest | |
25 else | |
26 # Outside the chroot, so output to the default device for a usb key. | |
27 DEFAULT_TO="/dev/sdb" | |
28 DEFAULT_TO_HELP="Destination device for USB keyfob." | |
29 AUTOTEST_SRC=${DEFAULT_CHROOT_DIR}/usr/local/autotest | |
30 fi | |
31 | 13 |
32 # Flags | 14 # Flags |
33 DEFINE_string from "$DEFAULT_FROM" \ | 15 DEFINE_string board "" "Board for which the image was built" |
| 16 DEFINE_string from "" \ |
34 "Directory containing rootfs.image and mbr.image" | 17 "Directory containing rootfs.image and mbr.image" |
35 DEFINE_string to "$DEFAULT_TO" "$DEFAULT_TO_HELP" | 18 DEFINE_string to "" "$DEFAULT_TO_HELP" |
36 DEFINE_boolean yes $FLAGS_FALSE "Answer yes to all prompts" "y" | 19 DEFINE_boolean yes $FLAGS_FALSE "Answer yes to all prompts" "y" |
37 DEFINE_boolean install_autotest $FLAGS_FALSE \ | 20 DEFINE_boolean install_autotest $FLAGS_FALSE \ |
38 "Whether to install autotest to the stateful partition." | 21 "Whether to install autotest to the stateful partition." |
39 | 22 |
40 # Parse command line | 23 # Parse command line |
41 FLAGS "$@" || exit 1 | 24 FLAGS "$@" || exit 1 |
42 eval set -- "${FLAGS_ARGV}" | 25 eval set -- "${FLAGS_ARGV}" |
43 | 26 |
| 27 # Inside the chroot, so output to usb.img in the same dir as the other |
| 28 # Script can be run either inside or outside the chroot. |
| 29 if [ $INSIDE_CHROOT -eq 1 ] |
| 30 then |
| 31 AUTOTEST_SRC="/usr/local/autotest/${FLAGS_board}" |
| 32 else |
| 33 AUTOTEST_SRC="${DEFAULT_CHROOT_DIR}/usr/local/autotest/${FLAGS_board}" |
| 34 fi |
| 35 |
44 # Die on any errors. | 36 # Die on any errors. |
45 set -e | 37 set -e |
46 | 38 |
| 39 # If from isn't explicitly set |
| 40 if [ -z "$FLAGS_from" ]; then |
| 41 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" |
| 42 FLAGS_from="${IMAGES_DIR}/$(ls -t $IMAGES_DIR 2>&-| head -1)" |
| 43 fi |
| 44 |
| 45 # If to isn't explicitly set |
| 46 if [ -z "$FLAGS_to" ]; then |
| 47 # Script can be run either inside or outside the chroot. |
| 48 if [ $INSIDE_CHROOT -eq 1 ] |
| 49 then |
| 50 # Inside the chroot, so output to usb.img in the same dir as the other |
| 51 # images. |
| 52 FLAGS_to="${FLAGS_from}/usb.img" |
| 53 else |
| 54 # Outside the chroot, so output to the default device for a usb key. |
| 55 FLAGS_to="/dev/sdb" |
| 56 fi |
| 57 fi |
| 58 |
47 # Convert args to paths. Need eval to un-quote the string so that shell | 59 # Convert args to paths. Need eval to un-quote the string so that shell |
48 # chars like ~ are processed; just doing FOO=`readlink -f $FOO` won't work. | 60 # chars like ~ are processed; just doing FOO=`readlink -f $FOO` won't work. |
49 FLAGS_from=`eval readlink -f $FLAGS_from` | 61 FLAGS_from=`eval readlink -f $FLAGS_from` |
50 FLAGS_to=`eval readlink -f $FLAGS_to` | 62 FLAGS_to=`eval readlink -f $FLAGS_to` |
51 | 63 |
52 function do_cleanup { | 64 function do_cleanup { |
53 sudo losetup -d "$LOOP_DEV" | 65 sudo losetup -d "$LOOP_DEV" |
54 } | 66 } |
55 | 67 |
56 STATEFUL_DIR=${FLAGS_from}/stateful_partition | 68 STATEFUL_DIR=${FLAGS_from}/stateful_partition |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 echo "Done. To copy to USB keyfob, outside the chroot, do something like:" | 195 echo "Done. To copy to USB keyfob, outside the chroot, do something like:" |
184 echo " sudo dd if=${FLAGS_to} of=/dev/sdb bs=4M" | 196 echo " sudo dd if=${FLAGS_to} of=/dev/sdb bs=4M" |
185 echo "where /dev/sdb is the entire keyfob." | 197 echo "where /dev/sdb is the entire keyfob." |
186 if [ $INSIDE_CHROOT -eq 1 ] | 198 if [ $INSIDE_CHROOT -eq 1 ] |
187 then | 199 then |
188 echo "NOTE: Since you are currently inside the chroot, and you'll need to" | 200 echo "NOTE: Since you are currently inside the chroot, and you'll need to" |
189 echo "run dd outside the chroot, the path to the USB image will be" | 201 echo "run dd outside the chroot, the path to the USB image will be" |
190 echo "different (ex: ~/chromeos/trunk/src/build/images/SOME_DIR/usb.img)." | 202 echo "different (ex: ~/chromeos/trunk/src/build/images/SOME_DIR/usb.img)." |
191 fi | 203 fi |
192 fi | 204 fi |
OLD | NEW |