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 build a bootable keyfob-based chromeos system image from within | 7 # Script to build a bootable keyfob-based chromeos system image from within |
8 # a chromiumos setup. This assumes that all needed packages have been built into | 8 # a chromiumos setup. This assumes that all needed packages have been built into |
9 # the given target's root with binary packages turned on. This script will | 9 # the given target's root with binary packages turned on. This script will |
10 # build the Chrome OS image using only pre-built binary packages. | 10 # build the Chrome OS image using only pre-built binary packages. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 echo "Use --build_attempt option to specify an unused attempt." | 108 echo "Use --build_attempt option to specify an unused attempt." |
109 echo "Or use --replace if you want to overwrite this directory." | 109 echo "Or use --replace if you want to overwrite this directory." |
110 exit 1 | 110 exit 1 |
111 fi | 111 fi |
112 fi | 112 fi |
113 | 113 |
114 # Create the output directory. | 114 # Create the output directory. |
115 mkdir -p "$OUTPUT_DIR" | 115 mkdir -p "$OUTPUT_DIR" |
116 | 116 |
117 cleanup_rootfs_loop() { | 117 cleanup_rootfs_loop() { |
118 sudo umount "$LOOP_DEV" | 118 sudo umount -d "$ROOT_FS_DIR" |
119 sleep 1 # in case $LOOP_DEV is in use. | |
120 sudo losetup -d "$LOOP_DEV" | |
121 } | 119 } |
122 | 120 |
123 cleanup_stateful_fs_loop() { | 121 cleanup_stateful_fs_loop() { |
124 sudo umount "${ROOT_FS_DIR}/usr/local" | 122 sudo umount "${ROOT_FS_DIR}/usr/local" |
125 sudo umount "${ROOT_FS_DIR}/var" | 123 sudo umount "${ROOT_FS_DIR}/var" |
126 sudo umount "${STATEFUL_DIR}" | 124 sudo umount -d "${STATEFUL_DIR}" |
127 sleep 1 # follows from cleanup_root_fs_loop. | |
128 sudo losetup -d "$STATEFUL_LOOP_DEV" | |
129 } | 125 } |
130 | 126 |
131 cleanup_esp_loop() { | 127 cleanup_esp_loop() { |
132 sudo umount "$ESP_DIR" | 128 sudo umount -d "$ESP_DIR" |
133 sleep 1 | |
134 sudo losetup -d "$ESP_LOOP_DEV" | |
135 } | 129 } |
136 | 130 |
137 cleanup() { | 131 cleanup() { |
138 # Disable die on error. | 132 # Disable die on error. |
139 set +e | 133 set +e |
140 | 134 |
141 if [[ -n "$STATEFUL_LOOP_DEV" ]]; then | 135 if [[ -n "$STATEFUL_LOOP_DEV" ]]; then |
142 cleanup_stateful_fs_loop | 136 cleanup_stateful_fs_loop |
143 fi | 137 fi |
144 | 138 |
145 if [[ -n "$LOOP_DEV" ]]; then | 139 if [[ -n "$LOOP_DEV" ]]; then |
146 cleanup_rootfs_loop | 140 cleanup_rootfs_loop |
147 fi | 141 fi |
148 | 142 |
149 if [[ -n "$ESP_LOOP_DEV" ]]; then | 143 if [[ -n "$ESP_LOOP_DEV" ]]; then |
150 cleanup_esp_loop | 144 cleanup_esp_loop |
151 fi | 145 fi |
152 | 146 |
153 # Turn die on error back on. | 147 # Turn die on error back on. |
154 set -e | 148 set -e |
155 } | 149 } |
156 | 150 |
| 151 delete_prompt() { |
| 152 echo "An error occurred in your build so your latest output directory" \ |
| 153 "is invalid." |
| 154 read -p "Would you like to delete the output directory (y/N)? " SURE |
| 155 SURE="${SURE:0:1}" # Get just the first character |
| 156 if [ "${SURE}" == "y" ] ; then |
| 157 sudo rm -rf "$OUTPUT_DIR" |
| 158 echo "Deleted $OUTPUT_DIR" |
| 159 else |
| 160 echo "Not deleting $OUTPUT_DIR. Note dev server updates will not work" \ |
| 161 "until you successfully build another image or delete this directory" |
| 162 fi |
| 163 } |
| 164 |
157 # ${DEV_IMAGE_ROOT} specifies the location of where developer packages will | 165 # ${DEV_IMAGE_ROOT} specifies the location of where developer packages will |
158 # be installed on the stateful dir. On a Chromium OS system, this will | 166 # be installed on the stateful dir. On a Chromium OS system, this will |
159 # translate to /usr/local | 167 # translate to /usr/local |
160 DEV_IMAGE_ROOT= | 168 DEV_IMAGE_ROOT= |
161 | 169 |
162 # Sets up symlinks for the stateful partition based on the root specified by | 170 # Sets up symlinks for the stateful partition based on the root specified by |
163 # ${1} and var directory specified by ${2}. | 171 # ${1} and var directory specified by ${2}. |
164 setup_symlinks_on_root() { | 172 setup_symlinks_on_root() { |
165 echo "Setting up symlinks on the stateful partition rooted at ${1} with"\ | 173 echo "Setting up symlinks on the stateful partition rooted at ${1} with"\ |
166 "var directory located at ${2}" | 174 "var directory located at ${2}" |
(...skipping 13 matching lines...) Expand all Loading... |
180 if [ -h "${DEV_IMAGE_ROOT}/var" ] ; then | 188 if [ -h "${DEV_IMAGE_ROOT}/var" ] ; then |
181 sudo unlink "${DEV_IMAGE_ROOT}/var" | 189 sudo unlink "${DEV_IMAGE_ROOT}/var" |
182 elif [ -e "${DEV_IMAGE_ROOT}/var" ] ; then | 190 elif [ -e "${DEV_IMAGE_ROOT}/var" ] ; then |
183 echo "*** ERROR: ${DEV_IMAGE_ROOT}/var should be a symlink if it exists" | 191 echo "*** ERROR: ${DEV_IMAGE_ROOT}/var should be a symlink if it exists" |
184 return 1 | 192 return 1 |
185 fi | 193 fi |
186 | 194 |
187 sudo ln -s "${2}" "${DEV_IMAGE_ROOT}/var" | 195 sudo ln -s "${2}" "${DEV_IMAGE_ROOT}/var" |
188 } | 196 } |
189 | 197 |
190 trap cleanup EXIT | 198 trap "cleanup && delete_prompt" EXIT |
191 | 199 |
192 mkdir -p "$ROOT_FS_DIR" | 200 mkdir -p "$ROOT_FS_DIR" |
193 | 201 |
194 # Create and format the root file system. | 202 # Create and format the root file system. |
195 | 203 |
196 # Check for loop device before creating image. | 204 # Check for loop device before creating image. |
197 LOOP_DEV=$(sudo losetup -f) | 205 LOOP_DEV=$(sudo losetup -f) |
198 if [ -z "$LOOP_DEV" ] ; then | 206 if [ -z "$LOOP_DEV" ] ; then |
199 echo "No free loop device. Free up a loop device or reboot. exiting. " | 207 echo "No free loop device. Free up a loop device or reboot. exiting. " |
200 exit 1 | 208 exit 1 |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 --target="$ARCH" | 429 --target="$ARCH" |
422 | 430 |
423 # Clean up symlinks so they work on a running target rooted at "/". | 431 # Clean up symlinks so they work on a running target rooted at "/". |
424 # Here development packages are rooted at /usr/local. However, do not | 432 # Here development packages are rooted at /usr/local. However, do not |
425 # create /usr/local or /var on host (already exist on target). | 433 # create /usr/local or /var on host (already exist on target). |
426 setup_symlinks_on_root "/usr/local" "/var" | 434 setup_symlinks_on_root "/usr/local" "/var" |
427 | 435 |
428 # Cleanup loop devices. | 436 # Cleanup loop devices. |
429 cleanup | 437 cleanup |
430 | 438 |
| 439 trap delete_prompt EXIT |
| 440 |
431 # Create the GPT-formatted image | 441 # Create the GPT-formatted image |
432 ${SCRIPTS_DIR}/build_gpt.sh \ | 442 ${SCRIPTS_DIR}/build_gpt.sh \ |
433 --arch=${ARCH} --board=${FLAGS_board} "${OUTPUT_DIR}" "${OUTPUT_IMG}" | 443 --arch=${ARCH} --board=${FLAGS_board} "${OUTPUT_DIR}" "${OUTPUT_IMG}" |
434 | 444 |
435 # Clean up temporary files. | 445 # Clean up temporary files. |
436 rm -f "${ROOT_FS_IMG}" "${STATEFUL_IMG}" "${OUTPUT_DIR}/vmlinuz.image" \ | 446 rm -f "${ROOT_FS_IMG}" "${STATEFUL_IMG}" "${OUTPUT_DIR}/vmlinuz.image" \ |
437 "${ESP_IMG}" | 447 "${ESP_IMG}" |
438 rmdir "${ROOT_FS_DIR}" "${STATEFUL_DIR}" "${ESP_DIR}" | 448 rmdir "${ROOT_FS_DIR}" "${STATEFUL_DIR}" "${ESP_DIR}" |
439 | 449 |
440 OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}" | 450 OUTSIDE_OUTPUT_DIR="../build/images/${FLAGS_board}/${IMAGE_SUBDIR}" |
441 echo "Done. Image created in ${OUTPUT_DIR}" | 451 echo "Done. Image created in ${OUTPUT_DIR}" |
442 echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:" | 452 echo "To copy to USB keyfob, OUTSIDE the chroot, do something like:" |
443 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX" | 453 echo " ./image_to_usb.sh --from=${OUTSIDE_OUTPUT_DIR} --to=/dev/sdX" |
444 echo "To convert to VMWare image, OUTSIDE the chroot, do something like:" | 454 echo "To convert to VMWare image, OUTSIDE the chroot, do something like:" |
445 echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}" | 455 echo " ./image_to_vmware.sh --from=${OUTSIDE_OUTPUT_DIR}" |
446 echo "from the scripts directory where you entered the chroot." | 456 echo "from the scripts directory where you entered the chroot." |
447 | 457 |
448 trap - EXIT | 458 trap - EXIT |
OLD | NEW |