| 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 manipulate the tag files in the output of build_image | 7 # Script to manipulate the tag files in the output of build_image |
| 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. |
| 11 . "$(dirname "$0")/common.sh" | 11 . "$(dirname "$0")/common.sh" |
| 12 | 12 |
| 13 load_shflags |
| 14 |
| 13 DEFINE_string from "chromiumos_image.bin" \ | 15 DEFINE_string from "chromiumos_image.bin" \ |
| 14 "Input file name of Chrome OS image to tag/stamp." | 16 "Input file name of Chrome OS image to tag/stamp." |
| 15 DEFINE_string dev_mode "" \ | 17 DEFINE_string dev_mode "" \ |
| 16 "(build-info) Tag as a developer mode build (1 to enable, 0 to disable)" | 18 "(build-info) Tag as a developer mode build (1 to enable, 0 to disable)" |
| 17 DEFINE_string update_firmware "" \ | 19 DEFINE_string update_firmware "" \ |
| 18 "(auto-update) Force updating firmware (1 to enable, 0 to disable)" | 20 "(auto-update) Force updating firmware (1 to enable, 0 to disable)" |
| 19 DEFINE_string forget_usernames "" \ | 21 DEFINE_string forget_usernames "" \ |
| 20 "(session-manager) Forget usernames (1 to enable, 0 to disable)" | 22 "(session-manager) Forget usernames (1 to enable, 0 to disable)" |
| 21 DEFINE_string leave_core "" \ | 23 DEFINE_string leave_core "" \ |
| 22 "(crash-reporter) Leave core dumps (1 to enable, 0 to disable)" | 24 "(crash-reporter) Leave core dumps (1 to enable, 0 to disable)" |
| 25 DEFINE_string crosh_workarounds "" \ |
| 26 "(crosh) Keep crosh (1 to keep, 0 to disable *irreversible*)" |
| 27 |
| 28 # Parameters for manipulating /etc/lsb-release. |
| 29 DEFINE_boolean remove_test_label false \ |
| 30 "(build-info) Remove 'test' suffix in /etc/lsb-release" |
| 31 DEFINE_boolean change_dev_to_beta false \ |
| 32 "(build-info) Change 'dev' -> 'beta' in /etc/lsb-release" |
| 33 |
| 23 | 34 |
| 24 # TODO(hungte) we can add factory_installer and factory_test, | 35 # TODO(hungte) we can add factory_installer and factory_test, |
| 25 # but I don't see any reason to tweak/check these values. | 36 # but I don't see any reason to tweak/check these values. |
| 26 | 37 |
| 27 # Parse command line | 38 # Parse command line. |
| 28 FLAGS "$@" || exit 1 | 39 FLAGS "$@" || exit 1 |
| 29 eval set -- "${FLAGS_ARGV}" | 40 eval set -- "${FLAGS_ARGV}" |
| 30 | 41 |
| 31 # Abort on error | 42 # Abort on error. |
| 32 set -e | 43 set -e |
| 33 | 44 |
| 34 if [ -z "${FLAGS_from}" ] || [ ! -s "${FLAGS_from}" ] ; then | 45 if [ -z "${FLAGS_from}" ] || [ ! -s "${FLAGS_from}" ] ; then |
| 35 echo "Error: need a valid file by --from" | 46 echo "Error: need a valid file by --from" |
| 36 exit 1 | 47 exit 1 |
| 37 fi | 48 fi |
| 38 | 49 |
| 39 # Global variable to track if image is modified. | 50 # Global variable to track if the image is modified. |
| 40 g_modified=${FLAGS_FALSE} | 51 g_modified=${FLAGS_FALSE} |
| 41 | 52 |
| 42 # Processes (enable, disable, or simply report) a tag file. | 53 # Processes (enable, disable, or simply report) a tag file. |
| 43 # Args: DO_MODIFICATION NAME ROOT TAG_FILE ACTION | 54 # Args: DO_MODIFICATION NAME ROOT TAG_FILE ACTION |
| 44 # | 55 # |
| 45 # When DO_MODIFICATION=${FLAGS_TRUE}, | 56 # When DO_MODIFICATION=${FLAGS_TRUE}, |
| 46 # Creates (ACTION=1) the TAG_FILE in ROOT, or | 57 # Creates (ACTION=1) the TAG_FILE in ROOT, or |
| 47 # removes (ACTION=0) the TAG_FILE in ROOT, then | 58 # removes (ACTION=0) the TAG_FILE in ROOT, then |
| 48 # reports the status (and change) to the tag file. | 59 # reports the status (and change) to the tag file. |
| 49 # When DO_MODIFICATION=${FLAGS_FALSE}, | 60 # When DO_MODIFICATION=${FLAGS_FALSE}, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 "(session-manager) forget_usernames" \ | 145 "(session-manager) forget_usernames" \ |
| 135 "${rootfs}" \ | 146 "${rootfs}" \ |
| 136 /root/.forget_usernames \ | 147 /root/.forget_usernames \ |
| 137 "${FLAGS_forget_usernames}" | 148 "${FLAGS_forget_usernames}" |
| 138 | 149 |
| 139 process_tag "${do_modification}" \ | 150 process_tag "${do_modification}" \ |
| 140 "(crash-reporter) leave_core" \ | 151 "(crash-reporter) leave_core" \ |
| 141 "${rootfs}" \ | 152 "${rootfs}" \ |
| 142 /root/.leave_core \ | 153 /root/.leave_core \ |
| 143 "${FLAGS_leave_core}" | 154 "${FLAGS_leave_core}" |
| 155 |
| 156 process_tag "${do_modification}" \ |
| 157 "(crosh) crosh_workarounds" \ |
| 158 "${rootfs}" \ |
| 159 /usr/bin/crosh-workarounds \ |
| 160 "${FLAGS_crosh_workarounds}" |
| 144 } | 161 } |
| 145 | 162 |
| 163 # Iterates through all options for manipulating the lsb-release. |
| 164 # Args: ROOTFS DO_MODIFICATION |
| 165 process_all_lsb_mods() { |
| 166 local rootfs="$1" |
| 167 local do_modifications="$2" |
| 168 if [ ${FLAGS_remove_test_label} = ${FLAGS_TRUE} ]; then |
| 169 if grep -wq "test" ${rootfs}/etc/lsb-release; then |
| 170 g_modified=${FLAGS_TRUE} |
| 171 fi |
| 172 if [ ${do_modifications} = ${FLAGS_TRUE} ]; then |
| 173 sed -i 's/\btest\b//' "${rootfs}/etc/lsb-release" && |
| 174 echo "Test Label removed from /etc/lsb-release" |
| 175 fi |
| 176 fi |
| 177 |
| 178 if [ ${FLAGS_change_dev_to_beta} = ${FLAGS_TRUE} ]; then |
| 179 if grep -wq "dev" ${rootfs}/etc/lsb-release; then |
| 180 g_modified=${FLAGS_TRUE} |
| 181 fi |
| 182 if [ ${do_modifications} = ${FLAGS_TRUE} ]; then |
| 183 sed -i 's/\bdev\b/beta/' "${rootfs}/etc/lsb-release" && |
| 184 echo "Dev Channel Label was changed to Beta" |
| 185 fi |
| 186 fi |
| 187 } |
| 188 |
| 189 |
| 146 IMAGE=$(readlink -f "${FLAGS_from}") | 190 IMAGE=$(readlink -f "${FLAGS_from}") |
| 147 if [[ -z "${IMAGE}" || ! -f "${IMAGE}" ]]; then | 191 if [[ -z "${IMAGE}" || ! -f "${IMAGE}" ]]; then |
| 148 echo "Missing required argument: --from (image to update)" | 192 echo "Missing required argument: --from (image to update)" |
| 149 usage | 193 usage |
| 150 exit 1 | 194 exit 1 |
| 151 fi | 195 fi |
| 152 | 196 |
| 153 # First round, mount as read-only and check if we read any modification. | 197 # First round, mount as read-only and check if we need any modifications. |
| 154 rootfs=$(make_temp_dir) | 198 rootfs=$(make_temp_dir) |
| 155 mount_image_partition_ro "${IMAGE}" 3 "${rootfs}" | 199 mount_image_partition_ro "${IMAGE}" 3 "${rootfs}" |
| 156 | 200 |
| 157 # we don't have tags in stateful partition yet... | 201 # we don't have tags in stateful partition yet... |
| 158 # stateful_dir=$(make_temp_dir) | 202 # stateful_dir=$(make_temp_dir) |
| 159 # mount_image_partition ${IMAGE} 1 ${stateful_dir} | 203 # mount_image_partition ${IMAGE} 1 ${stateful_dir} |
| 160 | 204 |
| 161 process_all_tags "${rootfs}" ${FLAGS_FALSE} | 205 process_all_tags "${rootfs}" ${FLAGS_FALSE} |
| 206 process_all_lsb_mods "${rootfs}" ${FLAGS_FALSE} |
| 162 | 207 |
| 163 if [ ${g_modified} = ${FLAGS_TRUE} ]; then | 208 if [ ${g_modified} = ${FLAGS_TRUE} ]; then |
| 164 # remount as RW (we can't use mount -o rw,remount because of loop device) | 209 # remount as RW (we can't use mount -o rw,remount because of loop device) |
| 165 sudo umount -d "${rootfs}" | 210 sudo umount -d "${rootfs}" |
| 166 mount_image_partition "${IMAGE}" 3 "${rootfs}" | 211 mount_image_partition "${IMAGE}" 3 "${rootfs}" |
| 167 | 212 |
| 168 # Second round, apply the modification to image. | 213 # second round, apply the modification to image. |
| 169 process_all_tags "${rootfs}" ${FLAGS_TRUE} | 214 process_all_tags "${rootfs}" ${FLAGS_TRUE} |
| 215 process_all_lsb_mods "${rootfs}" ${FLAGS_TRUE} |
| 170 | 216 |
| 171 # this is supposed to be automatically done in mount_image_partition, | 217 # this is supposed to be automatically done in mount_image_partition, |
| 172 # but it's no harm to explicitly make it again here. | 218 # but it's no harm to explicitly make it again here. |
| 173 tag_as_needs_to_be_resigned "${rootfs}" | 219 tag_as_needs_to_be_resigned "${rootfs}" |
| 174 echo "IMAGE IS MODIFIED. PLEASE REMEMBER TO RESIGN YOUR IMAGE." | 220 echo "IMAGE IS MODIFIED. PLEASE REMEMBER TO RESIGN YOUR IMAGE." |
| 175 else | 221 else |
| 176 echo "Image is not modified." | 222 echo "Image is not modified." |
| 177 fi | 223 fi |
| OLD | NEW |