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

Side by Side Diff: mod_image_for_test.sh

Issue 5271010: Factored out the code to copy an image and modify it for test (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/crosutils.git@master
Patch Set: Final upload to check before push Created 9 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « image_to_vm.sh ('k') | 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 modify a keyfob-based chromeos system image for testability. 7 # Script to modify a keyfob-based chromeos system image for testability.
8 8
9 # --- BEGIN COMMON.SH BOILERPLATE --- 9 # --- BEGIN COMMON.SH BOILERPLATE ---
10 # Load common CrOS utilities. Inside the chroot this file is installed in 10 # Load common CrOS utilities. Inside the chroot this file is installed in
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 DEFINE_string image "" "Location of the rootfs raw image file" i 44 DEFINE_string image "" "Location of the rootfs raw image file" i
45 DEFINE_boolean installmask $FLAGS_TRUE \ 45 DEFINE_boolean installmask $FLAGS_TRUE \
46 "Use INSTALL_MASK to shrink the resulting image." m 46 "Use INSTALL_MASK to shrink the resulting image." m
47 DEFINE_integer jobs -1 \ 47 DEFINE_integer jobs -1 \
48 "How many packages to build in parallel at maximum." j 48 "How many packages to build in parallel at maximum." j
49 DEFINE_string qualdb "" "Location of qualified component file" d 49 DEFINE_string qualdb "" "Location of qualified component file" d
50 DEFINE_boolean yes $FLAGS_FALSE "Answer yes to all prompts" y 50 DEFINE_boolean yes $FLAGS_FALSE "Answer yes to all prompts" y
51 DEFINE_string build_root "/build" \ 51 DEFINE_string build_root "/build" \
52 "The root location for board sysroots." 52 "The root location for board sysroots."
53 DEFINE_boolean fast ${DEFAULT_FAST} "Call many emerges in parallel" 53 DEFINE_boolean fast ${DEFAULT_FAST} "Call many emerges in parallel"
54 DEFINE_boolean inplace $FLAGS_TRUE \
55 "Modify/overwrite the image ${CHROMEOS_IMAGE_NAME} in place. \
56 Otherwise the image will be copied to ${CHROMEOS_TEST_IMAGE_NAME} \
57 if needed, and modified there"
58 DEFINE_boolean force_copy ${FLAGS_FALSE} \
59 "Always rebuild test image if --noinplace"
54 60
55 61
56 # Parse command line 62 # Parse command line
57 FLAGS "$@" || exit 1 63 FLAGS "$@" || exit 1
58 eval set -- "${FLAGS_ARGV}" 64 eval set -- "${FLAGS_ARGV}"
59 65
60 EMERGE_CMD="emerge" 66 EMERGE_CMD="emerge"
61 EMERGE_BOARD_CMD="emerge-${FLAGS_board}" 67 EMERGE_BOARD_CMD="emerge-${FLAGS_board}"
62 if [ "${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]; then 68 if [ "${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]; then
63 echo "Using alternate emerge" 69 echo "Using alternate emerge"
64 EMERGE_CMD="${SCRIPTS_DIR}/parallel_emerge" 70 EMERGE_CMD="${SCRIPTS_DIR}/parallel_emerge"
65 EMERGE_BOARD_CMD="${EMERGE_CMD} --board=${FLAGS_board}" 71 EMERGE_BOARD_CMD="${EMERGE_CMD} --board=${FLAGS_board}"
66 fi 72 fi
67 73
68 # No board, no default and no image set then we can't find the image 74 # No board, no default and no image set then we can't find the image
69 if [ -z $FLAGS_image ] && [ -z $FLAGS_board ] ; then 75 if [ -z $FLAGS_image ] && [ -z $FLAGS_board ] ; then
70 setup_board_warning 76 setup_board_warning
71 die "mod_image_for_test failed. No board set and no image set" 77 die "mod_image_for_test failed. No board set and no image set"
72 fi 78 fi
73 79
74 # We have a board name but no image set. Use image at default location 80 # We have a board name but no image set. Use image at default location
75 if [ -z $FLAGS_image ] ; then 81 if [ -z $FLAGS_image ] ; then
76 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" 82 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}"
77 FILENAME="chromiumos_image.bin" 83 FILENAME="${CHROMEOS_IMAGE_NAME}"
78 FLAGS_image="${IMAGES_DIR}/$(ls -t $IMAGES_DIR 2>&-| head -1)/${FILENAME}" 84 FLAGS_image="${IMAGES_DIR}/$(ls -t $IMAGES_DIR 2>&-| head -1)/${FILENAME}"
79 fi 85 fi
80 86
81 # Turn path into an absolute path. 87 # Turn path into an absolute path.
82 FLAGS_image=`eval readlink -f ${FLAGS_image}` 88 FLAGS_image=`eval readlink -f ${FLAGS_image}`
83 89
84 # Abort early if we can't find the image 90 # Abort early if we can't find the image
85 if [ ! -f $FLAGS_image ] ; then 91 if [ ! -f $FLAGS_image ] ; then
86 echo "No image found at $FLAGS_image" 92 echo "No image found at $FLAGS_image"
87 exit 1 93 exit 1
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 --exclude=site_tests/desktopui_UITest \ 171 --exclude=site_tests/desktopui_UITest \
166 --exclude=.svn \ 172 --exclude=.svn \
167 ${AUTOTEST_SRC}/client/* "${stateful_root}/${autotest_client}" 173 ${AUTOTEST_SRC}/client/* "${stateful_root}/${autotest_client}"
168 174
169 sudo chmod 755 "${stateful_root}/${autotest_client}" 175 sudo chmod 755 "${stateful_root}/${autotest_client}"
170 sudo chown -R 1000:1000 "${stateful_root}/${autotest_client}" 176 sudo chown -R 1000:1000 "${stateful_root}/${autotest_client}"
171 } 177 }
172 178
173 # main process begins here. 179 # main process begins here.
174 180
181 IMAGE_DIR="$(dirname "${FLAGS_image}")"
182
183 # Copy the image to a test location if required
184 if [ ${FLAGS_inplace} -eq ${FLAGS_FALSE} ]; then
185 TEST_PATHNAME="${IMAGE_DIR}/${CHROMEOS_TEST_IMAGE_NAME}"
186 if [ ! -f "${TEST_PATHNAME}" ] || \
187 [ ${FLAGS_force_copy} -eq ${FLAGS_TRUE} ] ; then
188 echo "Creating test image from original..."
189 ${COMMON_PV_CAT} "${FLAGS_image}" >"${TEST_PATHNAME}" \
190 || die "Cannot copy ${FLAGS_image} to test image"
191 FLAGS_image="${TEST_PATHNAME}"
192 else
193 echo "Using cached test image"
194 exit
195 fi
196
197 # No need to confirm now, since we are not overwriting the main image
198 FLAGS_yes="$FLAGS_TRUE"
199 fi
200
175 # Make sure this is really what the user wants, before nuking the device 201 # Make sure this is really what the user wants, before nuking the device
176 if [ $FLAGS_yes -ne $FLAGS_TRUE ]; then 202 if [ $FLAGS_yes -ne $FLAGS_TRUE ]; then
177 read -p "Modifying image ${FLAGS_image} for test; are you sure (y/N)? " SURE 203 read -p "Modifying image ${FLAGS_image} for test; are you sure (y/N)? " SURE
178 SURE="${SURE:0:1}" # Get just the first character 204 SURE="${SURE:0:1}" # Get just the first character
179 if [ "$SURE" != "y" ]; then 205 if [ "$SURE" != "y" ]; then
180 echo "Ok, better safe than sorry." 206 echo "Ok, better safe than sorry."
181 exit 1 207 exit 1
182 fi 208 fi
183 else 209 else
184 echo "Modifying image ${FLAGS_image} for test..." 210 echo "Modifying image ${FLAGS_image} for test..."
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 cleanup 274 cleanup
249 275
250 # Now make it bootable with the flags from build_image 276 # Now make it bootable with the flags from build_image
251 "${SCRIPTS_DIR}/bin/cros_make_image_bootable" "$(dirname "${FLAGS_image}")" \ 277 "${SCRIPTS_DIR}/bin/cros_make_image_bootable" "$(dirname "${FLAGS_image}")" \
252 $(basename "${FLAGS_image}") 278 $(basename "${FLAGS_image}")
253 279
254 print_time_elapsed 280 print_time_elapsed
255 281
256 trap - EXIT 282 trap - EXIT
257 283
OLDNEW
« no previous file with comments | « image_to_vm.sh ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698