Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: scripts/image_signing/set_lsb_release.sh

Issue 3164010: Fix set_lsb_release.sh issues with handling spaces in arguments. (Closed) Base URL: http://src.chromium.org/git/vboot_reference.git
Patch Set: Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 # Customizes a Chrome OS release image by setting /etc/lsb-release values. 7 # Customizes a Chrome OS release image by setting /etc/lsb-release values.
8 8
9 # Usage: ./set_lsb_release.sh <image.bin> [<key> <value>]
10 #
11 # If executed with key/value parameters, sets <key>=<value> in
12 # /etc/lsb-release and then dumps /etc/lsb-release to stdout. If
13 # executed with no key/value, dumps /etc/lsb-release to stdout. Note
14 # that the order of the keyvals in /etc/lsb-release may not be
15 # preserved.
16
17 # Load common constants and variables. 9 # Load common constants and variables.
18 . "$(dirname "$0")/common.sh" 10 . "$(dirname "$0")/common.sh"
19 11
20 set_lsb_release_keyval() { 12 set_lsb_release_keyval() {
21 local rootfs=$1 13 local rootfs=$1
22 local key=$2 14 local key=$2
23 local value=$3 15 local value=$3
24 echo "Setting '$key' to '$value'..."
25 local temp_lsb_release="$rootfs/etc/temp-lsb-release" 16 local temp_lsb_release="$rootfs/etc/temp-lsb-release"
26 echo "$key=$value" | sudo tee "$temp_lsb_release" > /dev/null 17 echo "$key=$value" | sudo tee "$temp_lsb_release" > /dev/null
27 grep -Ev "^$key=" "$rootfs/etc/lsb-release" \ 18 grep -Ev "^$key=" "$rootfs/etc/lsb-release" \
28 | sudo tee -a "$temp_lsb_release" > /dev/null 19 | sudo tee -a "$temp_lsb_release" > /dev/null
29 sudo mv -f "$temp_lsb_release" "$rootfs/etc/lsb-release" 20 sudo sort -o "$rootfs/etc/lsb-release" "$temp_lsb_release"
21 sudo rm -f "$temp_lsb_release"
30 } 22 }
31 23
32 main() { 24 main() {
33 set -e 25 set -e
34 26
35 local image=$1 27 local image=$1
36 local key=$2 28 local key=$2
37 local value=$3 29 local value=$3
38 if [ $# -ne 1 ] && [ $# -ne 3 ]; then 30 if [ $# -ne 1 ] && [ $# -ne 3 ]; then
39 echo "Usage: $PROG <image.bin> [<key> <value>]" 31 cat <<EOF
32 Usage: $PROG <image.bin> [<key> <value>]
33
34 Examples:
35
36 $ $PROG chromiumos_image.bin
37
38 Dumps /etc/lsb-release from chromiumos_image.bin to stdout.
39
40 $ $PROG chromiumos_image.bin CHROMEOS_RELEASE_DESCRIPTION "New description"
41
42 Sets the CHROMEOS_RELEASE_DESCRIPTION key's value to "New description"
43 in /etc/lsb-release in chromiumos_image.bin, sorts the keys and dumps
44 the updated file to stdout.
45
46 EOF
40 exit 1 47 exit 1
41 fi 48 fi
42 49
43 local rootfs=$(mktemp -d) 50 local rootfs=$(mktemp -d)
44 mount_image_partition "$image" 3 "$rootfs" 51 mount_image_partition "$image" 3 "$rootfs"
45 trap "sudo umount -d $rootfs; rm -rf $rootfs" EXIT 52 trap "sudo umount -d $rootfs; rm -rf $rootfs" EXIT
46 if [ -n "$key" ]; then 53 if [ -n "$key" ]; then
47 set_lsb_release_keyval "$rootfs" "$key" "$value" 54 set_lsb_release_keyval "$rootfs" "$key" "$value"
48 touch "$image" # Updates the image modification time. 55 touch "$image" # Updates the image modification time.
49 fi 56 fi
50 echo ===
51 cat "$rootfs/etc/lsb-release" 57 cat "$rootfs/etc/lsb-release"
52 echo ===
53 echo Done.
54 } 58 }
55 59
56 main $@ 60 main "$@"
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698