flatcar-scripts/core_upload_update
2013-07-21 23:20:50 -07:00

78 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
# Copyright (c) 2013 The CoreOS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
SCRIPT_ROOT=$(dirname $(readlink -f "$0"))
# We have to simple-mindedly set GCLIENT_ROOT in case we're running from
# au-generator.zip because common.sh will fail while auto-detect it.
export GCLIENT_ROOT=$(readlink -f "${SCRIPT_ROOT}/../../")
. "${SCRIPT_ROOT}/common.sh" || exit 1
DEFINE_string image "${SRC_ROOT}/build/images/amd64-generic/latest/${COREOS_BASE_IMAGE_NAME}" \
"Path to the basic image (not qemu/xen/etc)"
DEFINE_string version "${COREOS_VERSION_STRING}" \
"Version number of this build."
DEFINE_string track "dev-channel" \
"Track that this update goes into."
DEFINE_string api_key "" \
"API secret key for access to the administrative interface."
DEFINE_string public_key "" \
"Path to the public RSA key that will sign this build."
DEFINE_string private_key "" \
"Path to the private RSA key that will sign this build."
DEFINE_string app_id "{e96281a6-d1af-4bde-9a0a-97b76e56dc57}" \
"GUID of the app that this update is for."
FLAGS_HELPS="usage: $SCRIPTNAME [flags]
Setting everything up for use\n
1) Run 'gsutil config' and use project id coreos.com:core-update-storage\n
2) Ensure core-admin is installed, it is a recent addition\n
NOTE: Use the coreos_image.bin not a qemu/xen/etc image for generating the
update.
"
# Parse flags
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
switch_to_strict_mode
[[ -z "${FLAGS_api_key}" ]] && die "--api_key is required"
[[ -z "${FLAGS_private_key}" ]] && die "--private_key is required"
[[ -z "${FLAGS_public_key}" ]] && die "--public_key is required"
# Add the current directory to $PATH if we seem to be from a au bundle
if ! which cros_generate_update_payload &>/dev/null; then
if [[ -e "${SCRIPT_ROOT}/cros_generate_update_payload" ]]; then
export PATH="${SCRIPT_ROOT}:${PATH}"
else
die_notrace "Cannot find cros_generate_update_payload"
fi
fi
OUTPUT_DIR=$(mktemp -d)
trap "rm -rf ${OUTPUT_DIR}" INT TERM EXIT
# Generate a payload and sign it with our private key
cros_generate_update_payload \
--image "${FLAGS_image}" \
--output "${OUTPUT_DIR}/update.gz" \
--metadata_output "${OUTPUT_DIR}/update.metadata" \
--private_key "${FLAGS_private_key}" \
--public_key "${FLAGS_public_key}" \
--outside_chroot
MD5SUM=$(md5sum ${FLAGS_image} | cut -f1 -d" ")
gsutil cp "${OUTPUT_DIR}/update.gz" \
gs://update-storage.core-os.net/${FLAGS_track}/$MD5SUM/update.gz
CORE_UPDATE_URL="https://core-api.appspot.com" core-admin new-version \
-k ${FLAGS_api_key} \
-a ${FLAGS_app_id} \
-v ${FLAGS_version} \
-m "${OUTPUT_DIR}/update.metadata" \
-t ${FLAGS_track} -p $MD5SUM "${OUTPUT_DIR}/update.gz"