1#!/bin/bash 2# Copyright (C) 2019 The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16set -e 17 18echo "" 19echo "Downloading latest copy of test data" 20echo "" 21LATEST_ZIP="$(cat tools/install-build-deps | grep -o 'https://.*/perfetto/test-data-.*.zip')" 22curl -o /tmp/latest-test-data.zip $LATEST_ZIP 23 24echo "" 25echo "Extracting test data to temp folder" 26echo "" 27rm -rf /tmp/latest-test-data 2>/dev/null 28unzip /tmp/latest-test-data.zip -d /tmp/latest-test-data 29 30echo "" 31echo "Copying trace to temp folder" 32echo "" 33cp $1 /tmp/latest-test-data 34 35echo "" 36echo "Zipping file back up" 37echo "" 38NEW_TEST_DATA="test-data-$(date +%Y%m%d-%H%M%S).zip" 39CWD="$(pwd)" 40cd /tmp/latest-test-data 41zip -r /tmp/$NEW_TEST_DATA * 42cd $CWD 43 44echo "" 45echo "Uploading file to Google Cloud" 46echo "" 47gsutil cp /tmp/$NEW_TEST_DATA gs://perfetto/$NEW_TEST_DATA 48 49echo "" 50echo "Setting file to world readable" 51echo "" 52gsutil acl ch -u AllUsers:R gs://perfetto/$NEW_TEST_DATA 53 54echo "" 55echo "SHA-256 of file $NEW_TEST_DATA is" 56NEW_SHA=$(shasum -a 256 /tmp/$NEW_TEST_DATA | cut -c1-64) 57echo $NEW_SHA 58 59echo "" 60echo "Cleaning up leftover files" 61echo "" 62rm -r /tmp/latest-test-data 63rm /tmp/latest-test-data.zip 64rm /tmp/$NEW_TEST_DATA 65 66echo "" 67echo "Updating tools/install-build-deps" 68echo "" 69 70OLD_SHA=$(cat tools/install-build-deps | grep '/test-data-.*.zip' -A1 | tail -n1 | egrep -o '[a-f0-9]+') 71 72# Cannot easily use sed -i, it has different syntax on Linux vs Mac. 73cat tools/install-build-deps \ 74 | sed -e "s|/test-data-.*.zip|/$NEW_TEST_DATA|g" \ 75 | sed -e "s|$OLD_SHA|$NEW_SHA|g" \ 76 > tools/install-build-deps.tmp 77 78mv -f tools/install-build-deps.tmp tools/install-build-deps 79chmod 755 tools/install-build-deps 80 81echo "All done!" 82