| 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. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 cleanup_rootfs_mounts() { | 43 cleanup_rootfs_mounts() { |
| 44 # Occasionally there are some daemons left hanging around that have our | 44 # Occasionally there are some daemons left hanging around that have our |
| 45 # 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. |
| 46 PIDS=`sudo lsof -t "${ROOT_FS_DIR}" | sort | uniq` | 46 PIDS=`sudo lsof -t "${ROOT_FS_DIR}" | sort | uniq` |
| 47 for pid in ${PIDS} | 47 for pid in ${PIDS} |
| 48 do | 48 do |
| 49 local cmdline=`cat /proc/$pid/cmdline` | 49 local cmdline=`cat /proc/$pid/cmdline` |
| 50 echo "Killing process that has open file on our rootfs: $cmdline" | 50 echo "Killing process that has open file on our rootfs: $cmdline" |
| 51 ! sudo kill $pid # Preceded by ! to disable ERR trap. | 51 ! sudo kill $pid # Preceded by ! to disable ERR trap. |
| 52 done | 52 done |
| 53 if [[ -d "${ROOT_FS_DIR}/modify_scripts" ]]; then | |
| 54 echo "Cleaned up modify_scripts mount" | |
| 55 ! sudo umount "${ROOT_FS_DIR}/modify_scripts" | |
| 56 fi | |
| 57 } | 53 } |
| 58 | 54 |
| 59 cleanup_rootfs_loop() { | 55 cleanup_rootfs_loop() { |
| 60 sudo umount "${LOOP_DEV}" | 56 sudo umount "${LOOP_DEV}" |
| 61 sleep 1 # in case $LOOP_DEV is in use | 57 sleep 1 # in case $LOOP_DEV is in use |
| 62 sudo losetup -d "${LOOP_DEV}" | 58 sudo losetup -d "${LOOP_DEV}" |
| 63 } | 59 } |
| 64 | 60 |
| 65 cleanup() { | 61 cleanup() { |
| 66 # Disable die on error. | 62 # Disable die on error. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 93 SURE="${SURE:0:1}" # Get just the first character | 89 SURE="${SURE:0:1}" # Get just the first character |
| 94 if [ "$SURE" != "y" ]; then | 90 if [ "$SURE" != "y" ]; then |
| 95 echo "Ok, better safe than sorry." | 91 echo "Ok, better safe than sorry." |
| 96 exit 1 | 92 exit 1 |
| 97 fi | 93 fi |
| 98 else | 94 else |
| 99 echo "Modifying image ${FLAGS_image} for test..." | 95 echo "Modifying image ${FLAGS_image} for test..." |
| 100 fi | 96 fi |
| 101 | 97 |
| 102 MOD_SCRIPTS_ROOT="${GCLIENT_ROOT}/src/scripts/mod_for_test_scripts" | 98 MOD_SCRIPTS_ROOT="${GCLIENT_ROOT}/src/scripts/mod_for_test_scripts" |
| 103 sudo mkdir -p "${ROOT_FS_DIR}/modify_scripts" | |
| 104 | |
| 105 sudo mount --bind "${MOD_SCRIPTS_ROOT}" "${ROOT_FS_DIR}/modify_scripts" | |
| 106 | |
| 107 # Run test setup script inside chroot jail to modify the image | 99 # Run test setup script inside chroot jail to modify the image |
| 108 sudo chroot "${ROOT_FS_DIR}" "/modify_scripts/test_setup.sh" | 100 sudo GCLIENT_ROOT=${GCLIENT_ROOT} ROOT_FS_DIR=${ROOT_FS_DIR} \ |
| 109 | 101 "${MOD_SCRIPTS_ROOT}/test_setup.sh" |
| 110 sudo umount "${ROOT_FS_DIR}/modify_scripts" | |
| 111 sudo rmdir "${ROOT_FS_DIR}/modify_scripts" | |
| 112 | 102 |
| 113 cleanup | 103 cleanup |
| 114 trap - EXIT | 104 trap - EXIT |
| 115 | 105 |
| OLD | NEW |