1f46ba292498d880686df43773225b840c02e0764leozwang@webrtc.org#!/bin/bash
2f46ba292498d880686df43773225b840c02e0764leozwang@webrtc.org
3f46ba292498d880686df43773225b840c02e0764leozwang@webrtc.org# Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
4f46ba292498d880686df43773225b840c02e0764leozwang@webrtc.org#
5f46ba292498d880686df43773225b840c02e0764leozwang@webrtc.org# Use of this source code is governed by a BSD-style license
6f46ba292498d880686df43773225b840c02e0764leozwang@webrtc.org# that can be found in the LICENSE file in the root of the source
7f46ba292498d880686df43773225b840c02e0764leozwang@webrtc.org# tree. An additional intellectual property rights grant can be found
8f46ba292498d880686df43773225b840c02e0764leozwang@webrtc.org# in the file PATENTS.  All contributing project authors may
9f46ba292498d880686df43773225b840c02e0764leozwang@webrtc.org# be found in the AUTHORS file in the root of the source tree.
10f46ba292498d880686df43773225b840c02e0764leozwang@webrtc.org
11f46ba292498d880686df43773225b840c02e0764leozwang@webrtc.org# 'adb shell' always returns "0" regardless of executable return code.
12f46ba292498d880686df43773225b840c02e0764leozwang@webrtc.org# This handy script will return executable return code to shell which
13f46ba292498d880686df43773225b840c02e0764leozwang@webrtc.org# can be used by buildbots.
14f46ba292498d880686df43773225b840c02e0764leozwang@webrtc.org
15f46ba292498d880686df43773225b840c02e0764leozwang@webrtc.orgadb_shell () {
16f46ba292498d880686df43773225b840c02e0764leozwang@webrtc.org  local RET ADB_LOG
17f46ba292498d880686df43773225b840c02e0764leozwang@webrtc.org  ADB_LOG=$(mktemp "${TMPDIR:-/tmp}/adb-XXXXXXXX")
188ca9b76775ccf69316b073f58b8d16c4934bb454leozwang@webrtc.org  adb "$1" "$2" shell "$3" "$4" ";" echo \$? | tee "$ADB_LOG"
19f46ba292498d880686df43773225b840c02e0764leozwang@webrtc.org  sed -i -e 's![[:cntrl:]]!!g' "$ADB_LOG"  # Remove \r.
20f46ba292498d880686df43773225b840c02e0764leozwang@webrtc.org  RET=$(sed -e '$!d' "$ADB_LOG")           # Last line contains status code.
21f46ba292498d880686df43773225b840c02e0764leozwang@webrtc.org  rm -f "$ADB_LOG"
22f46ba292498d880686df43773225b840c02e0764leozwang@webrtc.org  return $RET
23f46ba292498d880686df43773225b840c02e0764leozwang@webrtc.org}
24