diff options
author | Mike Frysinger <vapier@chromium.org> | 2013-02-05 00:22:55 -0500 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-02-05 12:32:33 -0800 |
commit | 5ede8c969878a8374a60b66922cb083db080b821 (patch) | |
tree | df2d826a10942730baff892e5fb0156f557fc5ab /scripts | |
parent | 5cfcab54375c93fec3f04cd1cb76ea2f5beaaf97 (diff) | |
download | vboot-5ede8c969878a8374a60b66922cb083db080b821.tar.gz |
set_lsb_release: enable batch modification
When setting a field, this script mounts the image, unmounts, mounts
it, then writes the field, then unmounts it. When setting 4 or 5
keys at once, this is quite a waste.
Tweak it so we only mount it once, and we can set multiple keys in
a single call by looping over the input args.
BUG=None
TEST=`./signing_unittests.py` passes
BRANCH=None
Change-Id: Id7dc4e8ef58113cc4632721851fcab04ef1e69eb
Reviewed-on: https://gerrit.chromium.org/gerrit/42601
Reviewed-by: Ryan Cui <rcui@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/image_signing/set_lsb_release.sh | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/scripts/image_signing/set_lsb_release.sh b/scripts/image_signing/set_lsb_release.sh index 5d859d81..9d0addd0 100755 --- a/scripts/image_signing/set_lsb_release.sh +++ b/scripts/image_signing/set_lsb_release.sh @@ -24,12 +24,9 @@ set_lsb_release_keyval() { main() { set -e - local image=$1 - local key=$2 - local value=$3 - if [ $# -ne 1 ] && [ $# -ne 3 ]; then + if [[ $(( $# % 2 )) -eq 0 ]]; then cat <<EOF -Usage: $PROG <image.bin> [<key> <value>] +Usage: $PROG <image.bin> [<key> <value> [<key> <value> ...]] Examples: @@ -47,15 +44,28 @@ EOF exit 1 fi + local image=$1 + shift local rootfs=$(make_temp_dir) - mount_image_partition_ro "$image" 3 "$rootfs" - if [ -n "$key" ]; then - sudo umount "$rootfs" - mount_image_partition "$image" 3 "$rootfs" - set_lsb_release_keyval "$rootfs" "$key" "$value" - touch "$image" # Updates the image modification time. + + # If there are no key/value pairs to process, we don't need write access. + if [[ $# -eq 0 ]]; then + mount_image_partition_ro "${image}" 3 "${rootfs}" + else + mount_image_partition "${image}" 3 "${rootfs}" + touch "${image}" # Updates the image modification time. fi - cat "$rootfs/etc/lsb-release" + + # Process all the key/value pairs. + local key value + while [[ $# -ne 0 ]]; do + key=$1 value=$2 + shift 2 + set_lsb_release_keyval "${rootfs}" "${key}" "${value}" + done + + # Dump the final state. + cat "${rootfs}/etc/lsb-release" } main "$@" |