image_signing: unify board extraction logic from lsb-release

We had two places extracting the board value from lsb-release and parsing
the output by hand.  Unify them to use the same parsing logic to avoid
desynchronized behavior.

We also create a new get_boardvar_from_lsb_release helper to unify the
board name -> variable name mangling logic.

BUG=chromium:667192
TEST=`./security_test_image --board samus` still detects the correct board
BRANCH=None

Change-Id: If88a8ae59b9c9fd45ddd796653a0173ed0186d2d
Reviewed-on: https://chromium-review.googlesource.com/414224
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
This commit is contained in:
Mike Frysinger
2016-11-23 12:22:29 -05:00
committed by chrome-bot
parent c66cbc3440
commit 1e9245dfff
4 changed files with 33 additions and 29 deletions

View File

@@ -75,14 +75,28 @@ die() {
exit 1
}
# Extract and return board name from /etc/lsb-release.
# Args: rootfs
# Usage: lsbval path-to-lsb-file key
# Returns the value for the given lsb-release file variable.
lsbval() {
local lsbfile="$1"
local key="$2"
grep "^${key}=" "${lsbfile}" | sed "s/^${key}=//"
}
# Usage: get_board_from_lsb_release rootfs
# Returns the exact board name from /etc/lsb-release. This may contain
# dashes or other characters not suitable for variable names. See the
# next function for that.
get_board_from_lsb_release() {
local rootfs=$1
# The cuts turn e.g. x86-foo as a well as x86-foo-pvtkeys into x86_foo.
local board=$(grep CHROMEOS_RELEASE_BOARD= "${rootfs}/etc/lsb-release" | \
cut -d = -f 2 | cut -d - -f 1,2 --output-delimiter=_)
echo "${board}"
local rootfs="$1"
lsbval "${rootfs}/etc/lsb-release" CHROMEOS_RELEASE_BOARD
}
# Usage: get_boardvar_from_lsb_release rootfs
# Returns the board name from /etc/lsb-release in a mangled form that can
# be used in variable names. e.g. dashes are turned into underscores.
get_boardvar_from_lsb_release() {
get_board_from_lsb_release "$@" | sed 's:[-]:_:g'
}
# This will override the trap set in common_minmal.sh