| 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 to verify integrity of root file system for a GPT-based image | 7 # Script to verify integrity of root file system for a GPT-based image |
| 8 | 8 |
| 9 # Load functions and constants | 9 # --- BEGIN COMMON.SH BOILERPLATE --- |
| 10 . "$(dirname "$0")/common.sh" || exit 1 | 10 # Load common CrOS utilities. Inside the chroot this file is installed in |
| 11 . "$(dirname "$0")/chromeos-common.sh" || exit 1 | 11 # /usr/lib/crosutils. Outside the chroot we find it relative to the script's |
| 12 # location. |
| 13 find_common_sh() { |
| 14 local common_paths=(/usr/lib/crosutils $(dirname "$(readlink -f "$0")")) |
| 15 local path |
| 16 |
| 17 SCRIPT_ROOT= |
| 18 for path in "${common_paths[@]}"; do |
| 19 if [ -r "${path}/common.sh" ]; then |
| 20 SCRIPT_ROOT=${path} |
| 21 break |
| 22 fi |
| 23 done |
| 24 } |
| 25 |
| 26 find_common_sh |
| 27 . "${SCRIPT_ROOT}/common.sh" || (echo "Unable to load common.sh" && exit 1) |
| 28 # --- END COMMON.SH BOILERPLATE --- |
| 29 |
| 30 # Load functions and constants for chromeos-install |
| 31 [ -f /usr/lib/installer/chromeos-common.sh ] && \ |
| 32 INSTALLER_ROOT=/usr/lib/installer || \ |
| 33 INSTALLER_ROOT=$(dirname "$(readlink -f "$0")") |
| 34 |
| 35 . "${INSTALLER_ROOT}/chromeos-common.sh" || \ |
| 36 die "Unable to load chromeos-common.sh" |
| 12 | 37 |
| 13 # Needed for partoffset and partsize calls | 38 # Needed for partoffset and partsize calls |
| 14 locate_gpt | 39 locate_gpt |
| 15 | 40 |
| 16 # Script must be run inside the chroot. | 41 # Script must be run inside the chroot. |
| 17 restart_in_chroot_if_needed $* | 42 restart_in_chroot_if_needed "$@" |
| 18 | 43 |
| 19 DEFINE_string image "" "Device or an image path. Default: (empty)." | 44 DEFINE_string image "" "Device or an image path. Default: (empty)." |
| 20 | 45 |
| 21 # Parse command line. | 46 # Parse command line. |
| 22 FLAGS "$@" || exit 1 | 47 FLAGS "$@" || exit 1 |
| 23 eval set -- "${FLAGS_ARGV}" | 48 eval set -- "${FLAGS_ARGV}" |
| 24 | 49 |
| 25 if [ -z $FLAGS_image ] ; then | 50 if [ -z $FLAGS_image ] ; then |
| 26 die "Use --from to specify a device or an image file." | 51 die "Use --from to specify a device or an image file." |
| 27 fi | 52 fi |
| (...skipping 23 matching lines...) Expand all Loading... |
| 51 local rootfs_count=$(partsize "${FLAGS_image}" 3) | 76 local rootfs_count=$(partsize "${FLAGS_image}" 3) |
| 52 | 77 |
| 53 # TODO(tgao): use loop device to save 1GB in temp space | 78 # TODO(tgao): use loop device to save 1GB in temp space |
| 54 dd if="${FLAGS_image}" of=${KERNEL_IMG} bs=512 skip=${kernel_offset} \ | 79 dd if="${FLAGS_image}" of=${KERNEL_IMG} bs=512 skip=${kernel_offset} \ |
| 55 count=${kernel_count} &>/dev/null | 80 count=${kernel_count} &>/dev/null |
| 56 dd if="${FLAGS_image}" of=${ROOTFS_IMG} bs=512 skip=${rootfs_offset} \ | 81 dd if="${FLAGS_image}" of=${ROOTFS_IMG} bs=512 skip=${rootfs_offset} \ |
| 57 count=${rootfs_count} &>/dev/null | 82 count=${rootfs_count} &>/dev/null |
| 58 } | 83 } |
| 59 | 84 |
| 60 function cleanup() { | 85 function cleanup() { |
| 61 for i in ${KERNEL_IMG} ${ROOTFS_IMG} | 86 for i in ${KERNEL_IMG} ${ROOTFS_IMG}; do |
| 62 do | |
| 63 if [ ! -b ${i} ]; then | 87 if [ ! -b ${i} ]; then |
| 64 rm -f ${i} | 88 rm -f ${i} |
| 65 fi | 89 fi |
| 66 done | 90 done |
| 67 } | 91 } |
| 68 | 92 |
| 69 get_partitions | 93 get_partitions |
| 70 | 94 |
| 71 # Logic below extracted from src/platform/installer/chromeos-setimage | 95 # Logic below extracted from src/platform/installer/chromeos-setimage |
| 72 DUMP_KERNEL_CONFIG=/usr/bin/dump_kernel_config | 96 DUMP_KERNEL_CONFIG=/usr/bin/dump_kernel_config |
| (...skipping 18 matching lines...) Expand all Loading... |
| 91 | 115 |
| 92 cleanup | 116 cleanup |
| 93 | 117 |
| 94 if [ "${expected_hash}" != "${generated_hash}" ]; then | 118 if [ "${expected_hash}" != "${generated_hash}" ]; then |
| 95 warn "expected hash = ${expected_hash}" | 119 warn "expected hash = ${expected_hash}" |
| 96 warn "actual hash = ${generated_hash}" | 120 warn "actual hash = ${generated_hash}" |
| 97 die "Root filesystem has been modified unexpectedly!" | 121 die "Root filesystem has been modified unexpectedly!" |
| 98 else | 122 else |
| 99 info "Root filesystem checksum match!" | 123 info "Root filesystem checksum match!" |
| 100 fi | 124 fi |
| OLD | NEW |