• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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# Customizes a Chrome OS release image by setting /etc/lsb-release values.
8
9# Load common constants and variables.
10. "$(dirname "$0")/common.sh"
11
12set_lsb_release_keyval() {
13  local rootfs=$1
14  local key=$2
15  local value=$3
16  local temp_lsb_release="$rootfs/etc/temp-lsb-release"
17  echo "$key=$value" | sudo tee "$temp_lsb_release" > /dev/null
18  grep -Ev "^$key=" "$rootfs/etc/lsb-release" \
19    | sudo tee -a "$temp_lsb_release" > /dev/null
20  sudo sort -o "$rootfs/etc/lsb-release" "$temp_lsb_release"
21  sudo rm -f "$temp_lsb_release"
22}
23
24main() {
25  set -e
26
27  if [[ $(( $# % 2 )) -eq 0 ]]; then
28    cat <<EOF
29Usage: $PROG <image.bin> [<key> <value> [<key> <value> ...]]
30
31Examples:
32
33$ $PROG chromiumos_image.bin
34
35Dumps /etc/lsb-release from chromiumos_image.bin to stdout.
36
37$ $PROG chromiumos_image.bin CHROMEOS_RELEASE_DESCRIPTION "New description"
38
39Sets the CHROMEOS_RELEASE_DESCRIPTION key's value to "New description"
40in /etc/lsb-release in chromiumos_image.bin, sorts the keys and dumps
41the updated file to stdout.
42
43EOF
44    exit 1
45  fi
46
47  local image=$1
48  shift
49  local rootfs=$(make_temp_dir)
50
51  # If there are no key/value pairs to process, we don't need write access.
52  if [[ $# -eq 0 ]]; then
53    mount_image_partition_ro "${image}" 3 "${rootfs}"
54  else
55    mount_image_partition "${image}" 3 "${rootfs}"
56    touch "${image}"  # Updates the image modification time.
57  fi
58
59  # Process all the key/value pairs.
60  local key value
61  while [[ $# -ne 0 ]]; do
62    key=$1 value=$2
63    shift 2
64    set_lsb_release_keyval "${rootfs}" "${key}" "${value}"
65  done
66
67  # Dump the final state.
68  cat "${rootfs}/etc/lsb-release"
69}
70
71main "$@"
72