-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathci-after-fail-debug.sh
More file actions
executable file
·175 lines (134 loc) · 4 KB
/
Copy pathci-after-fail-debug.sh
File metadata and controls
executable file
·175 lines (134 loc) · 4 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/env bash
#
# © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com
# Contributors: denbond7
#
set -euo pipefail
SUMMARY_FAILURES=0
print_section() {
local title="$1"
echo
echo "======================================================================"
echo "${title}"
date -u '+UTC time: %Y-%m-%d %H:%M:%S'
echo "======================================================================"
}
run_debug_cmd() {
local description="$1"
shift
echo
echo "[debug] ${description}"
"$@" || true
}
adb_root_shell() {
local cmd="$1"
adb shell "su 0 sh -c '${cmd}' 2>/dev/null || sh -c '${cmd}'"
}
summary_check() {
local label="$1"
shift
if "$@" >/dev/null 2>&1; then
echo "[summary] PASS: ${label}"
else
echo "[summary] FAIL: ${label}"
SUMMARY_FAILURES=$((SUMMARY_FAILURES + 1))
fi
}
collect_network_debug_info() {
print_section "Host-side adb state"
run_debug_cmd "adb devices" adb devices -l
run_debug_cmd "adb server version" adb version
run_debug_cmd "adb forward list" adb forward --list
run_debug_cmd "adb reverse list" adb reverse --list
print_section "Device network overview"
run_debug_cmd "boot completed" adb shell getprop sys.boot_completed
run_debug_cmd "net/dns props" adb shell "getprop | grep -E 'net\\.|dns|dhcp|private_dns'"
run_debug_cmd "ip addr" adb shell ip addr
run_debug_cmd "ip route" adb shell ip route
run_debug_cmd "connectivity dumpsys" adb shell dumpsys connectivity
run_debug_cmd "private dns mode" adb shell settings get global private_dns_mode
print_section "DNS and internet checks"
run_debug_cmd \
"ping raw IP 8.8.8.8" \
adb shell ping -c 1 8.8.8.8
run_debug_cmd \
"ping www.google.com" \
adb shell ping -c 1 www.google.com
run_debug_cmd \
"ping emulator host gateway 10.0.2.2" \
adb shell ping -c 1 10.0.2.2
run_debug_cmd \
"ping fes.flowcrypt.test" \
adb shell ping -c 1 fes.flowcrypt.test
print_section "NAT and sockets"
run_debug_cmd \
"iptables nat OUTPUT rules" \
adb_root_shell "iptables -t nat -S OUTPUT"
run_debug_cmd \
"iptables nat OUTPUT counters" \
adb_root_shell "iptables -t nat -L OUTPUT -n -v"
run_debug_cmd \
"listeners netstat" \
adb shell netstat -lntp
}
print_summary() {
print_section "Network summary"
summary_check \
"internet raw IP (8.8.8.8)" \
adb shell ping -c 1 8.8.8.8
summary_check \
"internet DNS (www.google.com)" \
adb shell ping -c 1 www.google.com
summary_check \
"emulator host gateway 10.0.2.2" \
adb shell ping -c 1 10.0.2.2
summary_check \
"flowcrypt.test ping" \
adb shell ping -c 1 fes.flowcrypt.test
summary_check \
"iptables OUTPUT redirect 443->1212 present" \
adb_root_shell \
"iptables -t nat -S OUTPUT | grep -F -- '--dport 443 -j REDIRECT --to-ports 1212'"
summary_check \
"listener on :1212 present" \
adb shell \
"netstat -lnt 2>/dev/null | grep -E '(^|[:.])1212([[:space:]]|$)'"
if [[ "$SUMMARY_FAILURES" -eq 0 ]]; then
echo "[summary] RESULT: PASS"
else
echo "[summary] RESULT: FAIL (${SUMMARY_FAILURES} checks failed)"
fi
}
check_ping_or_fail() {
local host="$1"
local label="$2"
for attempt in {1..10}; do
if adb shell "ping -c 1 ${host}"; then
return 0
fi
if [[ "$attempt" -eq 10 ]]; then
echo "Failed to ping ${host}: ${label}"
return 1
fi
sleep 2
done
}
###################################################################################################
NETWORK_FAILURE=0
if ! check_ping_or_fail "www.google.com" "internet connection"; then
NETWORK_FAILURE=1
fi
if ! check_ping_or_fail "10.0.2.2" "emulator host gateway"; then
NETWORK_FAILURE=1
fi
if ! check_ping_or_fail "fes.flowcrypt.test" "flowcrypt.test DNS/reachability"; then
NETWORK_FAILURE=1
fi
if [[ "$NETWORK_FAILURE" -eq 1 ]]; then
print_section "Network failure diagnostics"
collect_network_debug_info
print_summary
exit 1
fi
print_section "Network status"
echo "All network checks passed"