blob: 2a8a7e80f91c6d514a676e6d4d6b251a629ea93c [file] [log] [blame]
# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# This script verifies if a chromeos rootfs is valid for activation, by running
# the chromeos-postinst script.
. "$(dirname "$0")/" || exit 1
set -e
rollback_changes() {
# don't stop, even if we encounter any issues
local failure_msg="WARNING: Failed to rollback some changes..."
if [ -n "$CGPT_CONFIG" ]; then
cgpt_restore_status "$CGPT_DEVICE" "$CGPT_CONFIG" || alert "$failure_msg"
cleanup() {
if [ -n "$NEED_ROLLBACK" ]; then
main() {
if [ "$#" != "1" ]; then
alert "Usage: $0 release_rootfs"
exit 1
local release_rootfs="$1"
local factory_rootfs="$(echo "$release_rootfs" | tr '35' '53')"
[ "$release_rootfs" != "$factory_rootfs" ] ||
die "Unknown type of device: $release_rootfs"
cgpt_init "$(device_remove_partno "$release_rootfs")" ||
die "Failed to initialize device: $release_rootfs"
# No matter what, revert cgpt changes.
# TODO(hungte) Using chromeos_invoke_postinst here is leaving a window where
# unexpected reboot or test exit may cause the system to boot into the release
# image. Currently "cgpt" is very close to the last step of postinst so it may
# be OK, but we should seek for better method for this, for example adding a
# "--nochange_boot_partition" to chromeos-postinst.
chromeos_invoke_postinst "$release_rootfs"
if chromeos_is_legacy_firmware; then
# Reverting legacy boot loaders -- only required if current system is using
# a legacy firmware. Setting legacy boot partition to "1" would prevent
# unexpected reboots during next chromeos_invoke_postinst to bring up
# release OS image.
cgpt boot -i "1" "$CGPT_DEVICE"
chromeos_invoke_postinst "$factory_rootfs"
trap cleanup EXIT
main "$@"