OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 | 2 |
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 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 VMware image and write a | 7 # Script to convert the output of build_image.sh to a VMware image and write a |
8 # corresponding VMware config file. | 8 # corresponding VMware config file. |
9 | 9 |
10 # Load common constants. This should be the first executable line. | 10 # --- BEGIN COMMON.SH BOILERPLATE --- |
11 # The path to common.sh should be relative to your script's location. | 11 # Load common CrOS utilities. Inside the chroot this file is installed in |
12 . "$(dirname "$0")/common.sh" | 12 # /usr/lib/crosutils. Outside the chroot we find it relative to the script's |
13 . "$(dirname "$0")/chromeos-common.sh" | 13 # location. |
14 . "$(dirname "$0")/lib/cros_vm_constants.sh" | 14 find_common_sh() { |
| 15 local common_paths=(/usr/lib/crosutils $(dirname "$(readlink -f "$0")")) |
| 16 local path |
| 17 |
| 18 SCRIPT_ROOT= |
| 19 for path in "${common_paths[@]}"; do |
| 20 if [ -r "${path}/common.sh" ]; then |
| 21 SCRIPT_ROOT=${path} |
| 22 break |
| 23 fi |
| 24 done |
| 25 } |
| 26 |
| 27 find_common_sh |
| 28 . "${SCRIPT_ROOT}/common.sh" || (echo "Unable to load common.sh" && exit 1) |
| 29 # --- END COMMON.SH BOILERPLATE --- |
| 30 |
| 31 # Need to be inside the chroot to load chromeos-common.sh |
| 32 assert_inside_chroot |
| 33 |
| 34 # Load functions and constants for chromeos-install |
| 35 . "/usr/lib/installer/chromeos-common.sh" || \ |
| 36 die "Unable to load /usr/lib/installer/chromeos-common.sh" |
| 37 |
| 38 . "${SCRIPT_ROOT}/lib/cros_vm_constants.sh" || \ |
| 39 die "Unable to load ${SCRIPT_ROOT}/lib/cros_vm_constants.sh" |
15 | 40 |
16 get_default_board | 41 get_default_board |
17 assert_inside_chroot | |
18 | 42 |
19 # Flags | 43 # Flags |
20 DEFINE_string board "${DEFAULT_BOARD}" \ | 44 DEFINE_string board "${DEFAULT_BOARD}" \ |
21 "Board for which the image was built" | 45 "Board for which the image was built" |
22 DEFINE_boolean factory $FLAGS_FALSE \ | 46 DEFINE_boolean factory $FLAGS_FALSE \ |
23 "Modify the image for manufacturing testing" | 47 "Modify the image for manufacturing testing" |
24 DEFINE_boolean factory_install $FLAGS_FALSE \ | 48 DEFINE_boolean factory_install $FLAGS_FALSE \ |
25 "Modify the image for factory install shim" | 49 "Modify the image for factory install shim" |
26 DEFINE_boolean force_copy ${FLAGS_FALSE} "Always rebuild test image" | 50 DEFINE_boolean force_copy ${FLAGS_FALSE} "Always rebuild test image" |
27 DEFINE_string format "qemu" \ | 51 DEFINE_string format "qemu" \ |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 "${FLAGS_from}/chromiumos_test_image.bin" ${EXTRA_ARGS} --yes | 137 "${FLAGS_from}/chromiumos_test_image.bin" ${EXTRA_ARGS} --yes |
114 echo "Done with mod_image_for_test." | 138 echo "Done with mod_image_for_test." |
115 else | 139 else |
116 echo "Using cached test image." | 140 echo "Using cached test image." |
117 fi | 141 fi |
118 SRC_IMAGE="${FLAGS_from}/chromiumos_test_image.bin" | 142 SRC_IMAGE="${FLAGS_from}/chromiumos_test_image.bin" |
119 echo "Source test image is: ${SRC_IMAGE}" | 143 echo "Source test image is: ${SRC_IMAGE}" |
120 fi | 144 fi |
121 | 145 |
122 # Memory units are in MBs | 146 # Memory units are in MBs |
123 TEMP_IMG="$(dirname ${SRC_IMAGE})/vm_temp_image.bin" | 147 TEMP_IMG="$(dirname "${SRC_IMAGE}")/vm_temp_image.bin" |
124 | 148 |
125 # If we're not building for VMWare, don't build the vmx | 149 # If we're not building for VMWare, don't build the vmx |
126 if [ "${FLAGS_format}" != "vmware" ]; then | 150 if [ "${FLAGS_format}" != "vmware" ]; then |
127 FLAGS_make_vmx="${FLAGS_FALSE}" | 151 FLAGS_make_vmx="${FLAGS_FALSE}" |
128 fi | 152 fi |
129 | 153 |
130 # Convert args to paths. Need eval to un-quote the string so that shell | 154 # Convert args to paths. Need eval to un-quote the string so that shell |
131 # chars like ~ are processed; just doing FOO=`readlink -f $FOO` won't work. | 155 # chars like ~ are processed; just doing FOO=`readlink -f $FOO` won't work. |
132 FLAGS_from=`eval readlink -f $FLAGS_from` | 156 FLAGS_from=`eval readlink -f $FLAGS_from` |
133 FLAGS_to=`eval readlink -f $FLAGS_to` | 157 FLAGS_to=`eval readlink -f $FLAGS_to` |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 rmdir "${TEMP_MNT}" "${TEMP_ESP_MNT}" | 206 rmdir "${TEMP_MNT}" "${TEMP_ESP_MNT}" |
183 } | 207 } |
184 trap cleanup INT TERM EXIT | 208 trap cleanup INT TERM EXIT |
185 mkdir -p "${TEMP_MNT}" | 209 mkdir -p "${TEMP_MNT}" |
186 enable_rw_mount "${TEMP_ROOTFS}" | 210 enable_rw_mount "${TEMP_ROOTFS}" |
187 sudo mount -o loop "${TEMP_ROOTFS}" "${TEMP_MNT}" | 211 sudo mount -o loop "${TEMP_ROOTFS}" "${TEMP_MNT}" |
188 mkdir -p "${TEMP_ESP_MNT}" | 212 mkdir -p "${TEMP_ESP_MNT}" |
189 sudo mount -o loop "${TEMP_ESP}" "${TEMP_ESP_MNT}" | 213 sudo mount -o loop "${TEMP_ESP}" "${TEMP_ESP_MNT}" |
190 | 214 |
191 if [ "${FLAGS_format}" = "qemu" ]; then | 215 if [ "${FLAGS_format}" = "qemu" ]; then |
192 sudo python "$(dirname $0)/fixup_image_for_qemu.py" \ | 216 sudo python "${SCRIPTS_DIR}/fixup_image_for_qemu.py" \ |
193 --mounted_dir="${TEMP_MNT}" \ | 217 --mounted_dir="${TEMP_MNT}" \ |
194 --enable_tablet=true | 218 --enable_tablet=true |
195 else | 219 else |
196 sudo python "$(dirname $0)/fixup_image_for_qemu.py" \ | 220 sudo python "${SCRIPTS_DIR}/fixup_image_for_qemu.py" \ |
197 --mounted_dir="${TEMP_MNT}" \ | 221 --mounted_dir="${TEMP_MNT}" \ |
198 --enable_tablet=false | 222 --enable_tablet=false |
199 fi | 223 fi |
200 | 224 |
201 # Modify the unverified usb template which uses a default usb_disk of sdb3 | 225 # Modify the unverified usb template which uses a default usb_disk of sdb3 |
202 sudo sed -i -e 's/sdb3/sda3/g' "${TEMP_MNT}/boot/syslinux/usb.A.cfg" | 226 sudo sed -i -e 's/sdb3/sda3/g' "${TEMP_MNT}/boot/syslinux/usb.A.cfg" |
203 | 227 |
204 # Unmount everything prior to building a final image | 228 # Unmount everything prior to building a final image |
205 sync | 229 sync |
206 trap - INT TERM EXIT | 230 trap - INT TERM EXIT |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 echo "${VMX_CONFIG}" | 305 echo "${VMX_CONFIG}" |
282 fi | 306 fi |
283 | 307 |
284 | 308 |
285 if [ "${FLAGS_format}" == "qemu" ]; then | 309 if [ "${FLAGS_format}" == "qemu" ]; then |
286 echo "If you have qemu-kvm installed, you can start the image by:" | 310 echo "If you have qemu-kvm installed, you can start the image by:" |
287 echo "sudo kvm -m ${FLAGS_mem} -vga std -pidfile /tmp/kvm.pid -net nic,model=v
irtio " \ | 311 echo "sudo kvm -m ${FLAGS_mem} -vga std -pidfile /tmp/kvm.pid -net nic,model=v
irtio " \ |
288 "-net user,hostfwd=tcp::9222-:22 \\" | 312 "-net user,hostfwd=tcp::9222-:22 \\" |
289 echo " -hda ${FLAGS_to}/${DEFAULT_QEMU_IMAGE}" | 313 echo " -hda ${FLAGS_to}/${DEFAULT_QEMU_IMAGE}" |
290 fi | 314 fi |
OLD | NEW |