| 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 DEFAULT_BOARD=x86-generic | 13 get_default_board |
| 14 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${DEFAULT_BOARD}" | |
| 15 DEFAULT_IMAGE="${IMAGES_DIR}/$(ls -t $IMAGES_DIR 2>&-| head -1)/rootfs.image" | |
| 16 | 14 |
| 17 DEFINE_string board "$DEFAULT_BOARD" "Board for which the image was built" | 15 DEFINE_string board "$DEFAULT_BOARD" "Board for which the image was built" |
| 18 DEFINE_string image "$DEFAULT_IMAGE" \ | 16 DEFINE_string image "" "Location of the rootfs raw image file" |
| 19 "Location of the rootfs raw image file" | |
| 20 DEFINE_boolean yes $FLAGS_FALSE "Answer yes to all prompts" "y" | 17 DEFINE_boolean yes $FLAGS_FALSE "Answer yes to all prompts" "y" |
| 21 | 18 |
| 22 # Parse command line | 19 # Parse command line |
| 23 FLAGS "$@" || exit 1 | 20 FLAGS "$@" || exit 1 |
| 24 eval set -- "${FLAGS_ARGV}" | 21 eval set -- "${FLAGS_ARGV}" |
| 25 | 22 |
| 26 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${DEFAULT_BOARD}" | 23 # No board, no default and no image set then we can't find the image |
| 27 DEFAULT_IMAGE="${IMAGES_DIR}/$(ls -t $IMAGES_DIR 2>&-| head -1)/rootfs.image" | 24 if [ -z $FLAGS_IMAGE ] && [ -z $FLAGS_board ] ; then |
| 25 setup_board_warning |
| 26 echo "*** mod_image_for_test failed. No board set and no image set" |
| 27 exit 1 |
| 28 fi |
| 29 |
| 30 # We have a board name but no image set. Use image at default location |
| 31 if [ -z $FLAGS_image ] ; then |
| 32 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}" |
| 33 FLAGS_image="${IMAGES_DIR}/$(ls -t $IMAGES_DIR 2>&-| head -1)/rootfs.image" |
| 34 fi |
| 35 |
| 36 # Abort early if we can't find the image |
| 37 if [ ! -f $FLAGS_image ] ; then |
| 38 echo "No image found at $FLAGS_image" |
| 39 exit 1 |
| 40 fi |
| 28 | 41 |
| 29 # Make sure anything mounted in the rootfs is cleaned up ok on exit. | 42 # Make sure anything mounted in the rootfs is cleaned up ok on exit. |
| 30 cleanup_rootfs_mounts() { | 43 cleanup_rootfs_mounts() { |
| 31 # Occasionally there are some daemons left hanging around that have our | 44 # Occasionally there are some daemons left hanging around that have our |
| 32 # root image file system open. We do a best effort attempt to kill them. | 45 # root image file system open. We do a best effort attempt to kill them. |
| 33 PIDS=`sudo lsof -t "${ROOT_FS_DIR}" | sort | uniq` | 46 PIDS=`sudo lsof -t "${ROOT_FS_DIR}" | sort | uniq` |
| 34 for pid in ${PIDS} | 47 for pid in ${PIDS} |
| 35 do | 48 do |
| 36 local cmdline=`cat /proc/$pid/cmdline` | 49 local cmdline=`cat /proc/$pid/cmdline` |
| 37 echo "Killing process that has open file on our rootfs: $cmdline" | 50 echo "Killing process that has open file on our rootfs: $cmdline" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 101 |
| 89 # Run test setup script inside chroot jail to modify the image | 102 # Run test setup script inside chroot jail to modify the image |
| 90 sudo chroot "${ROOT_FS_DIR}" "/modify_scripts/test_setup.sh" | 103 sudo chroot "${ROOT_FS_DIR}" "/modify_scripts/test_setup.sh" |
| 91 | 104 |
| 92 sudo umount "${ROOT_FS_DIR}/modify_scripts" | 105 sudo umount "${ROOT_FS_DIR}/modify_scripts" |
| 93 sudo rmdir "${ROOT_FS_DIR}/modify_scripts" | 106 sudo rmdir "${ROOT_FS_DIR}/modify_scripts" |
| 94 | 107 |
| 95 cleanup | 108 cleanup |
| 96 trap - EXIT | 109 trap - EXIT |
| 97 | 110 |
| OLD | NEW |