OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 # | 2 # |
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 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 which ensures that a given image has an up-to-date | 7 # Script which ensures that a given image has an up-to-date |
8 # kernel partition, rootfs integrity hashes, and legacy bootloader configs. | 8 # kernel partition, rootfs integrity hashes, and legacy bootloader configs. |
9 | 9 |
10 # Load common constants. This should be the first executable line. | 10 # --- BEGIN COMMON.SH BOILERPLATE --- |
11 # The path to common.sh should be relative to your script's location. | 11 # Load common CrOS utilities. Inside the chroot this file is installed in |
12 COMMON_PATH="$(dirname "$0")/../common.sh" | 12 # /usr/lib/crosutils. Outside the chroot we find it relative to the script's |
13 if [ ! -r "${COMMON_PATH}" ]; then | 13 # location. |
14 echo "ERROR! Cannot find common.sh: ${COMMON_PATH}" 1>&2 | 14 find_common_sh() { |
15 exit 1 | 15 local common_paths=(/usr/lib/crosutils "$(dirname "$(readlink -f "$0")")/..") |
16 fi | 16 local path |
17 | 17 |
18 . "$(dirname "$0")/../common.sh" | 18 SCRIPT_ROOT= |
| 19 for path in "${common_paths[@]}"; do |
| 20 if [ -r "${path}/common.sh" ]; then |
| 21 SCRIPT_ROOT=${path} |
| 22 break |
| 23 fi |
| 24 done |
| 25 } |
19 | 26 |
20 # Script must be run inside the chroot. | 27 find_common_sh |
| 28 . "${SCRIPT_ROOT}/common.sh" || (echo "Unable to load common.sh" && exit 1) |
| 29 # --- END COMMON.SH BOILERPLATE --- |
| 30 |
| 31 # Need to be inside the chroot to load chromeos-common.sh |
21 assert_inside_chroot | 32 assert_inside_chroot |
22 | 33 |
| 34 # Load functions and constants for chromeos-install |
| 35 . "/usr/lib/installer/chromeos-common.sh" || \ |
| 36 die "Unable to load /usr/lib/installer/chromeos-common.sh" |
| 37 |
23 set -e | 38 set -e |
24 . "$(dirname "$0")/../chromeos-common.sh" # for partoffset and partsize | |
25 | 39 |
26 if [ $# -lt 2 ]; then | 40 if [ $# -lt 2 ]; then |
27 echo "Usage: ${0} /PATH/TO/IMAGE IMAGE.BIN [shflags overrides]" | 41 echo "Usage: ${0} /PATH/TO/IMAGE IMAGE.BIN [shflags overrides]" |
28 exit 1 | 42 exit 1 |
29 fi | 43 fi |
30 | 44 |
31 IMAGE_DIR="$(readlink -f "${1}")" | 45 IMAGE_DIR="$(readlink -f "${1}")" |
32 BOOT_DESC_FILE="${IMAGE_DIR}/boot.desc" | 46 BOOT_DESC_FILE="${IMAGE_DIR}/boot.desc" |
33 IMAGE="${IMAGE_DIR}/${2}" | 47 IMAGE="${IMAGE_DIR}/${2}" |
34 shift | 48 shift |
35 shift | 49 shift |
36 FLAG_OVERRIDES="${@}" | 50 FLAG_OVERRIDES="${@}" |
37 | 51 |
38 if [ ! -r "${BOOT_DESC_FILE}" ]; then | 52 if [ ! -r "${BOOT_DESC_FILE}" ]; then |
39 warn "${BOOT_DESC_FILE} cannot be read!" | 53 warn "${BOOT_DESC_FILE} cannot be read!" |
40 warn "Falling back to command line parsing" | 54 warn "Falling back to command line parsing" |
41 BOOT_DESC="${@}" | 55 BOOT_DESC="${@}" |
42 else | 56 else |
43 BOOT_DESC="$(cat ${BOOT_DESC_FILE} | tr -s '\n' ' ')" | 57 BOOT_DESC="$(cat ${BOOT_DESC_FILE} | tr -s '\n' ' ')" |
44 info "Boot-time configuration for $(dirname ${IMAGE}): " | 58 info "Boot-time configuration for $(dirname "${IMAGE}"): " |
45 cat ${BOOT_DESC_FILE} | while read line; do | 59 cat ${BOOT_DESC_FILE} | while read line; do |
46 info " ${line}" | 60 info " ${line}" |
47 done | 61 done |
48 fi | 62 fi |
49 | 63 |
50 if [ ! -r "${IMAGE}" ]; then | 64 if [ ! -r "${IMAGE}" ]; then |
51 die "${IMAGE} cannot be read!" | 65 die "${IMAGE} cannot be read!" |
52 fi | 66 fi |
53 | 67 |
54 | 68 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 | 145 |
132 cros_root=/dev/sd%D%P | 146 cros_root=/dev/sd%D%P |
133 if [[ "${FLAGS_arch}" = "arm" ]]; then | 147 if [[ "${FLAGS_arch}" = "arm" ]]; then |
134 cros_root='/dev/${devname}${rootpart}' | 148 cros_root='/dev/${devname}${rootpart}' |
135 fi | 149 fi |
136 if [[ ${FLAGS_enable_rootfs_verification} -eq ${FLAGS_TRUE} ]]; then | 150 if [[ ${FLAGS_enable_rootfs_verification} -eq ${FLAGS_TRUE} ]]; then |
137 cros_root=/dev/dm-0 | 151 cros_root=/dev/dm-0 |
138 fi | 152 fi |
139 | 153 |
140 trap "mount_gpt_cleanup" EXIT | 154 trap "mount_gpt_cleanup" EXIT |
141 ${SCRIPTS_DIR}/mount_gpt_image.sh --from "$(dirname ${image})" \ | 155 "${SCRIPTS_DIR}/mount_gpt_image.sh" --from "$(dirname "${image}")" \ |
142 --image "$(basename ${image})" -r "${FLAGS_rootfs_mountpoint}" \ | 156 --image "$(basename ${image})" -r "${FLAGS_rootfs_mountpoint}" \ |
143 -s "${FLAGS_statefulfs_mountpoint}" | 157 -s "${FLAGS_statefulfs_mountpoint}" |
144 | 158 |
145 # The rootfs should never be mounted rw again after this point without | 159 # The rootfs should never be mounted rw again after this point without |
146 # re-calling make_image_bootable. | 160 # re-calling make_image_bootable. |
147 sudo mount -o remount,ro "${FLAGS_rootfs_mountpoint}" | 161 sudo mount -o remount,ro "${FLAGS_rootfs_mountpoint}" |
148 root_dev=$(mount | grep -- "on ${FLAGS_rootfs_mountpoint} type" | | 162 root_dev=$(mount | grep -- "on ${FLAGS_rootfs_mountpoint} type" | |
149 cut -f1 -d' ' | tail -1) | 163 cut -f1 -d' ' | tail -1) |
150 | 164 |
151 # Make the filesystem un-mountable as read-write. | 165 # Make the filesystem un-mountable as read-write. |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 mkdir -p ${FLAGS_espfs_mountpoint} | 298 mkdir -p ${FLAGS_espfs_mountpoint} |
285 | 299 |
286 make_image_bootable "${IMAGE}" | 300 make_image_bootable "${IMAGE}" |
287 verify_image_rootfs "${IMAGE}" | 301 verify_image_rootfs "${IMAGE}" |
288 | 302 |
289 if [ ${FLAGS_cleanup_dirs} -eq ${FLAGS_TRUE} ]; then | 303 if [ ${FLAGS_cleanup_dirs} -eq ${FLAGS_TRUE} ]; then |
290 rmdir ${FLAGS_rootfs_mountpoint} | 304 rmdir ${FLAGS_rootfs_mountpoint} |
291 rmdir ${FLAGS_statefulfs_mountpoint} | 305 rmdir ${FLAGS_statefulfs_mountpoint} |
292 rmdir ${FLAGS_espfs_mountpoint} | 306 rmdir ${FLAGS_espfs_mountpoint} |
293 fi | 307 fi |
OLD | NEW |