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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 fi | 83 fi |
84 | 84 |
85 # Convert args to paths. Need eval to un-quote the string so that shell | 85 # Convert args to paths. Need eval to un-quote the string so that shell |
86 # chars like ~ are processed; just doing FOO=`readlink -f ${FOO}` won't work. | 86 # chars like ~ are processed; just doing FOO=`readlink -f ${FOO}` won't work. |
87 FLAGS_from=`eval readlink -f ${FLAGS_from}` | 87 FLAGS_from=`eval readlink -f ${FLAGS_from}` |
88 FLAGS_to=`eval readlink -f ${FLAGS_to}` | 88 FLAGS_to=`eval readlink -f ${FLAGS_to}` |
89 | 89 |
90 # Use this image as the source image to copy | 90 # Use this image as the source image to copy |
91 SRC_IMAGE="${FLAGS_from}/chromiumos_image.bin" | 91 SRC_IMAGE="${FLAGS_from}/chromiumos_image.bin" |
92 | 92 |
93 # If we're asked to modify the image for test, then let's make a copy and | |
94 # modify that instead. | |
95 if [ ${FLAGS_test_image} -eq ${FLAGS_TRUE} ] ; then | |
96 if [ ! -f "${FLAGS_from}/chromiumos_test_image.bin" ] || \ | |
97 [ ${FLAGS_force_copy} -eq ${FLAGS_TRUE} ] ; then | |
98 # Copy it. | |
99 echo "Creating test image from original..." | |
100 cp -f "${SRC_IMAGE}" "${FLAGS_from}/chromiumos_test_image.bin" | |
101 | |
102 # Check for manufacturing image. | |
103 if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ] ; then | |
104 FACTORY_ARGS="--factory" | |
105 fi | |
106 | |
107 # Modify it. Pass --yes so that mod_image_for_test.sh won't ask us if we | |
108 # really want to modify the image; the user gave their assent already with | |
109 # --test-image and the original image is going to be preserved. | |
110 "${SCRIPTS_DIR}/mod_image_for_test.sh" --image \ | |
111 "${FLAGS_from}/chromiumos_test_image.bin" ${FACTORY_ARGS} --yes | |
112 echo "Done with mod_image_for_test." | |
113 else | |
114 echo "Using cached test image." | |
115 fi | |
116 SRC_IMAGE="${FLAGS_from}/chromiumos_test_image.bin" | |
117 echo "Source test image is: ${SRC_IMAGE}" | |
118 fi | |
119 | |
120 STATEFUL_DIR="${FLAGS_from}/stateful_partition" | 93 STATEFUL_DIR="${FLAGS_from}/stateful_partition" |
121 mkdir -p "${STATEFUL_DIR}" | 94 mkdir -p "${STATEFUL_DIR}" |
122 | 95 |
123 function do_cleanup { | 96 function do_cleanup { |
124 echo "Cleaning loopback devices: ${STATEFUL_LOOP_DEV}" | 97 echo "Cleaning loopback devices: ${STATEFUL_LOOP_DEV}" |
125 if [ "${STATEFUL_LOOP_DEV}" != "" ]; then | 98 if [ "${STATEFUL_LOOP_DEV}" != "" ]; then |
126 sudo umount "${STATEFUL_DIR}" | 99 sudo umount "${STATEFUL_DIR}" |
127 sudo losetup -d "${STATEFUL_LOOP_DEV}" | 100 sudo losetup -d "${STATEFUL_LOOP_DEV}" |
128 rmdir "${STATEFUL_DIR}" | 101 rmdir "${STATEFUL_DIR}" |
129 echo "Cleaned" | 102 echo "Cleaned" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 trap - INT TERM EXIT | 141 trap - INT TERM EXIT |
169 rmdir "${STATEFUL_DIR}" | 142 rmdir "${STATEFUL_DIR}" |
170 else | 143 else |
171 echo "/usr/local/autotest under ${DEFAULT_CHROOT_DIR} is not installed." | 144 echo "/usr/local/autotest under ${DEFAULT_CHROOT_DIR} is not installed." |
172 echo "Please call build_autotest.sh inside chroot first." | 145 echo "Please call build_autotest.sh inside chroot first." |
173 exit -1 | 146 exit -1 |
174 fi | 147 fi |
175 fi | 148 fi |
176 | 149 |
177 | 150 |
| 151 # If we're asked to modify the image for test, then let's make a copy and |
| 152 # modify that instead. |
| 153 if [ ${FLAGS_test_image} -eq ${FLAGS_TRUE} ] ; then |
| 154 if [ ! -f "${FLAGS_from}/chromiumos_test_image.bin" ] || \ |
| 155 [ ${FLAGS_force_copy} -eq ${FLAGS_TRUE} ] ; then |
| 156 # Copy it. |
| 157 echo "Creating test image from original..." |
| 158 cp -f "${SRC_IMAGE}" "${FLAGS_from}/chromiumos_test_image.bin" |
| 159 |
| 160 # Check for manufacturing image. |
| 161 if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ] ; then |
| 162 FACTORY_ARGS="--factory" |
| 163 fi |
| 164 |
| 165 # Modify it. Pass --yes so that mod_image_for_test.sh won't ask us if we |
| 166 # really want to modify the image; the user gave their assent already with |
| 167 # --test-image and the original image is going to be preserved. |
| 168 "${SCRIPTS_DIR}/mod_image_for_test.sh" --image \ |
| 169 "${FLAGS_from}/chromiumos_test_image.bin" ${FACTORY_ARGS} --yes |
| 170 echo "Done with mod_image_for_test." |
| 171 else |
| 172 echo "Using cached test image." |
| 173 fi |
| 174 SRC_IMAGE="${FLAGS_from}/chromiumos_test_image.bin" |
| 175 echo "Source test image is: ${SRC_IMAGE}" |
| 176 fi |
| 177 |
| 178 |
178 # Let's do it. | 179 # Let's do it. |
179 if [ -b "${FLAGS_to}" ] | 180 if [ -b "${FLAGS_to}" ] |
180 then | 181 then |
181 # Output to a block device (i.e., a real USB key), so need sudo dd | 182 # Output to a block device (i.e., a real USB key), so need sudo dd |
182 echo "Copying USB image ${SRC_IMAGE} to device ${FLAGS_to}..." | 183 echo "Copying USB image ${SRC_IMAGE} to device ${FLAGS_to}..." |
183 | 184 |
184 # Warn if it looks like they supplied a partition as the destination. | 185 # Warn if it looks like they supplied a partition as the destination. |
185 if echo "${FLAGS_to}" | grep -q '[0-9]$'; then | 186 if echo "${FLAGS_to}" | grep -q '[0-9]$'; then |
186 drive=$(echo "${FLAGS_to}" | sed -re 's/[0-9]+$//') | 187 drive=$(echo "${FLAGS_to}" | sed -re 's/[0-9]+$//') |
187 if [ -b "${drive}" ]; then | 188 if [ -b "${drive}" ]; then |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 echo " sudo dd if=${FLAGS_to} of=/dev/sdX bs=4M" | 228 echo " sudo dd if=${FLAGS_to} of=/dev/sdX bs=4M" |
228 echo "where /dev/sdX is the entire drive." | 229 echo "where /dev/sdX is the entire drive." |
229 if [ ${INSIDE_CHROOT} -eq 1 ] | 230 if [ ${INSIDE_CHROOT} -eq 1 ] |
230 then | 231 then |
231 example=$(basename "${FLAGS_to}") | 232 example=$(basename "${FLAGS_to}") |
232 echo "NOTE: Since you are currently inside the chroot, and you'll need to" | 233 echo "NOTE: Since you are currently inside the chroot, and you'll need to" |
233 echo "run dd outside the chroot, the path to the USB image will be" | 234 echo "run dd outside the chroot, the path to the USB image will be" |
234 echo "different (ex: ~/chromeos/trunk/src/build/images/SOME_DIR/$example)." | 235 echo "different (ex: ~/chromeos/trunk/src/build/images/SOME_DIR/$example)." |
235 fi | 236 fi |
236 fi | 237 fi |
OLD | NEW |