OLD | NEW |
(Empty) | |
| 1 #!/bin/bash |
| 2 |
| 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 |
| 5 # found in the LICENSE file. |
| 6 |
| 7 # Script to manipulate the tag files in the output of build_image |
| 8 |
| 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. |
| 11 . "$(dirname "$0")/../common.sh" |
| 12 . "$(dirname "$0")/../chromeos-common.sh" # for partoffset and partsize |
| 13 |
| 14 DEFINE_string from "chromiumos_image.bin" \ |
| 15 "Input file name of Chrome OS image to tag/stamp." |
| 16 DEFINE_boolean enable_update_firmware ${FLAGS_FALSE} \ |
| 17 "Tag to force updating firmware" |
| 18 DEFINE_boolean disable_update_firmware ${FLAGS_FALSE} \ |
| 19 "Remove firmware update tag" |
| 20 DEFINE_boolean enable_dev_mode ${FLAGS_FALSE} \ |
| 21 "Tag to enable developer mode" |
| 22 DEFINE_boolean disable_dev_mode ${FLAGS_FALSE} \ |
| 23 "Remove developer mode tag" |
| 24 |
| 25 # Parse command line |
| 26 FLAGS "$@" || exit 1 |
| 27 eval set -- "${FLAGS_ARGV}" |
| 28 |
| 29 # Abort on error |
| 30 set -e |
| 31 |
| 32 if [ -z $FLAGS_from ] || [ ! -f $FLAGS_from ] ; then |
| 33 echo "Error: invalid flag --from" |
| 34 exit 1 |
| 35 fi |
| 36 |
| 37 # Global variable to track if image is modified. |
| 38 g_modified=${FLAGS_FALSE} |
| 39 |
| 40 function process_tag() { |
| 41 # syntax: process_tag name file_path enable disable |
| 42 local tag_status_text |
| 43 |
| 44 if [ $3 = ${FLAGS_TRUE} -a $4 = ${FLAGS_TRUE} ]; then |
| 45 echo "Error: you cannot request to enable and disable tag '$1' at one time" |
| 46 exit 1 |
| 47 fi |
| 48 |
| 49 if [ -f "$2" ]; then |
| 50 tag_status_text="Enabled" |
| 51 if [ "$4" = "${FLAGS_TRUE}" ]; then |
| 52 # disable the tag |
| 53 sudo rm "$2" |
| 54 g_modified=${FLAGS_TRUE} |
| 55 tag_status_text="$tag_status_text => disabled" |
| 56 fi |
| 57 else |
| 58 tag_status_text="disabled" |
| 59 if [ "$3" = "${FLAGS_TRUE}" ]; then |
| 60 # enable the tag |
| 61 sudo touch "$2" |
| 62 g_modified=${FLAGS_TRUE} |
| 63 tag_status_text="$tag_status_text => Enabled" |
| 64 fi |
| 65 fi |
| 66 |
| 67 # report tag status |
| 68 echo "$1: $tag_status_text" |
| 69 } |
| 70 |
| 71 IMAGE=$( readlink -f ${FLAGS_from} ) |
| 72 IMAGE_DIR=$( dirname ${IMAGE} ) |
| 73 |
| 74 if [[ -z "${IMAGE}" || ! -f ${IMAGE} ]]; then |
| 75 echo "Missing required argument: --from (image to update)" |
| 76 usage |
| 77 exit 1 |
| 78 fi |
| 79 |
| 80 pushd ${IMAGE_DIR} >/dev/null |
| 81 if ! [[ -x ./unpack_partitions.sh && -x ./pack_partitions.sh ]]; then |
| 82 echo "Could not find image manipulation scripts (*pack_partitions.sh)." |
| 83 popd >/dev/null |
| 84 exit 1 |
| 85 fi |
| 86 |
| 87 mkdir -p ./rootfs |
| 88 mkdir -p ./stateful_part |
| 89 INSTALL_ROOT=./rootfs |
| 90 |
| 91 # we don't have tags in stateful partition yet, so comment it it now. |
| 92 |
| 93 ./unpack_partitions.sh ${IMAGE} 2>/dev/null |
| 94 #sudo mount -o loop part_1 stateful_part |
| 95 sudo mount -o loop part_3 rootfs |
| 96 #sudo mount --bind stateful_part/dev_image rootfs/usr/local |
| 97 #sudo mount --bind stateful_part/var rootfs/var |
| 98 |
| 99 # modify/list tags here |
| 100 process_tag "Update Firmware" \ |
| 101 ${INSTALL_ROOT}/root/.force_update_firmware \ |
| 102 ${FLAGS_enable_update_firmware} \ |
| 103 ${FLAGS_disable_update_firmware} |
| 104 process_tag "Developer Mode" \ |
| 105 ${INSTALL_ROOT}/root/.dev_mode \ |
| 106 ${FLAGS_enable_dev_mode} \ |
| 107 ${FLAGS_disable_dev_mode} |
| 108 |
| 109 #sudo umount rootfs/var |
| 110 #sudo umount rootfs/usr/local |
| 111 sudo umount rootfs |
| 112 #sudo umount stateful_part |
| 113 |
| 114 if [ $g_modified = ${FLAGS_TRUE} ]; then |
| 115 ./pack_partitions.sh ${IMAGE} 2>/dev/null |
| 116 echo "Image is modified. Please remember to resign your image." |
| 117 fi |
| 118 popd >/dev/null |
OLD | NEW |