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

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

Issue 1567013: Clean up temporary files and directories left by build_image, etc. (Closed)
Patch Set: Emit scripts to pack/unpack the image. Created 10 years, 8 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
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.
11 . "$(dirname "$0")/common.sh" 11 . "$(dirname "$0")/common.sh"
12 12
13 # Load functions and constants for chromeos-install 13 # Load functions and constants for chromeos-install
14 . "$(dirname "$0")/chromeos-common.sh" 14 . "$(dirname "$0")/chromeos-common.sh"
15 15
16 get_default_board 16 get_default_board
17 17
18 # Flags 18 # Flags
19 DEFINE_string board "${DEFAULT_BOARD}" "Board for which the image was built" 19 DEFINE_string board "${DEFAULT_BOARD}" "Board for which the image was built"
20 DEFINE_string from "" \ 20 DEFINE_string from "" \
21 "Directory containing rootfs.image and mbr.image" 21 "Directory containing chromiumos_image.bin"
22 DEFINE_string to "" "${DEFAULT_TO_HELP}" 22 DEFINE_string to "" "${DEFAULT_TO_HELP}"
23 DEFINE_boolean yes ${FLAGS_FALSE} "Answer yes to all prompts" "y" 23 DEFINE_boolean yes ${FLAGS_FALSE} "Answer yes to all prompts" "y"
24 DEFINE_boolean install_autotest ${FLAGS_FALSE} \ 24 DEFINE_boolean install_autotest ${FLAGS_FALSE} \
25 "Whether to install autotest to the stateful partition." 25 "Whether to install autotest to the stateful partition."
26 DEFINE_boolean copy_kernel ${FLAGS_FALSE} \ 26 DEFINE_boolean copy_kernel ${FLAGS_FALSE} \
27 "Copy the kernel to the fourth partition." 27 "Copy the kernel to the fourth partition."
28 DEFINE_boolean test_image "${FLAGS_FALSE}" \ 28 DEFINE_boolean test_image "${FLAGS_FALSE}" \
29 "Uses test image if available, otherwise creates one as rootfs_test.image." 29 "Copies normal image to chromiumos_test_image.bin, modifies it for test."
30 DEFINE_string build_root "/build" \ 30 DEFINE_string build_root "/build" \
31 "The root location for board sysroots." 31 "The root location for board sysroots."
32 32
33 # Parse command line 33 # Parse command line
34 FLAGS "$@" || exit 1 34 FLAGS "$@" || exit 1
35 eval set -- "${FLAGS_ARGV}" 35 eval set -- "${FLAGS_ARGV}"
36 36
37 # Inside the chroot, so output to usb.img in the same dir as the other 37 # Inside the chroot, so output to usb.img in the same dir as the other
38 # Script can be run either inside or outside the chroot. 38 # Script can be run either inside or outside the chroot.
39 if [ ${INSIDE_CHROOT} -eq 1 ] 39 if [ ${INSIDE_CHROOT} -eq 1 ]
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 # Copy it. 93 # Copy it.
94 echo "Creating test image from original..." 94 echo "Creating test image from original..."
95 cp -f "${SRC_IMAGE}" "${FLAGS_from}/chromiumos_test_image.bin" 95 cp -f "${SRC_IMAGE}" "${FLAGS_from}/chromiumos_test_image.bin"
96 # Use it. 96 # Use it.
97 SRC_IMAGE="${FLAGS_from}/chromiumos_test_image.bin" 97 SRC_IMAGE="${FLAGS_from}/chromiumos_test_image.bin"
98 # Modify it. 98 # Modify it.
99 "${SCRIPTS_DIR}/mod_image_for_test.sh" --image "${SRC_IMAGE}" 99 "${SCRIPTS_DIR}/mod_image_for_test.sh" --image "${SRC_IMAGE}"
100 fi 100 fi
101 101
102 STATEFUL_DIR="${FLAGS_from}/stateful_partition" 102 STATEFUL_DIR="${FLAGS_from}/stateful_partition"
103 mkdir -p "${STATEFUL_DIR}"
103 104
104 function do_cleanup { 105 function do_cleanup {
105 echo "Cleaning loopback devices: ${STATEFUL_LOOP_DEV}" 106 echo "Cleaning loopback devices: ${STATEFUL_LOOP_DEV}"
106 if [ "${STATEFUL_LOOP_DEV}" != "" ]; then 107 if [ "${STATEFUL_LOOP_DEV}" != "" ]; then
107 sudo umount "${STATEFUL_DIR}" 108 sudo umount "${STATEFUL_DIR}"
108 sudo losetup -d "${STATEFUL_LOOP_DEV}" 109 sudo losetup -d "${STATEFUL_LOOP_DEV}"
110 rmdir "${STATEFUL_DIR}"
109 echo "Cleaned" 111 echo "Cleaned"
110 fi 112 fi
111 } 113 }
112 114
113 if [ ${FLAGS_install_autotest} -eq ${FLAGS_TRUE} ] ; then 115 if [ ${FLAGS_install_autotest} -eq ${FLAGS_TRUE} ] ; then
114 echo "Detecting autotest at ${AUTOTEST_SRC}" 116 echo "Detecting autotest at ${AUTOTEST_SRC}"
115 if [ -d ${AUTOTEST_SRC} ] 117 if [ -d ${AUTOTEST_SRC} ]
116 then 118 then
117 # Figure out how to loop mount the stateful partition. It's always 119 # Figure out how to loop mount the stateful partition. It's always
118 # partition 1 on the disk image. 120 # partition 1 on the disk image.
(...skipping 18 matching lines...) Expand all
137 sudo mkdir -p "${stateful_root}${autotest_client}" 139 sudo mkdir -p "${stateful_root}${autotest_client}"
138 140
139 sudo cp -fpru ${AUTOTEST_SRC}/client/* \ 141 sudo cp -fpru ${AUTOTEST_SRC}/client/* \
140 "${stateful_root}/${autotest_client}" 142 "${stateful_root}/${autotest_client}"
141 sudo chmod 755 "${stateful_root}/${autotest_client}" 143 sudo chmod 755 "${stateful_root}/${autotest_client}"
142 sudo chown -R 1000:1000 "${stateful_root}/${autotest_client}" 144 sudo chown -R 1000:1000 "${stateful_root}/${autotest_client}"
143 145
144 sudo umount ${STATEFUL_DIR} 146 sudo umount ${STATEFUL_DIR}
145 sudo losetup -d "${stateful_loop_dev}" 147 sudo losetup -d "${stateful_loop_dev}"
146 trap - INT TERM EXIT 148 trap - INT TERM EXIT
149 rmdir "${STATEFUL_DIR}"
147 else 150 else
148 echo "/usr/local/autotest under ${DEFAULT_CHROOT_DIR} is not installed." 151 echo "/usr/local/autotest under ${DEFAULT_CHROOT_DIR} is not installed."
149 echo "Please call make_autotest.sh inside chroot first." 152 echo "Please call make_autotest.sh inside chroot first."
150 exit -1 153 exit -1
151 fi 154 fi
152 fi 155 fi
153 156
154 157
155 # Let's do it. 158 # Let's do it.
156 if [ -b "${FLAGS_to}" ] 159 if [ -b "${FLAGS_to}" ]
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 echo " sudo dd if=${FLAGS_to} of=/dev/sdb bs=4M" 207 echo " sudo dd if=${FLAGS_to} of=/dev/sdb bs=4M"
205 echo "where /dev/sdb is the entire keyfob." 208 echo "where /dev/sdb is the entire keyfob."
206 if [ ${INSIDE_CHROOT} -eq 1 ] 209 if [ ${INSIDE_CHROOT} -eq 1 ]
207 then 210 then
208 example=$(basename "${FLAGS_to}") 211 example=$(basename "${FLAGS_to}")
209 echo "NOTE: Since you are currently inside the chroot, and you'll need to" 212 echo "NOTE: Since you are currently inside the chroot, and you'll need to"
210 echo "run dd outside the chroot, the path to the USB image will be" 213 echo "run dd outside the chroot, the path to the USB image will be"
211 echo "different (ex: ~/chromeos/trunk/src/build/images/SOME_DIR/$example)." 214 echo "different (ex: ~/chromeos/trunk/src/build/images/SOME_DIR/$example)."
212 fi 215 fi
213 fi 216 fi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698