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 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images" | 13 DEFAULT_BOARD=x86-generic |
ericli
2010/02/22 23:25:48
DEFAULT_BOARD was already defined inside common.sh
| |
14 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${DEFAULT_BOARD}" | |
14 DEFAULT_IMAGE="${IMAGES_DIR}/$(ls -t $IMAGES_DIR 2>&-| head -1)/rootfs.image" | 15 DEFAULT_IMAGE="${IMAGES_DIR}/$(ls -t $IMAGES_DIR 2>&-| head -1)/rootfs.image" |
16 | |
17 DEFINE_string board "$DEFAULT_BOARD" "Board for which the image was built" | |
15 DEFINE_string image "$DEFAULT_IMAGE" \ | 18 DEFINE_string image "$DEFAULT_IMAGE" \ |
16 "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 | 21 |
18 # Parse command line | 22 # Parse command line |
19 FLAGS "$@" || exit 1 | 23 FLAGS "$@" || exit 1 |
20 eval set -- "${FLAGS_ARGV}" | 24 eval set -- "${FLAGS_ARGV}" |
21 | 25 |
26 IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${DEFAULT_BOARD}" | |
27 DEFAULT_IMAGE="${IMAGES_DIR}/$(ls -t $IMAGES_DIR 2>&-| head -1)/rootfs.image" | |
28 | |
22 # Make sure anything mounted in the rootfs is cleaned up ok on exit. | 29 # Make sure anything mounted in the rootfs is cleaned up ok on exit. |
23 cleanup_rootfs_mounts() { | 30 cleanup_rootfs_mounts() { |
24 # Occasionally there are some daemons left hanging around that have our | 31 # Occasionally there are some daemons left hanging around that have our |
25 # root image file system open. We do a best effort attempt to kill them. | 32 # root image file system open. We do a best effort attempt to kill them. |
26 PIDS=`sudo lsof -t "${ROOT_FS_DIR}" | sort | uniq` | 33 PIDS=`sudo lsof -t "${ROOT_FS_DIR}" | sort | uniq` |
27 for pid in ${PIDS} | 34 for pid in ${PIDS} |
28 do | 35 do |
29 local cmdline=`cat /proc/$pid/cmdline` | 36 local cmdline=`cat /proc/$pid/cmdline` |
30 echo "Killing process that has open file on our rootfs: $cmdline" | 37 echo "Killing process that has open file on our rootfs: $cmdline" |
31 ! sudo kill $pid # Preceded by ! to disable ERR trap. | 38 ! sudo kill $pid # Preceded by ! to disable ERR trap. |
(...skipping 24 matching lines...) Expand all Loading... | |
56 set -e | 63 set -e |
57 trap cleanup EXIT | 64 trap cleanup EXIT |
58 | 65 |
59 ROOT_FS_DIR="`dirname ${FLAGS_image}`/rootfs" | 66 ROOT_FS_DIR="`dirname ${FLAGS_image}`/rootfs" |
60 mkdir -p "${ROOT_FS_DIR}" | 67 mkdir -p "${ROOT_FS_DIR}" |
61 | 68 |
62 LOOP_DEV=`sudo losetup -f` | 69 LOOP_DEV=`sudo losetup -f` |
63 sudo losetup "${LOOP_DEV}" "${FLAGS_image}" | 70 sudo losetup "${LOOP_DEV}" "${FLAGS_image}" |
64 sudo mount "${LOOP_DEV}" "${ROOT_FS_DIR}" | 71 sudo mount "${LOOP_DEV}" "${ROOT_FS_DIR}" |
65 | 72 |
66 echo "Modifying image ${FLAGS_image} for test..." | 73 # Make sure this is really what the user wants, before nuking the device |
74 if [ $FLAGS_yes -ne $FLAGS_TRUE ]; then | |
75 read -p "Modifying image ${FLAGS_image} for test; are you sure (y/N)? " SURE | |
76 SURE="${SURE:0:1}" # Get just the first character | |
77 if [ "$SURE" != "y" ]; then | |
78 echo "Ok, better safe than sorry." | |
79 exit 1 | |
80 fi | |
81 else | |
82 echo "Modifying image ${FLAGS_image} for test..." | |
83 fi | |
67 | 84 |
68 MOD_SCRIPTS_ROOT="${GCLIENT_ROOT}/src/scripts/mod_for_test_scripts" | 85 MOD_SCRIPTS_ROOT="${GCLIENT_ROOT}/src/scripts/mod_for_test_scripts" |
69 sudo mkdir -p "${ROOT_FS_DIR}/modify_scripts" | 86 sudo mkdir -p "${ROOT_FS_DIR}/modify_scripts" |
70 sudo mount --bind "${MOD_SCRIPTS_ROOT}" "${ROOT_FS_DIR}/modify_scripts" | 87 sudo mount --bind "${MOD_SCRIPTS_ROOT}" "${ROOT_FS_DIR}/modify_scripts" |
71 | 88 |
72 # Run test setup script inside chroot jail to modify the image | 89 # Run test setup script inside chroot jail to modify the image |
73 sudo chroot "${ROOT_FS_DIR}" "/modify_scripts/test_setup.sh" | 90 sudo chroot "${ROOT_FS_DIR}" "/modify_scripts/test_setup.sh" |
74 | 91 |
75 sudo umount "${ROOT_FS_DIR}/modify_scripts" | 92 sudo umount "${ROOT_FS_DIR}/modify_scripts" |
76 sudo rmdir "${ROOT_FS_DIR}/modify_scripts" | 93 sudo rmdir "${ROOT_FS_DIR}/modify_scripts" |
77 | 94 |
78 cleanup | 95 cleanup |
79 trap - EXIT | 96 trap - EXIT |
80 | 97 |
OLD | NEW |