diff --git a/scripts/image_signing/common.sh b/scripts/image_signing/common.sh index 0d15cb4f2e..893ef07dfa 100644 --- a/scripts/image_signing/common.sh +++ b/scripts/image_signing/common.sh @@ -6,6 +6,7 @@ # Determine script directory SCRIPT_DIR=$(dirname $0) +PROG=$(basename $0) GPT=cgpt # Read GPT table to find the starting location of a specific partition. diff --git a/scripts/image_signing/set_lsb_release.sh b/scripts/image_signing/set_lsb_release.sh new file mode 100755 index 0000000000..645e9870b7 --- /dev/null +++ b/scripts/image_signing/set_lsb_release.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +# Copyright (c) 2010 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# Customizes a Chrome OS release image by setting /etc/lsb-release values. + +# Usage: ./set_lsb_release.sh [ ] +# +# If executed with key/value parameters, sets = in +# /etc/lsb-release and then dumps /etc/lsb-release to stdout. If +# executed with no key/value, dumps /etc/lsb-release to stdout. Note +# that the order of the keyvals in /etc/lsb-release may not be +# preserved. + +# Load common constants and variables. +. "$(dirname "$0")/common.sh" + +set_lsb_release_keyval() { + local rootfs=$1 + local key=$2 + local value=$3 + echo "Setting '$key' to '$value'..." + local temp_lsb_release="$rootfs/etc/temp-lsb-release" + echo "$key=$value" | sudo tee "$temp_lsb_release" > /dev/null + grep -Ev "^$key=" "$rootfs/etc/lsb-release" \ + | sudo tee -a "$temp_lsb_release" > /dev/null + sudo mv -f "$temp_lsb_release" "$rootfs/etc/lsb-release" +} + +main() { + set -e + + local image=$1 + local key=$2 + local value=$3 + if [ $# -ne 1 ] && [ $# -ne 3 ]; then + echo "Usage: $PROG [ ]" + exit 1 + fi + + local rootfs=$(mktemp -d) + mount_image_partition "$image" 3 "$rootfs" + trap "sudo umount -d $rootfs; rm -rf $rootfs" EXIT + if [ -n "$key" ]; then + set_lsb_release_keyval "$rootfs" "$key" "$value" + touch "$image" # Updates the image modification time. + fi + echo === + cat "$rootfs/etc/lsb-release" + echo === + echo Done. +} + +main $@