| 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 # --- 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 # Load functions and constants for chromeos-install | 30 # Load functions and constants for chromeos-install |
| 14 . "$(dirname "$0")/chromeos-common.sh" | 31 [ -f /usr/lib/installer/chromeos-common.sh ] && \ |
| 32 INSTALLER_ROOT=/usr/lib/installer || \ |
| 33 INSTALLER_ROOT=$(dirname "$(readlink -f "$0")") |
| 34 |
| 35 . "${INSTALLER_ROOT}/chromeos-common.sh" || \ |
| 36 die "Unable to load chromeos-common.sh" |
| 15 | 37 |
| 16 get_default_board | 38 get_default_board |
| 17 | 39 |
| 18 # Flags | 40 # Flags |
| 19 DEFINE_string board "${DEFAULT_BOARD}" "Board for which the image was built" | 41 DEFINE_string board "${DEFAULT_BOARD}" "Board for which the image was built" |
| 20 DEFINE_string from "" \ | 42 DEFINE_string from "" \ |
| 21 "Directory containing chromiumos_image.bin" | 43 "Directory containing chromiumos_image.bin" |
| 22 DEFINE_string to "/dev/sdX" "${DEFAULT_TO_HELP}" | 44 DEFINE_string to "/dev/sdX" "${DEFAULT_TO_HELP}" |
| 23 DEFINE_boolean yes ${FLAGS_FALSE} "Answer yes to all prompts" "y" | 45 DEFINE_boolean yes ${FLAGS_FALSE} "Answer yes to all prompts" "y" |
| 24 DEFINE_boolean force_copy ${FLAGS_FALSE} "Always rebuild test image" | 46 DEFINE_boolean force_copy ${FLAGS_FALSE} "Always rebuild test image" |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 echo "Done with mod_image_for_test." | 198 echo "Done with mod_image_for_test." |
| 177 else | 199 else |
| 178 echo "Using cached test image." | 200 echo "Using cached test image." |
| 179 fi | 201 fi |
| 180 SRC_IMAGE="${FLAGS_from}/chromiumos_test_image.bin" | 202 SRC_IMAGE="${FLAGS_from}/chromiumos_test_image.bin" |
| 181 echo "Source test image is: ${SRC_IMAGE}" | 203 echo "Source test image is: ${SRC_IMAGE}" |
| 182 fi | 204 fi |
| 183 | 205 |
| 184 | 206 |
| 185 # Let's do it. | 207 # Let's do it. |
| 186 if [ -b "${FLAGS_to}" ] | 208 if [ -b "${FLAGS_to}" ]; then |
| 187 then | |
| 188 # Output to a block device (i.e., a real USB key), so need sudo dd | 209 # Output to a block device (i.e., a real USB key), so need sudo dd |
| 189 if [ ${FLAGS_install} -ne ${FLAGS_TRUE} ]; then | 210 if [ ${FLAGS_install} -ne ${FLAGS_TRUE} ]; then |
| 190 echo "Copying USB image ${SRC_IMAGE} to device ${FLAGS_to}..." | 211 echo "Copying USB image ${SRC_IMAGE} to device ${FLAGS_to}..." |
| 191 else | 212 else |
| 192 echo "Installing USB image ${SRC_IMAGE} to device ${FLAGS_to}..." | 213 echo "Installing USB image ${SRC_IMAGE} to device ${FLAGS_to}..." |
| 193 fi | 214 fi |
| 194 | 215 |
| 195 # Warn if it looks like they supplied a partition as the destination. | 216 # Warn if it looks like they supplied a partition as the destination. |
| 196 if echo "${FLAGS_to}" | grep -q '[0-9]$'; then | 217 if echo "${FLAGS_to}" | grep -q '[0-9]$'; then |
| 197 drive=$(echo "${FLAGS_to}" | sed -re 's/[0-9]+$//') | 218 drive=$(echo "${FLAGS_to}" | sed -re 's/[0-9]+$//') |
| 198 if [ -b "${drive}" ]; then | 219 if [ -b "${drive}" ]; then |
| 199 echo | 220 echo |
| 200 echo "NOTE: It looks like you may have supplied a partition as the " | 221 echo "NOTE: It looks like you may have supplied a partition as the " |
| 201 echo "destination. This script needs to write to the drive's device " | 222 echo "destination. This script needs to write to the drive's device " |
| 202 echo "node instead (i.e. ${drive} rather than ${FLAGS_to})." | 223 echo "node instead (i.e. ${drive} rather than ${FLAGS_to})." |
| 203 echo | 224 echo |
| 204 fi | 225 fi |
| 205 fi | 226 fi |
| 206 | 227 |
| 207 # Make sure this is really what the user wants, before nuking the device | 228 # Make sure this is really what the user wants, before nuking the device |
| 208 if [ ${FLAGS_yes} -ne ${FLAGS_TRUE} ] | 229 if [ ${FLAGS_yes} -ne ${FLAGS_TRUE} ]; then |
| 209 then | |
| 210 sudo fdisk -l "${FLAGS_to}" 2>/dev/null | grep Disk | head -1 | 230 sudo fdisk -l "${FLAGS_to}" 2>/dev/null | grep Disk | head -1 |
| 211 [ -n "$disk_manufacturer" ] && echo "Manufacturer: $disk_manufacturer" | 231 [ -n "$disk_manufacturer" ] && echo "Manufacturer: $disk_manufacturer" |
| 212 [ -n "$disk_product" ] && echo "Product: $disk_product" | 232 [ -n "$disk_product" ] && echo "Product: $disk_product" |
| 213 echo "This will erase all data on this device:" | 233 echo "This will erase all data on this device:" |
| 214 read -p "Are you sure (y/N)? " SURE | 234 read -p "Are you sure (y/N)? " SURE |
| 215 SURE="${SURE:0:1}" # Get just the first character | 235 SURE="${SURE:0:1}" # Get just the first character |
| 216 if [ "${SURE}" != "y" ] | 236 if [ "${SURE}" != "y" ]; then |
| 217 then | |
| 218 echo "Ok, better safe than sorry." | 237 echo "Ok, better safe than sorry." |
| 219 exit 1 | 238 exit 1 |
| 220 fi | 239 fi |
| 221 fi | 240 fi |
| 222 | 241 |
| 223 echo "Attempting to unmount any mounts on the USB device..." | 242 echo "Attempting to unmount any mounts on the USB device..." |
| 224 for i in $(mount | grep ^"${FLAGS_to}" | awk '{print $1}') | 243 for i in $(mount | grep ^"${FLAGS_to}" | awk '{print $1}'); do |
| 225 do | |
| 226 if sudo umount "$i" 2>&1 >/dev/null | grep "not found"; then | 244 if sudo umount "$i" 2>&1 >/dev/null | grep "not found"; then |
| 227 echo | 245 echo |
| 228 echo "The device you have specified is already mounted at some point " | 246 echo "The device you have specified is already mounted at some point " |
| 229 echo "that is not visible from inside the chroot. Please unmount the " | 247 echo "that is not visible from inside the chroot. Please unmount the " |
| 230 echo "device manually from outside the chroot and try again." | 248 echo "device manually from outside the chroot and try again." |
| 231 echo | 249 echo |
| 232 exit 1 | 250 exit 1 |
| 233 fi | 251 fi |
| 234 done | 252 done |
| 235 sleep 3 | 253 sleep 3 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 263 echo "Done." | 281 echo "Done." |
| 264 else | 282 else |
| 265 # Output to a file, so just make a copy. | 283 # Output to a file, so just make a copy. |
| 266 echo "Copying ${SRC_IMAGE} to ${FLAGS_to}..." | 284 echo "Copying ${SRC_IMAGE} to ${FLAGS_to}..." |
| 267 cp -f "${SRC_IMAGE}" "${FLAGS_to}" | 285 cp -f "${SRC_IMAGE}" "${FLAGS_to}" |
| 268 | 286 |
| 269 echo "Done. To copy to a USB drive, do something like:" | 287 echo "Done. To copy to a USB drive, do something like:" |
| 270 echo " sudo dd if=${FLAGS_to} of=/dev/sdX bs=4M oflag=sync" | 288 echo " sudo dd if=${FLAGS_to} of=/dev/sdX bs=4M oflag=sync" |
| 271 echo "where /dev/sdX is the entire drive." | 289 echo "where /dev/sdX is the entire drive." |
| 272 fi | 290 fi |
| OLD | NEW |