update_kernel: Allow specifying multiple remote hosts

The hosts will be updated in parallel.

BUG=None
TEST=update_kernel.sh --remote=host1,host2

Change-Id: Ie4fe63030906f28b5d14405487e04e9b058f8758
Reviewed-on: https://chromium-review.googlesource.com/170801
Reviewed-by: Doug Anderson <dianders@chromium.org>
Tested-by: Doug Anderson <dianders@chromium.org>
Reviewed-by: Olof Johansson <olofj@chromium.org>
Commit-Queue: Doug Anderson <dianders@chromium.org>
diff --git a/update_kernel.sh b/update_kernel.sh
index d71f283..764d6b5 100755
--- a/update_kernel.sh
+++ b/update_kernel.sh
@@ -23,6 +23,8 @@
 DEFINE_boolean bootonce $FLAGS_FALSE "Mark kernel partition as boot once"
 DEFINE_boolean remote_bootargs $FLAGS_FALSE "Use bootargs from running kernel on target"
 
+ORIG_ARGS=("$@")
+
 # Parse command line.
 FLAGS "$@" || exit 1
 eval set -- "${FLAGS_ARGV}"
@@ -144,7 +146,24 @@
   fi
 }
 
+multi_main() {
+  local host
+
+  IFS=","
+  for host in ${FLAGS_remote}; do
+    "$0" "${ORIG_ARGS[@]}" --remote="${host}" \
+      |& sed "s/^/${V_BOLD_YELLOW}${host}: ${V_VIDOFF}/" &
+  done
+  wait
+}
+
 main() {
+  # If there are commas in the --remote, run the script in parallel.
+  if [[ ${FLAGS_remote} == *,* ]]; then
+    multi_main
+    return $?
+  fi
+
   trap cleanup EXIT
 
   TMP=$(mktemp -d /tmp/update_kernel.XXXXXX)