Hal Canary | 23fda7a | 2018-01-23 09:22:38 +0000 | [diff] [blame] | 1 | #! /bin/sh |
| 2 | |
| 3 | # Copyright 2018 Google Inc. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | |
| 7 | set -e |
| 8 | |
Hal Canary | ce243ba | 2018-01-30 16:08:17 -0500 | [diff] [blame] | 9 | BASE_DIR='platform_tools/android/apps/skqp/src/main/assets' |
Hal Canary | ac7f23c | 2018-11-26 14:07:41 -0500 | [diff] [blame] | 10 | PATH_LIST='gmkb' |
Hal Canary | ce243ba | 2018-01-30 16:08:17 -0500 | [diff] [blame] | 11 | BUCKET=skia-skqp-assets |
| 12 | |
Hal Canary | 23fda7a | 2018-01-23 09:22:38 +0000 | [diff] [blame] | 13 | EXTANT="$(mktemp "${TMPDIR:-/tmp}/extant.XXXXXXXXXX")" |
Hal Canary | ce243ba | 2018-01-30 16:08:17 -0500 | [diff] [blame] | 14 | gsutil ls gs://$BUCKET/ | sed "s|^gs://$BUCKET/||" > "$EXTANT" |
Hal Canary | 23fda7a | 2018-01-23 09:22:38 +0000 | [diff] [blame] | 15 | |
| 16 | upload() { |
| 17 | MD5=$(md5sum < "$1" | head -c 32) |
| 18 | if ! grep -q "$MD5" "$EXTANT"; then |
Hal Canary | ce243ba | 2018-01-30 16:08:17 -0500 | [diff] [blame] | 19 | URL="gs://${BUCKET}/$MD5" |
Hal Canary | 8d4a9f0 | 2018-01-23 14:44:27 -0500 | [diff] [blame] | 20 | gsutil cp "$1" "$URL" > /dev/null 2>&1 & |
Hal Canary | 23fda7a | 2018-01-23 09:22:38 +0000 | [diff] [blame] | 21 | fi |
| 22 | echo $MD5 |
| 23 | } |
| 24 | |
Hal Canary | ce243ba | 2018-01-30 16:08:17 -0500 | [diff] [blame] | 25 | size() { gsutil du -s gs://$BUCKET | awk '{print $1}'; } |
| 26 | |
| 27 | cd "$(dirname "$0")/../../$BASE_DIR" |
Hal Canary | 23fda7a | 2018-01-23 09:22:38 +0000 | [diff] [blame] | 28 | |
| 29 | rm -f files.checksum |
| 30 | |
| 31 | FILES="$(mktemp "${TMPDIR:-/tmp}/files.XXXXXXXXXX")" |
| 32 | |
| 33 | : > "$FILES" |
| 34 | |
Hal Canary | ce243ba | 2018-01-30 16:08:17 -0500 | [diff] [blame] | 35 | COUNT=$(find $PATH_LIST -type f | wc -l) |
Hal Canary | 23fda7a | 2018-01-23 09:22:38 +0000 | [diff] [blame] | 36 | INDEX=1 |
Hal Canary | 8d4a9f0 | 2018-01-23 14:44:27 -0500 | [diff] [blame] | 37 | SHARD_COUNT=32 |
| 38 | |
Hal Canary | ce243ba | 2018-01-30 16:08:17 -0500 | [diff] [blame] | 39 | SIZE=$(size) |
| 40 | find $PATH_LIST -type f | sort | while IFS= read -r FILENAME; do |
Hal Canary | 23fda7a | 2018-01-23 09:22:38 +0000 | [diff] [blame] | 41 | printf '\r %d / %d ' "$INDEX" "$COUNT" |
Hal Canary | 23fda7a | 2018-01-23 09:22:38 +0000 | [diff] [blame] | 42 | if ! [ -f "$FILENAME" ]; then |
| 43 | echo error [${FILENAME}] >&2; |
| 44 | exit 1; |
| 45 | fi |
| 46 | case "$FILENAME" in *\;*) echo bad filename: $FILENAME >&2; exit 1;; esac |
| 47 | MD5=$(upload "$FILENAME") |
| 48 | printf '%s;%s\n' "$MD5" "$FILENAME" >> "$FILES" |
Hal Canary | 23fda7a | 2018-01-23 09:22:38 +0000 | [diff] [blame] | 49 | |
Hal Canary | 8d4a9f0 | 2018-01-23 14:44:27 -0500 | [diff] [blame] | 50 | if [ $(($INDEX % $SHARD_COUNT)) = 0 ]; then |
| 51 | wait |
| 52 | fi |
| 53 | INDEX=$(( $INDEX + 1)) |
| 54 | done |
| 55 | printf '\rdone \n' |
Hal Canary | 23fda7a | 2018-01-23 09:22:38 +0000 | [diff] [blame] | 56 | upload "$FILES" > files.checksum |
Hal Canary | 3da15bb | 2018-01-23 14:52:58 -0500 | [diff] [blame] | 57 | wait |
Hal Canary | 23fda7a | 2018-01-23 09:22:38 +0000 | [diff] [blame] | 58 | |
Hal Canary | ce243ba | 2018-01-30 16:08:17 -0500 | [diff] [blame] | 59 | D=$(( $(size) - $SIZE )) |
| 60 | printf 'Added %d bytes to %s, %d%%\n' $D $BUCKET $(( $D * 100 / $SIZE )) |
| 61 | |
| 62 | rm "$EXTANT" |