update_gpu_drivers: Remove call to equery-${BOARD}

The next CL will fetch the prebuilt from Google Storage, and allow
updating the prebuilt without having to run setup_board for the
target ${BOARD}.

Remove code that relies on equery-${BOARD}:
 - ebuild category is always media-libs
 - current binary version can be obtained with a simple sed
   expression

BUG=chromium:739235
TEST=./update_gpu_drivers.sh -n --package mali-drivers-bifrost

Change-Id: I2f5c20b24fdcdd4073a2cb17699dfbec77f0d059
Reviewed-on: https://chromium-review.googlesource.com/1350451
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/contrib/update_gpu_drivers.sh b/contrib/update_gpu_drivers.sh
index f367463..34e5cdb 100755
--- a/contrib/update_gpu_drivers.sh
+++ b/contrib/update_gpu_drivers.sh
@@ -23,6 +23,8 @@
 # Script must run inside the chroot.
 assert_inside_chroot
 
+# All drivers are in media-libs/ portage category.
+CATEGORY="media-libs"
 # List of supported drivers
 DRIVERS="mali-drivers mali-drivers-bifrost img-ddk"
 
@@ -142,8 +144,7 @@
   local pvr="$("equery-${board}" -q list -p -o --format="\$fullversion" ${pn} | sort | head -n 1)"
   # Binary PV (e.g. 13.0_p6)
   local pv="${pvr/-r/_p}"
-  local category="$("equery-${board}" -q list -p -o --format="\$category" ${pn} | sort | head -n 1)"
-  local inputtarball="/build/${board}/packages/${category}/${pn}-${pvr}.tbz2"
+  local inputtarball="/build/${board}/packages/${CATEGORY}/${pn}-${pvr}.tbz2"
   local outputtarball="${pn}-${suffix}-${pv}.tbz2"
   local script="${pn}-${suffix}-${pv}.run"
   local gspath="gs://chromeos-localmirror/distfiles"
@@ -185,17 +186,21 @@
     rm -rf "${temp}"
   fi
 
-  local pvbin=$("equery-${board}" -q list -p -o --format="\$fullversion" ${pnbin} | sort | head -n 1)
-  echo "New binary version: ${pv} (current binary version: ${pvbin})"
   # Uprev ebuild in git if it exists.
-  if [[ -d "${SRC_ROOT}/overlays/${opath}/${category}/${pnbin}" ]]; then
-    cd "${SRC_ROOT}/overlays/${opath}/${category}/${pnbin}"
+  if [[ -d "${SRC_ROOT}/overlays/${opath}/${CATEGORY}/${pnbin}" ]]; then
+    cd "${SRC_ROOT}/overlays/${opath}/${CATEGORY}/${pnbin}"
+
+    # Grab the version of the current release of the binary package.
+    local pvbin="$(printf '%s\n' *.ebuild | \
+                   sed -nE "s/^${pnbin}-(.*)\.ebuild\$/\1/p" | \
+                   sort -V | tail -n 1)"
+    echo "New binary version: ${pv} (current binary version: ${pvbin})"
 
     # following git commands may fail if they have been issued previously
-    git checkout -b "gpudriverbinupdate-${pv}"
+    git checkout -b "gpudriverbinupdate-${pnbin}-${pv}"
     git mv "${pnbin}-${pvbin}.ebuild" "${pnbin}-${pv}.ebuild"
 
-    "ebuild-${board}" "${pnbin}-${pv}.ebuild" manifest
+    ebuild "${pnbin}-${pv}.ebuild" manifest
   fi
 
   popd >& /dev/null