Checking in script to import new version from build server

Bug: 155906507
Test: ./import.sh 6508549

Change-Id: I1eef6568eba9a7ff96079477356448015cbf23ec
diff --git a/update.sh b/update.sh
new file mode 100755
index 0000000..ae9590f
--- /dev/null
+++ b/update.sh
@@ -0,0 +1,47 @@
+#!/bin/bash -v
+
+# Updates prebuilts/jdk/jdk11 from build server.
+# Usage:
+#    $ cd <REPO>/prebuilts/jdk/jdk11
+#    $ repo start jdk11_update .
+#    $ update-jdk11.sh <BUILD_NUMBER>
+#    $ repo upload --cbr .
+
+
+BUILD_NUMBER="${1:?Specify build number}"
+LINUX_ZIP=/tmp/$$.linux.zip
+DARWIN_ZIP=/tmp/$$.darwin.zip
+
+FETCH_ARTIFACT=/google/data/ro/projects/android/fetch_artifact
+cd "${ANDROID_BUILD_TOP:?ANDROID_BUILD_TOP must be set, run lunch first}"/prebuilts/jdk/jdk11
+
+rm -rf staging
+mkdir -p staging
+
+$FETCH_ARTIFACT --bid ${BUILD_NUMBER} --disable_progressbar --target linux_openjdk11 jdk.zip ${LINUX_ZIP}
+$FETCH_ARTIFACT --bid ${BUILD_NUMBER} --disable_progressbar --target darwin_mac_openjdk11 jdk.zip ${DARWIN_ZIP}
+$FETCH_ARTIFACT --bid ${BUILD_NUMBER} --disable_progressbar --target linux_openjdk11 manifest_${BUILD_NUMBER}.xml staging/manifest.xml
+
+rm -rf staging/linux-x86
+mkdir -p staging/linux-x86
+(cd staging/linux-x86; unzip -q ${LINUX_ZIP})
+touch staging/linux-x86/MODULE_LICENSE_GPL
+
+rm -rf staging/darwin-x86
+mkdir staging/darwin-x86
+(cd staging/darwin-x86; unzip -q ${DARWIN_ZIP})
+touch staging/darwin-x86/MODULE_LICENSE_GPL
+
+rm -f ${LINUX_ZIP} ${DARWIN_ZIP}
+
+version=$(staging/linux-x86/bin/java -version 2>&1 | grep "OpenJDK Runtime Environment" | sed -e 's/.*(\(.*\))/\1/')
+
+# Commit to staging
+git add staging
+git commit -m "Add JDK ${version} to staging
+
+Test: none"
+
+git rm -rf linux-x86 darwin-x86 manifest.xml
+git mv staging/* .
+git commit -m "Switch to JDK $version" --edit