git: Add a script which will download the current version of binary files.

This script will be run by a git hook and download large(ish) binary files
from google storage. By not having the history of those files stored in git,
we avoid having to download enough information to recreate obsolete versions
of those files every time a checkout is created.

Change-Id: I6bc34da60b3f2eb74e4101e321aa29a9af4ca08a
diff --git a/update.sh b/update.sh
new file mode 100755
index 0000000..2e01121
--- /dev/null
+++ b/update.sh
@@ -0,0 +1,35 @@
+#!/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="$(sha1sum "${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