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 VirtualBox image. | 7 # Script to convert the output of build_image.sh to a VirtualBox image. |
8 # Load common constants. This should be the first executable line. | 8 |
9 # The path to common.sh should be relative to your script's location. | 9 # --- BEGIN COMMON.SH BOILERPLATE --- |
10 . "$(dirname "$0")/common.sh" | 10 # Load common CrOS utilities. Inside the chroot this file is installed in |
| 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 --- |
11 | 29 |
12 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images" | 30 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images" |
13 # Default to the most recent image | 31 # Default to the most recent image |
14 DEFAULT_FROM="${IMAGES_DIR}/`ls -t $IMAGES_DIR | head -1`" | 32 DEFAULT_FROM="${IMAGES_DIR}/`ls -t $IMAGES_DIR | head -1`" |
15 DEFAULT_TO="${DEFAULT_FROM}/os.vdi" | 33 DEFAULT_TO="${DEFAULT_FROM}/os.vdi" |
16 TEMP_IMAGE="${IMAGES_DIR}/temp.img" | 34 TEMP_IMAGE="${IMAGES_DIR}/temp.img" |
17 | 35 |
18 # Flags | 36 # Flags |
19 DEFINE_string from "$DEFAULT_FROM" \ | 37 DEFINE_string from "$DEFAULT_FROM" \ |
20 "Directory containing rootfs.image and mbr.image" | 38 "Directory containing rootfs.image and mbr.image" |
21 DEFINE_string to "$DEFAULT_TO" \ | 39 DEFINE_string to "$DEFAULT_TO" \ |
22 "Destination file for VirtualBox image" | 40 "Destination file for VirtualBox image" |
23 | 41 |
24 # Parse command line | 42 # Parse command line |
25 FLAGS "$@" || exit 1 | 43 FLAGS "$@" || exit 1 |
26 eval set -- "${FLAGS_ARGV}" | 44 eval set -- "${FLAGS_ARGV}" |
27 | 45 |
28 # Die on any errors. | 46 # Die on any errors. |
29 set -e | 47 set -e |
30 | 48 |
31 # Convert args to paths. Need eval to un-quote the string so that shell | 49 # 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. | 50 # chars like ~ are processed; just doing FOO=`readlink -f $FOO` won't work. |
33 FLAGS_from=`eval readlink -f $FLAGS_from` | 51 FLAGS_from=`eval readlink -f $FLAGS_from` |
34 FLAGS_to=`eval readlink -f $FLAGS_to` | 52 FLAGS_to=`eval readlink -f $FLAGS_to` |
35 | 53 |
36 # Check if qemu-img and VBoxManage are available. | 54 # Check if qemu-img and VBoxManage are available. |
37 for EXTERNAL_tools in qemu-img VBoxManage; do | 55 for EXTERNAL_tools in qemu-img VBoxManage; do |
38 if ! type ${EXTERNAL_tools} >/dev/null 2>&1; then | 56 if ! type ${EXTERNAL_tools} >/dev/null 2>&1; then |
39 echo "Error: This script requires ${EXTERNAL_tools}." | 57 echo "Error: This script requires ${EXTERNAL_tools}." |
40 exit 1 | 58 exit 1 |
41 fi | 59 fi |
42 done | 60 done |
43 | 61 |
44 $(dirname "$0")/image_to_vmware.sh --format=virtualbox --from=$FLAGS_from \ | 62 "${SCRIPTS_DIR}/image_to_vmware.sh" --format=virtualbox --from="$FLAGS_from" \ |
45 --to=$(dirname "$FLAGS_to") --vbox_disk=$(basename "$FLAGS_to") | 63 --to="$(dirname "$FLAGS_to")" --vbox_disk="$(basename "$FLAGS_to")" |
OLD | NEW |