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 modify a keyfob-based chromeos system image for testability. | 7 # Script to modify a keyfob-based chromeos system image for testability. |
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 DEFINE_string board "$DEFAULT_BOARD" "Board for which the image was built" | 18 DEFINE_string board "$DEFAULT_BOARD" "Board for which the image was built" |
19 DEFINE_string qualdb "/tmp/run_remote_tests.*" \ | 19 DEFINE_string qualdb "/tmp/run_remote_tests.*" \ |
20 "Location of qualified component file" | 20 "Location of qualified component file" |
21 DEFINE_string image "" "Location of the rootfs raw image file" | 21 DEFINE_string image "" "Location of the rootfs raw image file" |
22 DEFINE_boolean factory $FLAGS_FALSE "Modify the image for manufacturing testing" | 22 DEFINE_boolean factory $FLAGS_FALSE "Modify the image for manufacturing testing" |
| 23 DEFINE_boolean factory_install $FLAGS_FALSE \ |
| 24 "Modify the image for factory install shim" |
23 DEFINE_boolean yes $FLAGS_FALSE "Answer yes to all prompts" "y" | 25 DEFINE_boolean yes $FLAGS_FALSE "Answer yes to all prompts" "y" |
24 | 26 |
25 # Parse command line | 27 # Parse command line |
26 FLAGS "$@" || exit 1 | 28 FLAGS "$@" || exit 1 |
27 eval set -- "${FLAGS_ARGV}" | 29 eval set -- "${FLAGS_ARGV}" |
28 | 30 |
29 # No board, no default and no image set then we can't find the image | 31 # No board, no default and no image set then we can't find the image |
30 if [ -z $FLAGS_image ] && [ -z $FLAGS_board ] ; then | 32 if [ -z $FLAGS_image ] && [ -z $FLAGS_board ] ; then |
31 setup_board_warning | 33 setup_board_warning |
32 echo "*** mod_image_for_test failed. No board set and no image set" | 34 echo "*** mod_image_for_test failed. No board set and no image set" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 sudo losetup -d "$1" | 68 sudo losetup -d "$1" |
67 } | 69 } |
68 | 70 |
69 cleanup() { | 71 cleanup() { |
70 # Disable die on error. | 72 # Disable die on error. |
71 set +e | 73 set +e |
72 | 74 |
73 cleanup_mounts "${ROOT_FS_DIR}" | 75 cleanup_mounts "${ROOT_FS_DIR}" |
74 if [ -n "${ROOT_LOOP_DEV}" ] | 76 if [ -n "${ROOT_LOOP_DEV}" ] |
75 then | 77 then |
| 78 sudo umount "${ROOT_FS_DIR}/var" |
76 cleanup_loop "${ROOT_LOOP_DEV}" | 79 cleanup_loop "${ROOT_LOOP_DEV}" |
77 fi | 80 fi |
78 rmdir "${ROOT_FS_DIR}" | 81 rmdir "${ROOT_FS_DIR}" |
79 | 82 |
80 cleanup_mounts "${STATEFUL_DIR}" | 83 cleanup_mounts "${STATEFUL_DIR}" |
81 if [ -n "${STATEFUL_LOOP_DEV}" ] | 84 if [ -n "${STATEFUL_LOOP_DEV}" ] |
82 then | 85 then |
83 cleanup_loop "${STATEFUL_LOOP_DEV}" | 86 cleanup_loop "${STATEFUL_LOOP_DEV}" |
84 fi | 87 fi |
85 rmdir "${STATEFUL_DIR}" | 88 rmdir "${STATEFUL_DIR}" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 # The stateful partition should be partition 1 on the disk image. | 130 # The stateful partition should be partition 1 on the disk image. |
128 offset=$(partoffset "${FLAGS_image}" 1) | 131 offset=$(partoffset "${FLAGS_image}" 1) |
129 | 132 |
130 STATEFUL_LOOP_DEV=$(sudo losetup -f) | 133 STATEFUL_LOOP_DEV=$(sudo losetup -f) |
131 if [ -z "$STATEFUL_LOOP_DEV" ]; then | 134 if [ -z "$STATEFUL_LOOP_DEV" ]; then |
132 echo "No free loop device" | 135 echo "No free loop device" |
133 exit 1 | 136 exit 1 |
134 fi | 137 fi |
135 sudo losetup -o $(( $offset * 512 )) "${STATEFUL_LOOP_DEV}" "${FLAGS_image}" | 138 sudo losetup -o $(( $offset * 512 )) "${STATEFUL_LOOP_DEV}" "${FLAGS_image}" |
136 sudo mount "${STATEFUL_LOOP_DEV}" "${STATEFUL_DIR}" | 139 sudo mount "${STATEFUL_LOOP_DEV}" "${STATEFUL_DIR}" |
| 140 sudo mount --bind "${STATEFUL_DIR}/var" "${ROOT_FS_DIR}/var" |
137 STATEFUL_DIR="${STATEFUL_DIR}" | 141 STATEFUL_DIR="${STATEFUL_DIR}" |
138 | 142 |
139 MOD_TEST_ROOT="${GCLIENT_ROOT}/src/scripts/mod_for_test_scripts" | 143 MOD_TEST_ROOT="${GCLIENT_ROOT}/src/scripts/mod_for_test_scripts" |
140 # Run test setup script to modify the image | 144 # Run test setup script to modify the image |
141 sudo GCLIENT_ROOT="${GCLIENT_ROOT}" ROOT_FS_DIR="${ROOT_FS_DIR}" \ | 145 sudo GCLIENT_ROOT="${GCLIENT_ROOT}" ROOT_FS_DIR="${ROOT_FS_DIR}" \ |
142 "${MOD_TEST_ROOT}/test_setup.sh" | 146 "${MOD_TEST_ROOT}/test_setup.sh" |
143 | 147 |
144 if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ]; then | 148 if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} ]; then |
145 MOD_FACTORY_ROOT="${GCLIENT_ROOT}/src/scripts/mod_for_factory_scripts" | 149 MOD_FACTORY_ROOT="${GCLIENT_ROOT}/src/scripts/mod_for_factory_scripts" |
146 # Run factory setup script to modify the image | 150 # Run factory setup script to modify the image |
147 sudo GCLIENT_ROOT="${GCLIENT_ROOT}" ROOT_FS_DIR="${ROOT_FS_DIR}" \ | 151 sudo GCLIENT_ROOT="${GCLIENT_ROOT}" ROOT_FS_DIR="${ROOT_FS_DIR}" \ |
148 STATEFUL_DIR="${STATEFUL_DIR}/dev_image" QUALDB="${FLAGS_qualdb}" \ | 152 STATEFUL_DIR="${STATEFUL_DIR}/dev_image" QUALDB="${FLAGS_qualdb}" \ |
149 "${MOD_FACTORY_ROOT}/factory_setup.sh" | 153 "${MOD_FACTORY_ROOT}/factory_setup.sh" |
150 fi | 154 fi |
151 | 155 |
| 156 if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ]; then |
| 157 # Run factory setup script to modify the image. |
| 158 sudo emerge-${FLAGS_board} --root=$ROOT_FS_DIR --usepkgonly \ |
| 159 --root-deps=rdeps chromeos-factoryinstall |
| 160 |
| 161 # Set factory server if necessary. |
| 162 if [ "${FACTORY_SERVER}" != "" ]; then |
| 163 sudo sed -i \ |
| 164 "s/CHROMEOS_AUSERVER=.*$/CHROMEOS_AUSERVER=\ |
| 165 http:\/\/${FACTORY_SERVER}:8080\/update/" \ |
| 166 ${ROOT_FS_DIR}/etc/lsb-release |
| 167 fi |
| 168 fi |
| 169 |
152 cleanup | 170 cleanup |
153 trap - EXIT | 171 trap - EXIT |
154 | 172 |
OLD | NEW |