Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: src/scripts/image_to_usb.sh

Issue 2363002: Print out disk manufacturer and product while asking user to confirm write to disk (Closed) Base URL: ssh://gitrw.chromium.org/chromiumos
Patch Set: Added size to disk listing Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 83
84 if [ -z "${FLAGS_to}" ]; then 84 if [ -z "${FLAGS_to}" ]; then
85 echo "You must specify a file or device to write to using --to." 85 echo "You must specify a file or device to write to using --to."
86 disks=$(list_usb_disks) 86 disks=$(list_usb_disks)
87 if [ -n "$disks" ]; then 87 if [ -n "$disks" ]; then
88 echo "Available USB disks:" 88 echo "Available USB disks:"
89 for disk in $disks; do 89 for disk in $disks; do
90 echo " /dev/$disk:" 90 echo " /dev/$disk:"
91 echo " Manufacturer: $(get_disk_info $disk manufacturer)" 91 echo " Manufacturer: $(get_disk_info $disk manufacturer)"
92 echo " Product: $(get_disk_info $disk product)" 92 echo " Product: $(get_disk_info $disk product)"
93 echo " Size: $(cat /sys/block/$disk/size) kBytes"
93 done 94 done
94 fi 95 fi
95 exit 1 96 exit 1
96 fi 97 fi
97 98
98 # Convert args to paths. Need eval to un-quote the string so that shell 99 # Convert args to paths. Need eval to un-quote the string so that shell
99 # chars like ~ are processed; just doing FOO=`readlink -f ${FOO}` won't work. 100 # chars like ~ are processed; just doing FOO=`readlink -f ${FOO}` won't work.
100 FLAGS_from=`eval readlink -f ${FLAGS_from}` 101 FLAGS_from=`eval readlink -f ${FLAGS_from}`
101 FLAGS_to=`eval readlink -f ${FLAGS_to}` 102 FLAGS_to=`eval readlink -f ${FLAGS_to}`
102 103
103 # One last check to make sure user is not shooting themselves in the foot 104 # One last check to make sure user is not shooting themselves in the foot
104 if [ -b "${FLAGS_to}" ] && 105 if [ -b "${FLAGS_to}" ]; then
105 ! list_usb_disks | grep -q '^'${FLAGS_to##*/}'$' && 106 if list_usb_disks | grep -q '^'${FLAGS_to##*/}'$'; then
106 [ ${FLAGS_force_non_usb} -ne ${FLAGS_TRUE} ] 107 disk_manufacturer=$(get_disk_info ${FLAGS_to##*/} manufacturer)
107 then 108 disk_product=$(get_disk_info ${FLAGS_to##*/} product)
108 # Safeguard against writing to a real non-USB disk 109 elif [ ${FLAGS_force_non_usb} -ne ${FLAGS_TRUE} ]; then
109 echo "Error: Device ${FLAGS_to} does not appear to be a USB disk!" 110 # Safeguard against writing to a real non-USB disk
110 echo " To override this safeguard, use the --force_non_usb flag" 111 echo "Error: Device ${FLAGS_to} does not appear to be a USB disk!"
111 exit 1 112 echo " To override this safeguard, use the --force_non_usb flag"
113 exit 1
114 fi
112 fi 115 fi
113 116
114 # Use this image as the source image to copy 117 # Use this image as the source image to copy
115 SRC_IMAGE="${FLAGS_from}/${FLAGS_image_name}" 118 SRC_IMAGE="${FLAGS_from}/${FLAGS_image_name}"
116 119
117 STATEFUL_DIR="${FLAGS_from}/stateful_partition" 120 STATEFUL_DIR="${FLAGS_from}/stateful_partition"
118 mkdir -p "${STATEFUL_DIR}" 121 mkdir -p "${STATEFUL_DIR}"
119 122
120 function do_cleanup { 123 function do_cleanup {
121 echo "Cleaning loopback devices: ${STATEFUL_LOOP_DEV}" 124 echo "Cleaning loopback devices: ${STATEFUL_LOOP_DEV}"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 echo "destination. This script needs to write to the drive's device " 179 echo "destination. This script needs to write to the drive's device "
177 echo "node instead (i.e. ${drive} rather than ${FLAGS_to})." 180 echo "node instead (i.e. ${drive} rather than ${FLAGS_to})."
178 echo 181 echo
179 fi 182 fi
180 fi 183 fi
181 184
182 # Make sure this is really what the user wants, before nuking the device 185 # Make sure this is really what the user wants, before nuking the device
183 if [ ${FLAGS_yes} -ne ${FLAGS_TRUE} ] 186 if [ ${FLAGS_yes} -ne ${FLAGS_TRUE} ]
184 then 187 then
185 sudo fdisk -l "${FLAGS_to}" 2>/dev/null | grep Disk | head -1 188 sudo fdisk -l "${FLAGS_to}" 2>/dev/null | grep Disk | head -1
189 [ -n "$disk_manufacturer" ] && echo "Manufacturer: $disk_manufacturer"
190 [ -n "$disk_product" ] && echo "Product: $disk_product"
186 echo "This will erase all data on this device:" 191 echo "This will erase all data on this device:"
187 read -p "Are you sure (y/N)? " SURE 192 read -p "Are you sure (y/N)? " SURE
188 SURE="${SURE:0:1}" # Get just the first character 193 SURE="${SURE:0:1}" # Get just the first character
189 if [ "${SURE}" != "y" ] 194 if [ "${SURE}" != "y" ]
190 then 195 then
191 echo "Ok, better safe than sorry." 196 echo "Ok, better safe than sorry."
192 exit 1 197 exit 1
193 fi 198 fi
194 fi 199 fi
195 200
(...skipping 24 matching lines...) Expand all
220 echo " sudo dd if=${FLAGS_to} of=/dev/sdX bs=4M" 225 echo " sudo dd if=${FLAGS_to} of=/dev/sdX bs=4M"
221 echo "where /dev/sdX is the entire drive." 226 echo "where /dev/sdX is the entire drive."
222 if [ ${INSIDE_CHROOT} -eq 1 ] 227 if [ ${INSIDE_CHROOT} -eq 1 ]
223 then 228 then
224 example=$(basename "${FLAGS_to}") 229 example=$(basename "${FLAGS_to}")
225 echo "NOTE: Since you are currently inside the chroot, and you'll need to" 230 echo "NOTE: Since you are currently inside the chroot, and you'll need to"
226 echo "run dd outside the chroot, the path to the USB image will be" 231 echo "run dd outside the chroot, the path to the USB image will be"
227 echo "different (ex: ~/chromeos/trunk/src/build/images/SOME_DIR/$example)." 232 echo "different (ex: ~/chromeos/trunk/src/build/images/SOME_DIR/$example)."
228 fi 233 fi
229 fi 234 fi
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698