blob: ff495e5ca586d85a801e6258f00d7ffd80d98496 [file] [log] [blame]
#!/bin/bash
# Copyright 2016 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -e
readonly SCRIPT_ROOT="$(cd $(dirname ${BASH_SOURCE[0]}) && pwd)"
readonly BUCKET="depthcharge"
function process_sha_file() {
local sha_file="${1}"
local base_file="${sha_file%.sha1}"
local stamp_file="${base_file}.stamp"
local requested_hash="$(cat "${sha_file}")"
local url="https://storage.googleapis.com/${BUCKET}/${requested_hash}"
if [[ ! -f "${stamp_file}" || "${requested_hash}" != "$(cat "${stamp_file}")" ]]; then
echo "Downloading ${base_file} (${requested_hash})..."
rm -f -- "${base_file}.tmp"
curl --progress-bar -continue-at=- --location --output "${base_file}.tmp" "${url}"
local actual_hash="$(shasum -a1 "${base_file}.tmp" | cut -d ' ' -f 1)"
if [[ "${actual_hash}" != "${requested_hash}" ]]; then
echo "${base_file} is corrupted."
else
mv -- "${base_file}.tmp" "${base_file}"
echo "${requested_hash}" > "${stamp_file}"
fi
fi
}
find "${SCRIPT_ROOT}" -name '*.sha1' | while read SHA; do
process_sha_file "${SHA}"
done