-
Notifications
You must be signed in to change notification settings - Fork 0
/
adbs.sh
89 lines (73 loc) · 2.21 KB
/
adbs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# Control all your connected Android devices simultaneously using adb with one command.
# [email protected] 2013-06-20
# Get "emulator-5554" from "emulator-5554 device"
function getSerialNumber(){
serialNumber=$(echo ${1%$'\t'*})
}
# device, offline, bootloader...
function getStatus(){
#alternative command: deviceStatus=$(adb -s $deviceId get-state)
deviceStatus=$(echo ${1#*$'\t'})
}
function getManufacturer(){
manufacturer=$(adb -s $serialNumber shell getprop ro.product.manufacturer | tr -d '\r\n ')
}
function getModel(){
model=`adb -s $serialNumber shell getprop ro.product.model | tr -d '\r\n '`
}
# os version like 4.2.2
function getRelease(){
release=$(adb -s $serialNumber shell getprop ro.build.version.release | tr -d '\r\n ')
}
function getBrand(){
brand=$(adb -s $serialNumber shell getprop ro.product.brand | tr -d '\r\n ')
}
function getDeviceInfo(){
manufacturer=""
model=""
release=""
brand=""
if [ "$deviceStatus"x = "device"x ]
then
getManufacturer
getModel
getRelease
getBrand
fi
}
# Check if there's any arg
if [ x$1 == x ]
then
echo
echo "Control all your connected Android devices simultaneously using adb with one command."
echo "Just like adb -s:"
echo "\tinstall xxx.apk"
echo "\tuninstall com.xxx.ooo"
echo "\tpull filesInPhone localPath"
echo "\tshell anyCommandInPhone"
echo "\t..."
echo
else
adb start-server
# Console output of "adb devices"
currentDevicesInfoRaw=$(adb devices)
# Delete useless text
currentDevicesInfo=${currentDevicesInfoRaw#*List of devices attached}
echo "$currentDevicesInfo"
numberOfLines=$(echo "$currentDevicesInfo" | wc -l)
for((i=2;i<=$numberOfLines;i++))
do {
deviceInfo=$(echo "$currentDevicesInfo" | awk NR==$i)
getSerialNumber "$deviceInfo"
getStatus "$deviceInfo"
# Get other information
getDeviceInfo
echo "\n----- adb -s $serialNumber $* | $manufacturer"_"$brand"_"$model"_"$release" && echo "\n<<<<< $manufacturer"_"$brand"_"$model"_"$release $serialNumber:\n$(adb -s $serialNumber $*)"
echo $#
echo $!
} &
done
# wait for all tasks done
wait
echo "\ndone"
fi