keygeneration: add some output helpers

These use the same forms as in other shell projects in CrOS.

BUG=b:35587169
TEST=ran create_new_android_keys.sh and new output works
BRANCH=None

Change-Id: Id75fd77203795d7837537f12ab948376a7ad105e
Reviewed-on: https://chromium-review.googlesource.com/520786
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
This commit is contained in:
Mike Frysinger
2017-06-01 11:03:50 -04:00
committed by chrome-bot
parent de4cefc915
commit fda1300464
4 changed files with 35 additions and 13 deletions

View File

@@ -8,7 +8,7 @@
usage() {
cat <<EOF
Usage: ${0##*/} <number of loem keys to add>
Usage: ${PROG} <number of loem keys to add>
If the existing keyset is not set up for loem usage, it will be converted.
@@ -52,8 +52,7 @@ main() {
local num_keys highest_key k
if [[ ! -e ${VERSION_FILE} ]]; then
echo "missing ${VERSION_FILE} in ${PWD}; please create one" >&2
exit 1
die "missing ${VERSION_FILE} in ${PWD}; please create one"
fi
firmware_key_version=$(get_version "firmware_key_version")

View File

@@ -6,6 +6,29 @@
# Common key generation functions.
SCRIPT_DIR="$(dirname "$(readlink -f -- "$0")")"
PROG=$(basename "$0")
CROS_LOG_PREFIX="${PROG}: "
# Prints an informational message.
info() {
echo "${CROS_LOG_PREFIX}INFO: $*" >&2
}
# Prints a warning message.
warn() {
echo "${CROS_LOG_PREFIX}WARNING: $*" >&2
}
# Prints an error message.
error() {
echo "${CROS_LOG_PREFIX}ERROR: $*" >&2
}
# Print an error message and then exit the script.
die() {
error "$@"
exit 1
}
# Algorithm ID mappings:
RSA1024_SHA1_ALGOID=0

View File

@@ -4,11 +4,12 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -e
# Load common constants and functions.
. "$(dirname "$0")/common.sh"
usage() {
cat <<EOF
Usage: $0 DIR
Usage: ${PROG} DIR
Generate Android's 4 framework key pairs at DIR. For detail, please refer to
"Certificates and private keys" and "Manually generating keys" in
@@ -17,8 +18,7 @@ https://source.android.com/devices/tech/ota/sign_builds.html.
EOF
if [[ $# -ne 0 ]]; then
echo "ERROR: $*" >&2
exit 1
die "$*"
else
exit 0
fi
@@ -48,6 +48,8 @@ make_pair() {
}
main() {
set -e
local dir
while [[ $# -gt 0 ]]; do
@@ -65,7 +67,7 @@ main() {
done
if [[ $# -ne 1 ]]; then
usage "Invalid argument."
usage "Missing output directory"
fi
dir=$1

View File

@@ -11,7 +11,7 @@
usage() {
cat <<EOF
Usage: $0 [options]
Usage: ${PROG} [options]
Options:
--devkeyblock Also generate developer firmware keyblock and data key
@@ -26,8 +26,7 @@ Options:
EOF
if [[ $# -ne 0 ]]; then
echo "ERROR: unknown option $*" >&2
exit 1
die "unknown option $*"
else
exit 0
fi
@@ -86,8 +85,7 @@ main() {
output_dir="$2"
setperms="true"
if [[ -d "${output_dir}" ]]; then
echo "ERROR: output dir (${output_dir}) already exists" >&2
exit 1
die "output dir (${output_dir}) already exists"
fi
shift
;;