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

Side by Side Diff: bin/cros_mod_image_for_test.sh

Issue 6413012: chromeos-installer: delete unused files (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/installer.git@master
Patch Set: 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 | « bin/cros_mod_image_for_recovery.sh ('k') | bin/cros_mount_gpt_image.sh » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/bin/bash
2
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
5 # found in the LICENSE file.
6
7 # Script to modify a keyfob-based chromeos system image for testability.
8
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.
11 . "/usr/lib/crosutils/common.sh"
12
13 # Load functions and constants for chromeos-install
14 . "/usr/lib/installer/chromeos-common.sh"
15
16 # We need to be in the chroot to emerge test packages.
17 assert_inside_chroot
18
19 get_default_board
20
21 DEFINE_string board "$DEFAULT_BOARD" "Board for which the image was built" b
22 DEFINE_boolean factory $FLAGS_FALSE \
23 "Modify the image for manufacturing testing" f
24 DEFINE_boolean factory_install $FLAGS_FALSE \
25 "Modify the image for factory install shim"
26 DEFINE_string image "" "Location of the rootfs raw image file" i
27 DEFINE_boolean installmask $FLAGS_TRUE \
28 "Use INSTALL_MASK to shrink the resulting image." m
29 DEFINE_integer jobs -1 \
30 "How many packages to build in parallel at maximum." j
31 DEFINE_string qualdb "" "Location of qualified component file" d
32 DEFINE_boolean yes $FLAGS_FALSE "Answer yes to all prompts" y
33 DEFINE_string build_root "/build" \
34 "The root location for board sysroots."
35 DEFINE_boolean fast ${DEFAULT_FAST} "Call many emerges in parallel"
36
37
38 # Parse command line
39 FLAGS "$@" || exit 1
40 eval set -- "${FLAGS_ARGV}"
41
42 EMERGE_CMD="emerge"
43 EMERGE_BOARD_CMD="emerge-${FLAGS_board}"
44 if [ "${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]; then
45 echo "Using alternate emerge"
46 EMERGE_CMD="${SCRIPTS_DIR}/parallel_emerge"
47 EMERGE_BOARD_CMD="${EMERGE_CMD} --board=${FLAGS_board}"
48 fi
49
50 # No board, no default and no image set then we can't find the image
51 if [ -z $FLAGS_image ] && [ -z $FLAGS_board ] ; then
52 setup_board_warning
53 die "cros_mod_image_for_test failed. No board set and no image set"
54 fi
55
56 # We have a board name but no image set. Use image at default location
57 if [ -z $FLAGS_image ] ; then
58 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}"
59 FILENAME="chromiumos_image.bin"
60 FLAGS_image="${IMAGES_DIR}/$(ls -t $IMAGES_DIR 2>&-| head -1)/${FILENAME}"
61 fi
62
63 # Turn path into an absolute path.
64 FLAGS_image=`eval readlink -f ${FLAGS_image}`
65
66 # Abort early if we can't find the image
67 if [ ! -f $FLAGS_image ] ; then
68 echo "No image found at $FLAGS_image"
69 exit 1
70 fi
71
72 # What cross-build are we targeting?
73 . "${FLAGS_build_root}/${FLAGS_board}/etc/make.conf.board_setup"
74 # Figure out ARCH from the given toolchain.
75 # TODO: Move to common.sh as a function after scripts are switched over.
76 TC_ARCH=$(echo "${CHOST}" | awk -F'-' '{ print $1 }')
77 case "${TC_ARCH}" in
78 arm*)
79 ARCH="arm"
80 ;;
81 *86)
82 ARCH="x86"
83 ;;
84 *)
85 error "Unable to determine ARCH from toolchain: ${CHOST}"
86 exit 1
87 esac
88
89 # Make sure anything mounted in the rootfs/stateful is cleaned up ok on exit.
90 cleanup_mounts() {
91 # Occasionally there are some daemons left hanging around that have our
92 # root/stateful image file system open. We do a best effort attempt to kill
93 # them.
94 PIDS=`sudo lsof -t "$1" | sort | uniq`
95 for pid in ${PIDS}
96 do
97 local cmdline=`cat /proc/$pid/cmdline`
98 echo "Killing process that has open file on the mounted directory: $cmdline"
99 sudo kill $pid || /bin/true
100 done
101 }
102
103 cleanup() {
104 "/usr/bin/cros_mount_gpt_image.sh" -u -r "$ROOT_FS_DIR" \
105 -s "$STATEFUL_DIR"
106 }
107
108 # Emerges chromeos-test onto the image.
109 emerge_chromeos_test() {
110 INSTALL_MASK=""
111 if [[ $FLAGS_installmask -eq ${FLAGS_TRUE} ]]; then
112 INSTALL_MASK="$DEFAULT_INSTALL_MASK"
113 fi
114
115 # Determine the root dir for test packages.
116 ROOT_DEV_DIR="$ROOT_FS_DIR/usr/local"
117
118 sudo INSTALL_MASK="$INSTALL_MASK" $EMERGE_BOARD_CMD \
119 --root="$ROOT_DEV_DIR" --root-deps=rdeps \
120 --usepkgonly chromeos-test $EMERGE_JOBS
121 }
122
123
124 install_autotest() {
125 SYSROOT="${FLAGS_build_root}/${FLAGS_board}"
126 AUTOTEST_SRC="${SYSROOT}/usr/local/autotest"
127 stateful_root="${ROOT_FS_DIR}/usr/local"
128 autotest_client="/autotest"
129
130 echo "Install autotest into stateful partition from $AUTOTEST_SRC"
131
132 sudo mkdir -p "${stateful_root}${autotest_client}"
133
134 # Remove excess files from stateful partition.
135 # If these aren't there, that's fine.
136 sudo rm -rf "${stateful_root}${autotest_client}/*" || true
137 sudo rm -rf "${stateful_root}/autotest-pkgs" || true
138 sudo rm -rf "${stateful_root}/lib/icedtea6" || true
139
140 sudo rsync --delete --delete-excluded -auv \
141 --exclude=deps/realtimecomm_playground \
142 --exclude=tests/ltp \
143 --exclude=site_tests/graphics_O3DSelenium \
144 --exclude=site_tests/realtimecomm_GTalk\* \
145 --exclude=site_tests/platform_StackProtector \
146 --exclude=deps/chrome_test \
147 --exclude=site_tests/desktopui_BrowserTest \
148 --exclude=site_tests/desktopui_UITest \
149 --exclude=.svn \
150 ${AUTOTEST_SRC}/client/* "${stateful_root}/${autotest_client}"
151
152 sudo chmod 755 "${stateful_root}/${autotest_client}"
153 sudo chown -R 1000:1000 "${stateful_root}/${autotest_client}"
154 }
155
156 # main process begins here.
157
158 # Make sure this is really what the user wants, before nuking the device
159 if [ $FLAGS_yes -ne $FLAGS_TRUE ]; then
160 read -p "Modifying image ${FLAGS_image} for test; are you sure (y/N)? " SURE
161 SURE="${SURE:0:1}" # Get just the first character
162 if [ "$SURE" != "y" ]; then
163 echo "Ok, better safe than sorry."
164 exit 1
165 fi
166 else
167 echo "Modifying image ${FLAGS_image} for test..."
168 fi
169
170 set -e
171
172 IMAGE_DIR="$(dirname "$FLAGS_image")"
173 IMAGE_NAME="$(basename "$FLAGS_image")"
174 ROOT_FS_DIR="$IMAGE_DIR/rootfs"
175 STATEFUL_DIR="$IMAGE_DIR/stateful_partition"
176
177 trap cleanup EXIT
178
179 # Mounts gpt image and sets up var, /usr/local and symlinks.
180 "/usr/bin/cros_mount_gpt_image.sh" -i "$IMAGE_NAME" \
181 -f "$IMAGE_DIR" -r "$ROOT_FS_DIR" -s "$STATEFUL_DIR"
182
183 if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ]; then
184 # We don't want to emerge test packages on factory install, otherwise we run
185 # out of space.
186
187 # Run factory setup script to modify the image.
188 sudo $EMERGE_BOARD_CMD --root=$ROOT_FS_DIR --usepkgonly \
189 --root-deps=rdeps --nodeps chromeos-factoryinstall
190
191 # Set factory server if necessary.
192 if [ "${FACTORY_SERVER}" != "" ]; then
193 sudo sed -i \
194 "s/CHROMEOS_AUSERVER=.*$/CHROMEOS_AUSERVER=\
195 http:\/\/${FACTORY_SERVER}:8080\/update/" \
196 ${ROOT_FS_DIR}/etc/lsb-release
197 fi
198 else
199 emerge_chromeos_test
200
201 MOD_TEST_ROOT="/usr/share/chromeos-installer/mod_for_test_scripts"
202 # Run test setup script to modify the image
203 sudo GCLIENT_ROOT="${GCLIENT_ROOT}" ROOT_FS_DIR="${ROOT_FS_DIR}" \
204 STATEFUL_DIR="${STATEFUL_DIR}" ARCH="${ARCH}" "${MOD_TEST_ROOT}/test_setup .sh"
205
206 if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ]; then
207 install_autotest
208
209 MOD_FACTORY_ROOT="/usr/share/chromeos-installer/mod_for_factory_scripts"
210 # Run factory setup script to modify the image
211 sudo GCLIENT_ROOT="${GCLIENT_ROOT}" ROOT_FS_DIR="${ROOT_FS_DIR}" \
212 QUALDB="${FLAGS_qualdb}" BOARD=${FLAGS_board} \
213 "${MOD_FACTORY_ROOT}/factory_setup.sh"
214 fi
215 fi
216
217 # Let's have a look at the image just in case..
218 if [ "${VERIFY}" = "true" ]; then
219 pushd "${ROOT_FS_DIR}"
220 bash
221 popd
222 fi
223
224 cleanup
225
226 # Now make it bootable with the flags from build_image
227 /usr/bin/cros_make_image_bootable $(dirname "${FLAGS_image}") \
228 $(basename "${FLAGS_image}")
229
230 print_time_elapsed
231
232 trap - EXIT
233
OLDNEW
« no previous file with comments | « bin/cros_mod_image_for_recovery.sh ('k') | bin/cros_mount_gpt_image.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698