Remove old versions of autotest-tests and autotest-deps.

This CL is copied from:
https://gerrit.chromium.org/gerrit/#/c/61600

To speed up the build, we are splitting the autotest-tests and
autotest-deps packages into a few other packages. This may cause
conflicts so we will need to uninstall the other packages first. This
migration script will take care of the uninstallation.

BUG=chromium:238407
TEST=none

Change-Id: Idd85c84279318ce1aaad07fa31e479c732e39752
Reviewed-on: https://gerrit.chromium.org/gerrit/62387
Reviewed-by: David James <davidjames@chromium.org>
Tested-by: Dan Shi <dshi@chromium.org>
Reviewed-by: Dan Shi <dshi@chromium.org>
Commit-Queue: Dan Shi <dshi@chromium.org>
diff --git a/chroot_version_hooks.d/61_upgrade_autotest_pkgs b/chroot_version_hooks.d/61_upgrade_autotest_pkgs
new file mode 100644
index 0000000..c8e5223
--- /dev/null
+++ b/chroot_version_hooks.d/61_upgrade_autotest_pkgs
@@ -0,0 +1,34 @@
+# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# Remove old versions of these packages.
+pkgs="chromeos-base/autotest-deps chromeos-base/autotest-tests"
+
+export CLEAN_DELAY=0
+
+update() {
+  local root=$1 board=$2 emerge
+
+  if [[ -z ${board} ]]; then
+    board="root"
+    emerge="sudo -E emerge"
+  else
+    emerge="emerge-${board}"
+  fi
+
+  for opkg in ${pkgs}; do
+    if portageq has_version ${root} ${opkg}; then
+      ${emerge} -Cq ${opkg}
+    fi
+  done
+}
+
+update / &
+
+for board_root in /build/*; do
+  board=${board_root##*/}
+  update ${board_root} ${board} &
+done
+
+wait