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

Side by Side Diff: mod_image_for_test.sh

Issue 6713049: Fix numerous style nits and inconsistencies in mod_image_for_test.sh (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/crosutils.git@master
Patch Set: More nit fixes for consistency Created 9 years, 9 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 | « 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) 2011 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
11 # /usr/lib/crosutils. Outside the chroot we find it relative to the script's 11 # /usr/lib/crosutils. Outside the chroot we find it relative to the script's
12 # location. 12 # location.
13 find_common_sh() { 13 find_common_sh() {
(...skipping 27 matching lines...) Expand all
41 "Modify the image for manufacturing testing" f 41 "Modify the image for manufacturing testing" f
42 DEFINE_string image "" "Location of the rootfs raw image file" i 42 DEFINE_string image "" "Location of the rootfs raw image file" i
43 DEFINE_boolean installmask $FLAGS_TRUE \ 43 DEFINE_boolean installmask $FLAGS_TRUE \
44 "Use INSTALL_MASK to shrink the resulting image." m 44 "Use INSTALL_MASK to shrink the resulting image." m
45 DEFINE_integer jobs -1 \ 45 DEFINE_integer jobs -1 \
46 "How many packages to build in parallel at maximum." j 46 "How many packages to build in parallel at maximum." j
47 DEFINE_string qualdb "" "Location of qualified component file" d 47 DEFINE_string qualdb "" "Location of qualified component file" d
48 DEFINE_boolean yes $FLAGS_FALSE "Answer yes to all prompts" y 48 DEFINE_boolean yes $FLAGS_FALSE "Answer yes to all prompts" y
49 DEFINE_string build_root "/build" \ 49 DEFINE_string build_root "/build" \
50 "The root location for board sysroots." 50 "The root location for board sysroots."
51 DEFINE_boolean fast ${DEFAULT_FAST} "Call many emerges in parallel" 51 DEFINE_boolean fast $DEFAULT_FAST "Call many emerges in parallel"
52 DEFINE_boolean inplace $FLAGS_TRUE \ 52 DEFINE_boolean inplace $FLAGS_TRUE \
53 "Modify/overwrite the image ${CHROMEOS_IMAGE_NAME} in place. \ 53 "Modify/overwrite the image $CHROMEOS_IMAGE_NAME in place. \
54 Otherwise the image will be copied to ${CHROMEOS_TEST_IMAGE_NAME} \ 54 Otherwise the image will be copied to $CHROMEOS_TEST_IMAGE_NAME \
55 (or ${CHROMEOS_FACTORY_TEST_IMAGE_NAME} for --factory) if needed, and \ 55 (or $CHROMEOS_FACTORY_TEST_IMAGE_NAME for --factory) if needed, and \
56 modified there" 56 modified there"
57 DEFINE_boolean force_copy ${FLAGS_FALSE} \ 57 DEFINE_boolean force_copy $FLAGS_FALSE \
58 "Always rebuild test image if --noinplace" 58 "Always rebuild test image if --noinplace"
59 59
60 # Parse command line 60 # Parse command line
61 FLAGS "$@" || exit 1 61 FLAGS "$@" || exit 1
62 eval set -- "${FLAGS_ARGV}" 62 eval set -- "$FLAGS_ARGV"
63 63
64 EMERGE_CMD="emerge" 64 EMERGE_CMD="emerge"
65 EMERGE_BOARD_CMD="emerge-${FLAGS_board}" 65 EMERGE_BOARD_CMD="emerge-$FLAGS_board"
66 if [ "${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]; then 66 if [ $FLAGS_fast -eq $FLAGS_TRUE ]; then
67 echo "Using alternate emerge" 67 echo "Using alternate emerge"
68 EMERGE_CMD="${GCLIENT_ROOT}/chromite/bin/parallel_emerge" 68 EMERGE_CMD="$GCLIENT_ROOT/chromite/bin/parallel_emerge"
69 EMERGE_BOARD_CMD="${EMERGE_CMD} --board=${FLAGS_board}" 69 EMERGE_BOARD_CMD="$EMERGE_CMD --board=$FLAGS_board"
70 fi 70 fi
71 71
72 # No board, no default and no image set then we can't find the image 72 # No board, no default and no image set then we can't find the image
73 if [ -z $FLAGS_image ] && [ -z $FLAGS_board ] ; then 73 if [ -z "$FLAGS_image" -a -z "$FLAGS_board" ] ; then
74 setup_board_warning 74 setup_board_warning
75 die "mod_image_for_test failed. No board set and no image set" 75 die "mod_image_for_test failed. No board set and no image set"
76 fi 76 fi
77 77
78 # We have a board name but no image set. Use image at default location 78 # We have a board name but no image set. Use image at default location
79 if [ -z $FLAGS_image ] ; then 79 if [ -z "$FLAGS_image" ] ; then
80 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" 80 IMAGES_DIR="$DEFAULT_BUILD_ROOT/images/$FLAGS_board"
81 FILENAME="${CHROMEOS_IMAGE_NAME}" 81 FILENAME="$CHROMEOS_IMAGE_NAME"
82 FLAGS_image="${IMAGES_DIR}/$(ls -t $IMAGES_DIR 2>&-| head -1)/${FILENAME}" 82 FLAGS_image="$IMAGES_DIR/$(ls -t $IMAGES_DIR 2>&-| head -1)/$FILENAME"
83 fi 83 fi
84 84
85 # Turn path into an absolute path. 85 # Turn path into an absolute path.
86 FLAGS_image=`eval readlink -f ${FLAGS_image}` 86 FLAGS_image=$(eval readlink -f $FLAGS_image)
87 87
88 # What cross-build are we targeting? 88 # What cross-build are we targeting?
89 . "${FLAGS_build_root}/${FLAGS_board}/etc/make.conf.board_setup" 89 . "$FLAGS_build_root/$FLAGS_board/etc/make.conf.board_setup"
90 # Figure out ARCH from the given toolchain. 90 # Figure out ARCH from the given toolchain.
91 # TODO: Move to common.sh as a function after scripts are switched over. 91 # TODO: Move to common.sh as a function after scripts are switched over.
92 TC_ARCH=$(echo "${CHOST}" | awk -F'-' '{ print $1 }') 92 TC_ARCH=$(echo "$CHOST" | awk -F'-' '{ print $1 }')
93 case "${TC_ARCH}" in 93 case "$TC_ARCH" in
94 arm*) 94 arm*)
95 ARCH="arm" 95 ARCH="arm"
96 ;; 96 ;;
97 *86) 97 *86)
98 ARCH="x86" 98 ARCH="x86"
99 ;; 99 ;;
100 *) 100 *)
101 error "Unable to determine ARCH from toolchain: ${CHOST}" 101 error "Unable to determine ARCH from toolchain: $CHOST"
102 exit 1 102 exit 1
103 esac 103 esac
104 104
105 # Make sure anything mounted in the rootfs/stateful is cleaned up ok on exit. 105 # Make sure anything mounted in the rootfs/stateful is cleaned up ok on exit.
106 cleanup_mounts() { 106 cleanup_mounts() {
107 # Occasionally there are some daemons left hanging around that have our 107 # Occasionally there are some daemons left hanging around that have our
108 # root/stateful image file system open. We do a best effort attempt to kill 108 # root/stateful image file system open. We do a best effort attempt to kill
109 # them. 109 # them.
110 PIDS=`sudo lsof -t "$1" | sort | uniq` 110 PIDS=$(sudo lsof -t "$1" | sort | uniq)
111 for pid in ${PIDS}; do 111 for pid in $PIDS; do
112 local cmdline=`cat /proc/$pid/cmdline` 112 local cmdline=$(cat /proc/$pid/cmdline)
113 echo "Killing process that has open file on the mounted directory: $cmdline" 113 echo "Killing process that has open file on the mounted directory: $cmdline"
114 sudo kill $pid || /bin/true 114 sudo kill $pid || true
115 done 115 done
116 } 116 }
117 117
118 cleanup() { 118 cleanup() {
119 "$SCRIPTS_DIR/mount_gpt_image.sh" -u -r "$ROOT_FS_DIR" -s "$STATEFUL_DIR" 119 "$SCRIPTS_DIR/mount_gpt_image.sh" -u -r "$ROOT_FS_DIR" -s "$STATEFUL_DIR"
120 } 120 }
121 121
122 # Emerges chromeos-test onto the image. 122 # Emerges chromeos-test onto the image.
123 emerge_chromeos_test() { 123 emerge_chromeos_test() {
124 INSTALL_MASK="" 124 INSTALL_MASK=""
125 if [[ $FLAGS_installmask -eq ${FLAGS_TRUE} ]]; then 125 if [[ $FLAGS_installmask -eq $FLAGS_TRUE ]]; then
126 INSTALL_MASK="$DEFAULT_INSTALL_MASK" 126 INSTALL_MASK="$DEFAULT_INSTALL_MASK"
127 fi 127 fi
128 128
129 # Determine the root dir for test packages. 129 # Determine the root dir for test packages.
130 ROOT_DEV_DIR="$ROOT_FS_DIR/usr/local" 130 ROOT_DEV_DIR="$ROOT_FS_DIR/usr/local"
131 131
132 sudo INSTALL_MASK="$INSTALL_MASK" $EMERGE_BOARD_CMD \ 132 sudo INSTALL_MASK="$INSTALL_MASK" $EMERGE_BOARD_CMD \
133 --root="$ROOT_DEV_DIR" --root-deps=rdeps \ 133 --root="$ROOT_DEV_DIR" --root-deps=rdeps \
134 --usepkgonly chromeos-test $EMERGE_JOBS 134 --usepkgonly chromeos-test $EMERGE_JOBS
135 } 135 }
136 136
137 137
138 install_autotest() { 138 install_autotest() {
139 SYSROOT="${FLAGS_build_root}/${FLAGS_board}" 139 local autotest_src="$FLAGS_build_root/$FLAGS_board/usr/local/autotest"
140 AUTOTEST_SRC="${SYSROOT}/usr/local/autotest" 140 local stateful_root="$ROOT_FS_DIR/usr/local"
141 stateful_root="${ROOT_FS_DIR}/usr/local" 141 local autotest_client="$stateful_root/autotest"
142 autotest_client="/autotest"
143 142
144 echo "Install autotest into stateful partition from $AUTOTEST_SRC" 143 echo "Install autotest into stateful partition from $AUTOTEST_SRC"
145 144
146 sudo mkdir -p "${stateful_root}${autotest_client}" 145 sudo mkdir -p "$autotest_client"
147 146
148 # Remove excess files from stateful partition. 147 # Remove excess files from stateful partition.
149 # If these aren't there, that's fine. 148 sudo rm -rf "$autotest_client/"*
150 sudo rm -rf "${stateful_root}${autotest_client}/*" || true 149 sudo rm -rf "$stateful_root/autotest-pkgs"
151 sudo rm -rf "${stateful_root}/autotest-pkgs" || true 150 sudo rm -rf "$stateful_root/lib/icedtea6"
152 sudo rm -rf "${stateful_root}/lib/icedtea6" || true
153 151
154 sudo rsync --delete --delete-excluded -auv \ 152 sudo rsync --delete --delete-excluded -auv \
155 --exclude=deps/realtimecomm_playground \ 153 --exclude=deps/realtimecomm_playground \
156 --exclude=tests/ltp \ 154 --exclude=tests/ltp \
157 --exclude=site_tests/graphics_O3DSelenium \ 155 --exclude=site_tests/graphics_O3DSelenium \
158 --exclude=site_tests/realtimecomm_GTalk\* \ 156 --exclude=site_tests/realtimecomm_GTalk\* \
159 --exclude=site_tests/platform_StackProtector \ 157 --exclude=site_tests/platform_StackProtector \
160 --exclude=deps/chrome_test \ 158 --exclude=deps/chrome_test \
161 --exclude=site_tests/desktopui_BrowserTest \ 159 --exclude=site_tests/desktopui_BrowserTest \
162 --exclude=site_tests/desktopui_PageCyclerTests \ 160 --exclude=site_tests/desktopui_PageCyclerTests \
163 --exclude=site_tests/desktopui_UITest \ 161 --exclude=site_tests/desktopui_UITest \
164 --exclude=.svn \ 162 --exclude=.svn \
165 ${AUTOTEST_SRC}/client/* "${stateful_root}/${autotest_client}" 163 "$autotest_src/client/"* "$autotest_client"
166 164
167 sudo chmod 755 "${stateful_root}/${autotest_client}" 165 sudo chmod 755 "$autotest_client"
168 sudo chown -R 1000:1000 "${stateful_root}/${autotest_client}" 166 sudo chown -R 1000:1000 "$autotest_client"
169 } 167 }
170 168
171 # main process begins here. 169 # main process begins here.
172 170
173 IMAGE_DIR="$(dirname "${FLAGS_image}")" 171 IMAGE_DIR=$(dirname "$FLAGS_image")
174 172
175 # Copy the image to a test location if required 173 # Copy the image to a test location if required
176 if [ ${FLAGS_inplace} -eq ${FLAGS_FALSE} ]; then 174 if [ $FLAGS_inplace -eq $FLAGS_FALSE ]; then
177 if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ]; then 175 if [ $FLAGS_factory -eq $FLAGS_TRUE ]; then
178 TEST_PATHNAME="${IMAGE_DIR}/${CHROMEOS_FACTORY_TEST_IMAGE_NAME}" 176 TEST_PATHNAME="$IMAGE_DIR/$CHROMEOS_FACTORY_TEST_IMAGE_NAME"
179 typename="factory" 177 typename="factory"
180 else 178 else
181 TEST_PATHNAME="${IMAGE_DIR}/${CHROMEOS_TEST_IMAGE_NAME}" 179 TEST_PATHNAME="$IMAGE_DIR/$CHROMEOS_TEST_IMAGE_NAME"
182 typename="test" 180 typename="test"
183 fi 181 fi
184 if [ ! -f "${TEST_PATHNAME}" ] || \ 182 if [ ! -f "$TEST_PATHNAME" -o $FLAGS_force_copy -eq $FLAGS_TRUE ] ; then
185 [ ${FLAGS_force_copy} -eq ${FLAGS_TRUE} ] ; then
186 echo "Creating test image from original..." 183 echo "Creating test image from original..."
187 ${COMMON_PV_CAT} "${FLAGS_image}" >"${TEST_PATHNAME}" \ 184 $COMMON_PV_CAT "$FLAGS_image" >"$TEST_PATHNAME" ||
188 || die "Cannot copy ${FLAGS_image} to test image" 185 die "Cannot copy $FLAGS_image to test image"
189 FLAGS_image="${TEST_PATHNAME}" 186 FLAGS_image="$TEST_PATHNAME"
190 else 187 else
191 echo "Using cached ${typename} image" 188 echo "Using cached $typename image"
192 exit 189 exit
193 fi 190 fi
194 191
195 # No need to confirm now, since we are not overwriting the main image 192 # No need to confirm now, since we are not overwriting the main image
196 FLAGS_yes="$FLAGS_TRUE" 193 FLAGS_yes="$FLAGS_TRUE"
197 fi 194 fi
198 195
199 # Make sure this is really what the user wants, before nuking the device 196 # Make sure this is really what the user wants, before nuking the device
200 if [ $FLAGS_yes -ne $FLAGS_TRUE ]; then 197 if [ $FLAGS_yes -ne $FLAGS_TRUE ]; then
201 read -p "Modifying image ${FLAGS_image} for test; are you sure (y/N)? " SURE 198 read -p "Modifying image $FLAGS_image for test; are you sure (y/N)? " SURE
202 SURE="${SURE:0:1}" # Get just the first character 199 SURE="${SURE:0:1}" # Get just the first character
203 if [ "$SURE" != "y" ]; then 200 if [ "$SURE" != "y" ]; then
204 echo "Ok, better safe than sorry." 201 echo "Ok, better safe than sorry."
205 exit 1 202 exit 1
206 fi 203 fi
207 else 204 else
208 echo "Modifying image ${FLAGS_image} for test..." 205 echo "Modifying image $FLAGS_image for test..."
209 fi 206 fi
210 207
211 # Abort early if we can't find the image 208 # Abort early if we can't find the image
212 if [ ! -f $FLAGS_image ] && [ ${FLAGS_inplace} -eq ${FLAGS_TRUE} ; then 209 if [ ! -f $FLAGS_image -a $FLAGS_inplace -eq $FLAGS_TRUE ] ; then
213 die "No image found at $FLAGS_image to modify" 210 die "No image found at $FLAGS_image to modify"
214 fi 211 fi
215 212
216 set -e 213 set -e
217 214
218 IMAGE_DIR=$(dirname "$FLAGS_image") 215 IMAGE_DIR=$(dirname "$FLAGS_image")
219 IMAGE_NAME="$(basename "$FLAGS_image")" 216 IMAGE_NAME=$(basename "$FLAGS_image")
220 ROOT_FS_DIR="$IMAGE_DIR/rootfs" 217 ROOT_FS_DIR="$IMAGE_DIR/rootfs"
221 STATEFUL_DIR="$IMAGE_DIR/stateful_partition" 218 STATEFUL_DIR="$IMAGE_DIR/stateful_partition"
222 219
223 trap cleanup EXIT 220 trap cleanup EXIT
224 221
225 # Mounts gpt image and sets up var, /usr/local and symlinks. 222 # Mounts gpt image and sets up var, /usr/local and symlinks.
226 "$SCRIPTS_DIR/mount_gpt_image.sh" -i "$IMAGE_NAME" -f "$IMAGE_DIR" \ 223 "$SCRIPTS_DIR/mount_gpt_image.sh" -i "$IMAGE_NAME" -f "$IMAGE_DIR" \
227 -r "$ROOT_FS_DIR" -s "$STATEFUL_DIR" 224 -r "$ROOT_FS_DIR" -s "$STATEFUL_DIR"
228 225
229 emerge_chromeos_test 226 emerge_chromeos_test
230 227
231 MOD_TEST_ROOT="${GCLIENT_ROOT}/src/scripts/mod_for_test_scripts" 228 MOD_TEST_SCRIPT="$SCRIPTS_DIR/mod_for_test_scripts/test_setup.sh"
232 # Run test setup script to modify the image 229 # Run test setup script to modify the image
233 sudo GCLIENT_ROOT="${GCLIENT_ROOT}" ROOT_FS_DIR="${ROOT_FS_DIR}" \ 230 sudo GCLIENT_ROOT="$GCLIENT_ROOT" ROOT_FS_DIR="$ROOT_FS_DIR" \
234 STATEFUL_DIR="${STATEFUL_DIR}" ARCH="${ARCH}" "${MOD_TEST_ROOT}/test_setup.s h" 231 STATEFUL_DIR="$STATEFUL_DIR" ARCH="$ARCH" "$MOD_TEST_SCRIPT"
235 232
236 if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ]; then 233 if [ $FLAGS_factory -eq $FLAGS_TRUE ]; then
237 install_autotest 234 install_autotest
238 235
239 MOD_FACTORY_ROOT="${GCLIENT_ROOT}/src/scripts/mod_for_factory_scripts" 236 MOD_FACTORY_SCRIPT="$SCRIPTS_DIR/mod_for_factory_scripts/factory_setup.sh"
240 # Run factory setup script to modify the image 237 # Run factory setup script to modify the image
241 sudo GCLIENT_ROOT="${GCLIENT_ROOT}" ROOT_FS_DIR="${ROOT_FS_DIR}" \ 238 sudo GCLIENT_ROOT="$GCLIENT_ROOT" ROOT_FS_DIR="$ROOT_FS_DIR" \
242 QUALDB="${FLAGS_qualdb}" BOARD=${FLAGS_board} \ 239 QUALDB="$FLAGS_qualdb" BOARD=$FLAGS_board "$MOD_FACTORY_SCRIPT"
243 "${MOD_FACTORY_ROOT}/factory_setup.sh"
244 fi 240 fi
245 241
246 # Re-run ldconfig to fix /etc/ldconfig.so.cache. 242 # Re-run ldconfig to fix /etc/ldconfig.so.cache.
247 sudo /sbin/ldconfig -r "${ROOT_FS_DIR}" 243 sudo ldconfig -r "$ROOT_FS_DIR"
248 244
249 # Let's have a look at the image just in case.. 245 # Let's have a look at the image just in case..
250 if [ "${VERIFY}" = "true" ]; then 246 if [ "$VERIFY" = "true" ]; then
251 pushd "${ROOT_FS_DIR}" 247 pushd "$ROOT_FS_DIR"
252 bash 248 bash
253 popd 249 popd
254 fi 250 fi
255 251
256 cleanup 252 cleanup
257 253
258 # Now make it bootable with the flags from build_image 254 # Now make it bootable with the flags from build_image
259 "${SCRIPTS_DIR}/bin/cros_make_image_bootable" "$(dirname "${FLAGS_image}")" \ 255 "$SCRIPTS_DIR/bin/cros_make_image_bootable" "$(dirname "$FLAGS_image")" \
260 $(basename "${FLAGS_image}") 256 "$(basename "$FLAGS_image")"
261 257
262 print_time_elapsed 258 print_time_elapsed
263 259
264 trap - EXIT 260 trap - EXIT
265
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