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 |
53 } | 57 } |
54 | 58 |
55 cleanup_rootfs_loop() { | 59 cleanup_rootfs_loop() { |
56 sudo umount "${LOOP_DEV}" | 60 sudo umount "${LOOP_DEV}" |
57 sleep 1 # in case $LOOP_DEV is in use | 61 sleep 1 # in case $LOOP_DEV is in use |
58 sudo losetup -d "${LOOP_DEV}" | 62 sudo losetup -d "${LOOP_DEV}" |
59 } | 63 } |
60 | 64 |
61 cleanup() { | 65 cleanup() { |
62 # Disable die on error. | 66 # Disable die on error. |
(...skipping 27 matching lines...) Expand all Loading... |
90 if [ "$SURE" != "y" ]; then | 94 if [ "$SURE" != "y" ]; then |
91 echo "Ok, better safe than sorry." | 95 echo "Ok, better safe than sorry." |
92 exit 1 | 96 exit 1 |
93 fi | 97 fi |
94 else | 98 else |
95 echo "Modifying image ${FLAGS_image} for test..." | 99 echo "Modifying image ${FLAGS_image} for test..." |
96 fi | 100 fi |
97 | 101 |
98 MOD_SCRIPTS_ROOT="${GCLIENT_ROOT}/src/scripts/mod_for_test_scripts" | 102 MOD_SCRIPTS_ROOT="${GCLIENT_ROOT}/src/scripts/mod_for_test_scripts" |
99 sudo mkdir -p "${ROOT_FS_DIR}/modify_scripts" | 103 sudo mkdir -p "${ROOT_FS_DIR}/modify_scripts" |
| 104 |
100 sudo mount --bind "${MOD_SCRIPTS_ROOT}" "${ROOT_FS_DIR}/modify_scripts" | 105 sudo mount --bind "${MOD_SCRIPTS_ROOT}" "${ROOT_FS_DIR}/modify_scripts" |
101 | 106 |
102 # Run test setup script inside chroot jail to modify the image | 107 # Run test setup script inside chroot jail to modify the image |
103 sudo chroot "${ROOT_FS_DIR}" "/modify_scripts/test_setup.sh" | 108 sudo chroot "${ROOT_FS_DIR}" "/modify_scripts/test_setup.sh" |
104 | 109 |
105 sudo umount "${ROOT_FS_DIR}/modify_scripts" | 110 sudo umount "${ROOT_FS_DIR}/modify_scripts" |
106 sudo rmdir "${ROOT_FS_DIR}/modify_scripts" | 111 sudo rmdir "${ROOT_FS_DIR}/modify_scripts" |
107 | 112 |
108 cleanup | 113 cleanup |
109 trap - EXIT | 114 trap - EXIT |
110 | 115 |
OLD | NEW |