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. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 function do_cleanup { | 48 function do_cleanup { |
49 sudo losetup -d "$LOOP_DEV" | 49 sudo losetup -d "$LOOP_DEV" |
50 } | 50 } |
51 | 51 |
52 # Copy MBR and rootfs to output image | 52 # Copy MBR and rootfs to output image |
53 if [ -b "$FLAGS_to" ] | 53 if [ -b "$FLAGS_to" ] |
54 then | 54 then |
55 # Output to a block device (i.e., a real USB key), so need sudo dd | 55 # Output to a block device (i.e., a real USB key), so need sudo dd |
56 echo "Copying USB image ${FLAGS_from} to device ${FLAGS_to}..." | 56 echo "Copying USB image ${FLAGS_from} to device ${FLAGS_to}..." |
57 | 57 |
| 58 # Warn if it looks like they supplied a partition as the destination. |
| 59 if echo $FLAGS_to | grep -q '[0-9]$'; then |
| 60 drive=$(echo $FLAGS_to | sed -re 's/[0-9]+$//') |
| 61 if [ -b "$drive" ]; then |
| 62 echo |
| 63 echo "NOTE: It looks like you may have supplied a partition as the " |
| 64 echo "destination. This script needs to write to the drive's device " |
| 65 echo "node instead (i.e. ${drive} rather than ${FLAGS_to})." |
| 66 echo |
| 67 fi |
| 68 fi |
| 69 |
58 # Make sure this is really what the user wants, before nuking the device | 70 # Make sure this is really what the user wants, before nuking the device |
59 if [ $FLAGS_yes -ne $FLAGS_TRUE ] | 71 if [ $FLAGS_yes -ne $FLAGS_TRUE ] |
60 then | 72 then |
61 echo "This will erase all data on this device:" | 73 echo "This will erase all data on this device:" |
62 sudo fdisk -l "$FLAGS_to" | grep Disk | head -1 | 74 sudo fdisk -l "$FLAGS_to" | grep Disk | head -1 |
63 read -p "Are you sure (y/N)? " SURE | 75 read -p "Are you sure (y/N)? " SURE |
64 SURE="${SURE:0:1}" # Get just the first character | 76 SURE="${SURE:0:1}" # Get just the first character |
65 if [ "$SURE" != "y" ] | 77 if [ "$SURE" != "y" ] |
66 then | 78 then |
67 echo "Ok, better safe than sorry." | 79 echo "Ok, better safe than sorry." |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 echo "Done. To copy to USB keyfob, outside the chroot, do something like:" | 144 echo "Done. To copy to USB keyfob, outside the chroot, do something like:" |
133 echo " sudo dd if=${FLAGS_to} of=/dev/sdb bs=4M" | 145 echo " sudo dd if=${FLAGS_to} of=/dev/sdb bs=4M" |
134 echo "where /dev/sdb is the entire keyfob." | 146 echo "where /dev/sdb is the entire keyfob." |
135 if [ $INSIDE_CHROOT -eq 1 ] | 147 if [ $INSIDE_CHROOT -eq 1 ] |
136 then | 148 then |
137 echo "NOTE: Since you are currently inside the chroot, and you'll need to" | 149 echo "NOTE: Since you are currently inside the chroot, and you'll need to" |
138 echo "run dd outside the chroot, the path to the USB image will be" | 150 echo "run dd outside the chroot, the path to the USB image will be" |
139 echo "different (ex: ~/chromeos/trunk/src/build/images/SOME_DIR/usb.img)." | 151 echo "different (ex: ~/chromeos/trunk/src/build/images/SOME_DIR/usb.img)." |
140 fi | 152 fi |
141 fi | 153 fi |
OLD | NEW |