| 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 # --- BEGIN COMMON.SH BOILERPLATE --- |
| 10 # The path to common.sh should be relative to your script's location. | 10 # Load common CrOS utilities. Inside the chroot this file is installed in |
| 11 . "$(dirname "$0")/common.sh" | 11 # /usr/lib/crosutils. Outside the chroot we find it relative to the script's |
| 12 # location. |
| 13 find_common_sh() { |
| 14 local common_paths=(/usr/lib/crosutils $(dirname "$(readlink -f "$0")")) |
| 15 local path |
| 16 |
| 17 SCRIPT_ROOT= |
| 18 for path in "${common_paths[@]}"; do |
| 19 if [ -r "${path}/common.sh" ]; then |
| 20 SCRIPT_ROOT=${path} |
| 21 break |
| 22 fi |
| 23 done |
| 24 } |
| 25 |
| 26 find_common_sh |
| 27 . "${SCRIPT_ROOT}/common.sh" || (echo "Unable to load common.sh" && exit 1) |
| 28 # --- END COMMON.SH BOILERPLATE --- |
| 29 |
| 30 # Need to be inside the chroot to load chromeos-common.sh |
| 31 assert_inside_chroot |
| 12 | 32 |
| 13 # Load functions and constants for chromeos-install | 33 # Load functions and constants for chromeos-install |
| 14 . "$(dirname "$0")/chromeos-common.sh" | 34 . "/usr/lib/installer/chromeos-common.sh" || \ |
| 15 | 35 die "Unable to load /usr/lib/installer/chromeos-common.sh" |
| 16 # We need to be in the chroot to emerge test packages. | |
| 17 assert_inside_chroot | |
| 18 | 36 |
| 19 get_default_board | 37 get_default_board |
| 20 | 38 |
| 21 DEFINE_string board "$DEFAULT_BOARD" "Board for which the image was built" b | 39 DEFINE_string board "$DEFAULT_BOARD" "Board for which the image was built" b |
| 22 DEFINE_boolean factory $FLAGS_FALSE \ | 40 DEFINE_boolean factory $FLAGS_FALSE \ |
| 23 "Modify the image for manufacturing testing" f | 41 "Modify the image for manufacturing testing" f |
| 24 DEFINE_boolean factory_install $FLAGS_FALSE \ | 42 DEFINE_boolean factory_install $FLAGS_FALSE \ |
| 25 "Modify the image for factory install shim" | 43 "Modify the image for factory install shim" |
| 26 DEFINE_string image "" "Location of the rootfs raw image file" i | 44 DEFINE_string image "" "Location of the rootfs raw image file" i |
| 27 DEFINE_boolean installmask $FLAGS_TRUE \ | 45 DEFINE_boolean installmask $FLAGS_TRUE \ |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 error "Unable to determine ARCH from toolchain: ${CHOST}" | 103 error "Unable to determine ARCH from toolchain: ${CHOST}" |
| 86 exit 1 | 104 exit 1 |
| 87 esac | 105 esac |
| 88 | 106 |
| 89 # Make sure anything mounted in the rootfs/stateful is cleaned up ok on exit. | 107 # Make sure anything mounted in the rootfs/stateful is cleaned up ok on exit. |
| 90 cleanup_mounts() { | 108 cleanup_mounts() { |
| 91 # Occasionally there are some daemons left hanging around that have our | 109 # 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 | 110 # root/stateful image file system open. We do a best effort attempt to kill |
| 93 # them. | 111 # them. |
| 94 PIDS=`sudo lsof -t "$1" | sort | uniq` | 112 PIDS=`sudo lsof -t "$1" | sort | uniq` |
| 95 for pid in ${PIDS} | 113 for pid in ${PIDS}; do |
| 96 do | |
| 97 local cmdline=`cat /proc/$pid/cmdline` | 114 local cmdline=`cat /proc/$pid/cmdline` |
| 98 echo "Killing process that has open file on the mounted directory: $cmdline" | 115 echo "Killing process that has open file on the mounted directory: $cmdline" |
| 99 sudo kill $pid || /bin/true | 116 sudo kill $pid || /bin/true |
| 100 done | 117 done |
| 101 } | 118 } |
| 102 | 119 |
| 103 cleanup() { | 120 cleanup() { |
| 104 "$SCRIPTS_DIR/mount_gpt_image.sh" -u -r "$ROOT_FS_DIR" -s "$STATEFUL_DIR" | 121 "$SCRIPTS_DIR/mount_gpt_image.sh" -u -r "$ROOT_FS_DIR" -s "$STATEFUL_DIR" |
| 105 } | 122 } |
| 106 | 123 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 if [ "$SURE" != "y" ]; then | 179 if [ "$SURE" != "y" ]; then |
| 163 echo "Ok, better safe than sorry." | 180 echo "Ok, better safe than sorry." |
| 164 exit 1 | 181 exit 1 |
| 165 fi | 182 fi |
| 166 else | 183 else |
| 167 echo "Modifying image ${FLAGS_image} for test..." | 184 echo "Modifying image ${FLAGS_image} for test..." |
| 168 fi | 185 fi |
| 169 | 186 |
| 170 set -e | 187 set -e |
| 171 | 188 |
| 172 IMAGE_DIR="$(dirname "$FLAGS_image")" | 189 IMAGE_DIR=$(dirname "$FLAGS_image") |
| 173 IMAGE_NAME="$(basename "$FLAGS_image")" | 190 IMAGE_NAME="$(basename "$FLAGS_image")" |
| 174 ROOT_FS_DIR="$IMAGE_DIR/rootfs" | 191 ROOT_FS_DIR="$IMAGE_DIR/rootfs" |
| 175 STATEFUL_DIR="$IMAGE_DIR/stateful_partition" | 192 STATEFUL_DIR="$IMAGE_DIR/stateful_partition" |
| 176 SCRIPTS_DIR=$(dirname "$0") | 193 SCRIPTS_DIR=${SCRIPT_ROOT} |
| 177 DEV_USER="chronos" | 194 DEV_USER="chronos" |
| 178 | 195 |
| 179 trap cleanup EXIT | 196 trap cleanup EXIT |
| 180 | 197 |
| 181 # Mounts gpt image and sets up var, /usr/local and symlinks. | 198 # Mounts gpt image and sets up var, /usr/local and symlinks. |
| 182 "$SCRIPTS_DIR/mount_gpt_image.sh" -i "$IMAGE_NAME" -f "$IMAGE_DIR" \ | 199 "$SCRIPTS_DIR/mount_gpt_image.sh" -i "$IMAGE_NAME" -f "$IMAGE_DIR" \ |
| 183 -r "$ROOT_FS_DIR" -s "$STATEFUL_DIR" | 200 -r "$ROOT_FS_DIR" -s "$STATEFUL_DIR" |
| 184 | 201 |
| 185 if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ]; then | 202 if [ ${FLAGS_factory_install} -eq ${FLAGS_TRUE} ]; then |
| 186 # We don't want to emerge test packages on factory install, otherwise we run | 203 # We don't want to emerge test packages on factory install, otherwise we run |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 # Let's have a look at the image just in case.. | 239 # Let's have a look at the image just in case.. |
| 223 if [ "${VERIFY}" = "true" ]; then | 240 if [ "${VERIFY}" = "true" ]; then |
| 224 pushd "${ROOT_FS_DIR}" | 241 pushd "${ROOT_FS_DIR}" |
| 225 bash | 242 bash |
| 226 popd | 243 popd |
| 227 fi | 244 fi |
| 228 | 245 |
| 229 cleanup | 246 cleanup |
| 230 | 247 |
| 231 # Now make it bootable with the flags from build_image | 248 # Now make it bootable with the flags from build_image |
| 232 ${SCRIPTS_DIR}/bin/cros_make_image_bootable $(dirname "${FLAGS_image}") \ | 249 "${SCRIPTS_DIR}/bin/cros_make_image_bootable" "$(dirname "${FLAGS_image}")" \ |
| 233 $(basename "${FLAGS_image}") | 250 $(basename "${FLAGS_image}") |
| 234 | 251 |
| 235 print_time_elapsed | 252 print_time_elapsed |
| 236 | 253 |
| 237 trap - EXIT | 254 trap - EXIT |
| 238 | 255 |
| OLD | NEW |