1#!/bin/bash
2# Find builds here:
3# https://ci.android.com/builds/branches/aosp-main/grid
4set -e
5
6# Change directory to cuttlefish_prebuilts
7# (assumes the script is at cuttlefish_prebuilts/scripts/update-trusty)
8cd "$(dirname $(dirname "$(realpath $0)"))"
9
10if [ $# == 1 ]
11then
12build=$1
13else
14	echo "Usage: $0 <build>"
15	exit 1
16fi
17
18download_trusty_file()
19{
20  local target=$1
21  local elf_file=$2
22
23  local ci_url="https://ci.android.com/builds/submitted/${build}/${target}/latest/raw"
24  local out_file="trusty/$elf_file"
25  echo "Downloading $elf_file..."
26  curl -fL "$ci_url/$elf_file" -o $out_file
27
28  echo "Adding $elf_file to current branch"
29  git add $out_file
30}
31
32mkdir -p trusty
33
34download_trusty_file "trusty_generic_x86_64" "generic-x86_64.lk.elf"
35download_trusty_file "trusty_generic_x86_64_test" "generic-x86_64-test.lk.elf"
36
37echo "Committing build $build..."
38git commit -m "Update Trusty prebuilts to $build
39
40Test: Presubmit"
41
42topic="trusty_cf_prebuilts_$build"
43echo "Uploading topic $topic"
44repo upload -c . --topic=$topic
45