-
Notifications
You must be signed in to change notification settings - Fork 4
/
helper
executable file
·86 lines (73 loc) · 1.89 KB
/
helper
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
#!/bin/bash
# Colors for script
BOLD="\033[1m"
GRN="\033[01;32m"
RED="\033[01;31m"
RST="\033[0m"
YLW="\033[01;33m"
function repopick(){
repopick -q
}
function _adb_connected {
{
if [[ "$(adb get-state)" == device ]]
then
return 0
fi
} 2>/dev/null
return 1
};
function init_adb_connection() {
adb start-server # Prevent unexpected starting server message from adb get-state in the next line
if ! _adb_connected; then
echo "No device is online. Waiting for one..."
echo "Please connect USB and/or enable USB debugging"
until _adb_connected; do
sleep 1
done
echo "Device Found."
fi
# Retrieve IP and PORT info if we're using a TCP connection
TCPIPPORT=$(adb devices | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \
| head -1 | awk '{print $1}')
adb root &> /dev/null
sleep 0.3
if [ -n "$TCPIPPORT" ]; then
# adb root just killed our connection
# so reconnect...
adb connect "$TCPIPPORT"
fi
adb wait-for-device &> /dev/null
sleep 0.3
}
# Alias for echo to handle escape codes like colors
function echo() {
command echo -e "$@"
}
# Prints a formatted header to point out what is being done to the user
function header() {
if [[ -n ${2} ]]; then
COLOR=${2}
else
COLOR=${RED}
fi
# shellcheck disable=SC2034
echo "${COLOR}\n====$(for i in $(seq ${#1}); do echo "=\c"; done)====\n== ${1} ==\n====$(for i in $(seq ${#1}); do echo "=\c"; done)====\n${RST}"
}
# Prints an error in bold red
function die() {
echo "${RED}${1}${RST}"
[[ ${2} = "-h" ]] && ${0} -h
exit 1
}
# Prints a statement in bold green
function success() {
echo "${GRN}${1}${RST}"
[[ -z ${2} ]] && echo
}
# Prints an info in bold yellow
function info() {
echo
echo "${YLW}${1}${RST}"
[[ -z ${2} ]] && echo
}