mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-07 13:06:59 +02:00
add(sdk_util.sh): Port basic SDK download logic to a shell library.
The current logic for downloading SDK tarballs is in cros_sdk and written in python which isn't super convenient for re-using in the rest of our shell scripts. This is a start of rewriting that logic into a re-usable library but does not yet replace the functionality in cros_sdk.
This commit is contained in:
parent
763b27bb7f
commit
59ef0901d3
60
sdk_lib/sdk_util.sh
Normal file
60
sdk_lib/sdk_util.sh
Normal file
@ -0,0 +1,60 @@
|
||||
#!/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.
|
||||
|
||||
# common.sh must be properly sourced before this file.
|
||||
[[ -n "${COREOS_SDK_VERSION}" ]] || exit 1
|
||||
|
||||
COREOS_SDK_ARCH="amd64" # We are unlikely to support anything else.
|
||||
COREOS_SDK_TARBALL="coreos-sdk-${COREOS_SDK_ARCH}-${COREOS_SDK_VERSION}.tar.bz2"
|
||||
COREOS_SDK_TARBALL_CACHE="${REPO_CACHE_DIR}/sdks"
|
||||
COREOS_SDK_TARBALL_PATH="${COREOS_SDK_TARBALL_CACHE}/${COREOS_SDK_TARBALL}"
|
||||
COREOS_SDK_URL_PREFIX="http://storage.core-os.net/coreos/sdk"
|
||||
COREOS_SDK_URL="${COREOS_SDK_URL_PREFIX}/${COREOS_SDK_ARCH}/${COREOS_SDK_VERSION}/${COREOS_SDK_TARBALL}"
|
||||
|
||||
# Download the current SDK tarball (if required) and verify digests/sig
|
||||
sdk_download_tarball() {
|
||||
if sdk_verify_digests; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
info "Downloading ${COREOS_SDK_TARBALL}"
|
||||
info "URL: ${COREOS_SDK_URL}"
|
||||
local suffix
|
||||
for suffix in "" ".DIGESTS"; do # TODO(marineam): download .asc
|
||||
wget --tries=3 --timeout=30 --continue \
|
||||
-O "${COREOS_SDK_TARBALL_PATH}${suffix}" \
|
||||
"${COREOS_SDK_URL}${suffix}" \
|
||||
|| die_notrace "SDK download failed!"
|
||||
done
|
||||
|
||||
sdk_verify_digests || die_notrace "SDK digest verification failed!"
|
||||
sdk_clean_cache
|
||||
}
|
||||
|
||||
sdk_verify_digests() {
|
||||
if [[ ! -f "${COREOS_SDK_TARBALL_PATH}" || \
|
||||
! -f "${COREOS_SDK_TARBALL_PATH}.DIGESTS" ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
# TODO(marineam): Add gpg signature verification too.
|
||||
|
||||
verify_digests "${COREOS_SDK_TARBALL_PATH}" || return 1
|
||||
}
|
||||
|
||||
sdk_clean_cache() {
|
||||
pushd "${COREOS_SDK_TARBALL_CACHE}" >/dev/null
|
||||
local filename
|
||||
for filename in *; do
|
||||
if [[ "${filename}" == "${COREOS_SDK_TARBALL}"* ]]; then
|
||||
continue
|
||||
fi
|
||||
info "Cleaning up ${filename}"
|
||||
# Not a big deal if this fails
|
||||
rm -f "${filename}" || true
|
||||
done
|
||||
popd >/dev/null
|
||||
}
|
Loading…
Reference in New Issue
Block a user