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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 cleanup() { | 68 cleanup() { |
69 # Disable die on error. | 69 # Disable die on error. |
70 set +e | 70 set +e |
71 | 71 |
72 cleanup_rootfs_mounts | 72 cleanup_rootfs_mounts |
73 if [ -n "${LOOP_DEV}" ] | 73 if [ -n "${LOOP_DEV}" ] |
74 then | 74 then |
75 cleanup_rootfs_loop | 75 cleanup_rootfs_loop |
76 fi | 76 fi |
77 | 77 |
| 78 rmdir "${ROOT_FS_DIR}" |
| 79 |
78 # Turn die on error back on. | 80 # Turn die on error back on. |
79 set -e | 81 set -e |
80 } | 82 } |
81 | 83 |
82 # main process begins here. | 84 # main process begins here. |
83 | 85 |
84 # Make sure this is really what the user wants, before nuking the device | 86 # Make sure this is really what the user wants, before nuking the device |
85 if [ $FLAGS_yes -ne $FLAGS_TRUE ]; then | 87 if [ $FLAGS_yes -ne $FLAGS_TRUE ]; then |
86 read -p "Modifying image ${FLAGS_image} for test; are you sure (y/N)? " SURE | 88 read -p "Modifying image ${FLAGS_image} for test; are you sure (y/N)? " SURE |
87 SURE="${SURE:0:1}" # Get just the first character | 89 SURE="${SURE:0:1}" # Get just the first character |
88 if [ "$SURE" != "y" ]; then | 90 if [ "$SURE" != "y" ]; then |
89 echo "Ok, better safe than sorry." | 91 echo "Ok, better safe than sorry." |
90 exit 1 | 92 exit 1 |
91 fi | 93 fi |
92 else | 94 else |
93 echo "Modifying image ${FLAGS_image} for test..." | 95 echo "Modifying image ${FLAGS_image} for test..." |
94 fi | 96 fi |
95 | 97 |
96 set -e | 98 set -e |
97 trap cleanup EXIT | |
98 | 99 |
99 ROOT_FS_DIR=$(dirname "${FLAGS_image}")/rootfs | 100 ROOT_FS_DIR=$(dirname "${FLAGS_image}")/rootfs |
100 mkdir -p "${ROOT_FS_DIR}" | 101 mkdir -p "${ROOT_FS_DIR}" |
101 | 102 |
| 103 trap cleanup EXIT |
| 104 |
102 # Figure out how to loop mount the rootfs partition. It should be partition 3 | 105 # Figure out how to loop mount the rootfs partition. It should be partition 3 |
103 # on the disk image. | 106 # on the disk image. |
104 offset=$(partoffset "${FLAGS_image}" 3) | 107 offset=$(partoffset "${FLAGS_image}" 3) |
105 | 108 |
106 LOOP_DEV=$(sudo losetup -f) | 109 LOOP_DEV=$(sudo losetup -f) |
107 if [ -z "$LOOP_DEV" ]; then | 110 if [ -z "$LOOP_DEV" ]; then |
108 echo "No free loop device" | 111 echo "No free loop device" |
109 exit 1 | 112 exit 1 |
110 fi | 113 fi |
111 sudo losetup -o $(( $offset * 512 )) "${LOOP_DEV}" "${FLAGS_image}" | 114 sudo losetup -o $(( $offset * 512 )) "${LOOP_DEV}" "${FLAGS_image}" |
(...skipping 27 matching lines...) Expand all Loading... |
139 ${ROOT_FS_DIR}/usr/local/manufacturing/qualified_components | 142 ${ROOT_FS_DIR}/usr/local/manufacturing/qualified_components |
140 else | 143 else |
141 echo "No qualified component file found at: ${FLAGS_qualdb}" | 144 echo "No qualified component file found at: ${FLAGS_qualdb}" |
142 exit 1 | 145 exit 1 |
143 fi | 146 fi |
144 fi | 147 fi |
145 | 148 |
146 cleanup | 149 cleanup |
147 trap - EXIT | 150 trap - EXIT |
148 | 151 |
OLD | NEW |