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 # Load common constants. This should be the first executable line. | 7 # --- BEGIN COMMON.SH BOILERPLATE --- |
8 # The path to common.sh should be relative to your script's location. | 8 # Load common CrOS utilities. Inside the chroot this file is installed in |
9 . "$(dirname "$0")/common.sh" | 9 # /usr/lib/crosutils. Outside the chroot we find it relative to the script's |
| 10 # location. |
| 11 find_common_sh() { |
| 12 local common_paths=(/usr/lib/crosutils $(dirname "$(readlink -f "$0")")) |
| 13 local path |
| 14 |
| 15 SCRIPT_ROOT= |
| 16 for path in "${common_paths[@]}"; do |
| 17 if [ -r "${path}/common.sh" ]; then |
| 18 SCRIPT_ROOT=${path} |
| 19 break |
| 20 fi |
| 21 done |
| 22 } |
| 23 |
| 24 find_common_sh |
| 25 . "${SCRIPT_ROOT}/common.sh" || (echo "Unable to load common.sh" && exit 1) |
| 26 # --- END COMMON.SH BOILERPLATE --- |
10 | 27 |
11 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images" | 28 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images" |
12 | 29 |
13 # Flags | 30 # Flags |
14 DEFINE_string from "" "Directory containing rootfs.image and mbr.image" | 31 DEFINE_string from "" "Directory containing rootfs.image and mbr.image" |
15 DEFINE_string to "" "Destination file for USB image." | 32 DEFINE_string to "" "Destination file for USB image." |
16 DEFINE_integer offset 0 "Offset to write the kernel to in the destination." | 33 DEFINE_integer offset 0 "Offset to write the kernel to in the destination." |
17 | 34 |
18 # Parse command line | 35 # Parse command line |
19 FLAGS "$@" || exit 1 | 36 FLAGS "$@" || exit 1 |
20 eval set -- "${FLAGS_ARGV}" | 37 eval set -- "${FLAGS_ARGV}" |
21 | 38 |
22 # Die on any errors. | 39 # Die on any errors. |
23 set -e | 40 set -e |
24 | 41 |
25 if [ -z "${FLAGS_from}" -o -z "${FLAGS_to}" -o -z "${FLAGS_offset}" ] | 42 if [ -z "${FLAGS_from}" -o -z "${FLAGS_to}" -o -z "${FLAGS_offset}" ]; then |
26 then | |
27 echo "You must define all of from, to and offset." | 43 echo "You must define all of from, to and offset." |
28 exit 1 | 44 exit 1 |
29 fi | 45 fi |
30 | 46 |
31 # Convert args to paths. Need eval to un-quote the string so that shell | 47 # Convert args to paths. Need eval to un-quote the string so that shell |
32 # chars like ~ are processed; just doing FOO=`readlink -f $FOO` won't work. | 48 # chars like ~ are processed; just doing FOO=`readlink -f $FOO` won't work. |
33 FLAGS_from=`eval readlink -f ${FLAGS_from}` | 49 FLAGS_from=`eval readlink -f ${FLAGS_from}` |
34 FLAGS_to=`eval readlink -f ${FLAGS_to}` | 50 FLAGS_to=`eval readlink -f ${FLAGS_to}` |
35 | 51 |
36 function do_cleanup { | 52 function do_cleanup { |
(...skipping 15 matching lines...) Expand all Loading... |
52 echo "Writing kernel to ${FLAGS_to} at ${FLAGS_offset}..." | 68 echo "Writing kernel to ${FLAGS_to} at ${FLAGS_offset}..." |
53 sudo "${SCRIPTS_DIR}"/file_copy.py \ | 69 sudo "${SCRIPTS_DIR}"/file_copy.py \ |
54 if=/tmp/kernel_fetch.$$/boot/vmlinux.uimg \ | 70 if=/tmp/kernel_fetch.$$/boot/vmlinux.uimg \ |
55 of="${FLAGS_to}" \ | 71 of="${FLAGS_to}" \ |
56 seek_bytes="${FLAGS_offset}" | 72 seek_bytes="${FLAGS_offset}" |
57 echo "Done." | 73 echo "Done." |
58 | 74 |
59 do_cleanup | 75 do_cleanup |
60 | 76 |
61 trap - EXIT | 77 trap - EXIT |
OLD | NEW |