Skip to content

Commit 1ee165a

Browse files
committed
split uploading debug info into dedicated tool
1 parent 1f90bce commit 1ee165a

2 files changed

Lines changed: 180 additions & 115 deletions

File tree

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#!/bin/bash
2+
#
3+
# armbian-debug
4+
#
5+
# Collect and upload system debug information for Armbian support.
6+
# Part of the Armbian project - https://www.armbian.com
7+
#
8+
############################################################################
9+
10+
# Config:
11+
declare -a paste_servers=("paste.armbian.com" "paste.next.armbian.com" "paste.armbian.de")
12+
if [[ "${PASTE_SERVER_HOST}" != "" ]]; then
13+
echo "Using custom paste server: '${PASTE_SERVER_HOST}'"
14+
paste_servers=("${PASTE_SERVER_HOST}" "${paste_servers[@]}")
15+
fi
16+
17+
# Set up colors if available
18+
if test -t 1; then
19+
ncolors=$(tput colors)
20+
if test -n "$ncolors" && test $ncolors -ge 8; then
21+
BOLD="$(tput bold)"
22+
NC='\033[0m' # No Color
23+
fi
24+
fi
25+
26+
Main() {
27+
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
28+
29+
# Check if curl is available, install if not
30+
if ! command -v curl > /dev/null 2>&1; then
31+
echo "curl not found in PATH. Trying to install it..." >&2
32+
if [ "$(id -u)" = "0" ]; then
33+
apt-get -f -y install curl
34+
else
35+
echo "Please install curl: sudo apt-get install curl" >&2
36+
exit 1
37+
fi
38+
fi
39+
40+
# 5 second countdown with option to force stdout output
41+
force_stdout=false
42+
echo -e "\n${BOLD}Collecting debug information for Armbian support${NC}"
43+
echo -e "Press any key within 5 seconds to output to stdout instead of uploading..."
44+
for i in {5..1}; do
45+
echo -ne "\r$i seconds remaining... "
46+
# Read with timeout (works in bash)
47+
if read -s -n 1 -t 1; then
48+
force_stdout=true
49+
echo -e "\n${BOLD}Key pressed - will output to stdout${NC}\n"
50+
break
51+
fi
52+
done
53+
if [ "$force_stdout" = false ]; then
54+
echo -e "\rStarting upload... "
55+
fi
56+
57+
# Collect and process the info
58+
if [ "$force_stdout" = true ]; then
59+
# Output to stdout with line numbers
60+
CollectSupportInfo |
61+
sed -E 's/([0-9]{1,3}\.)([0-9]{1,3}\.)([0-9]{1,3}\.)([0-9]{1,3})/XXX.XXX.\3\4/g' |
62+
awk '!NF{$0=" "}1' | nl -
63+
echo -e "\nPlease upload the ${BOLD}whole output${NC} above to an online pasteboard service\nand provide the URL in the forum where you have been asked for this.\n"
64+
else
65+
# Try to upload to paste servers
66+
upload_success=false
67+
68+
for paste_server in "${paste_servers[@]}"; do
69+
echo "Collecting info and sending to ${paste_server}..."
70+
declare -i counter=0
71+
{
72+
LC_ALL=C date
73+
echo "-----------------------------------------------------------------------------------------------------------------------------"
74+
dmesg --color=always
75+
echo "-----------------------------------------------------------------------------------------------------------------------------"
76+
CollectSupportInfo || echo "Error collecting support info"
77+
} |
78+
sed -E 's/([0-9]{1,3}\.)([0-9]{1,3}\.)([0-9]{1,3}\.)([0-9]{1,3})/XXX.XXX.\3\4/g' |
79+
curl -s --fail --data-binary @- "https://${paste_server}/log"
80+
81+
# Check PIPESTATUS
82+
for i in "${PIPESTATUS[@]}"; do
83+
counter=$((counter + 1))
84+
if [[ $i -ne 0 ]]; then
85+
echo "Failed (pipe ${counter} returned ${i})."
86+
continue 2
87+
fi
88+
done
89+
90+
# If we get here, upload succeeded
91+
upload_success=true
92+
break
93+
done
94+
95+
if [ "$upload_success" = true ]; then
96+
echo -e "\n${BOLD}Upload successful!${NC} Please post the URL above in the forum.\n"
97+
else
98+
echo -e "\n${BOLD}All upload attempts failed. Outputting to stdout instead:${NC}\n"
99+
CollectSupportInfo |
100+
sed -E 's/([0-9]{1,3}\.)([0-9]{1,3}\.)([0-9]{1,3}\.)([0-9]{1,3})/XXX.XXX.\3\4/g' |
101+
awk '!NF{$0=" "}1' | nl -
102+
echo -e "\nPlease upload the ${BOLD}whole output${NC} above to an online pasteboard service\nand provide the URL in the forum where you have been asked for this.\n"
103+
fi
104+
fi
105+
}
106+
107+
CollectSupportInfo() {
108+
[[ -s /var/log/armbian-hardware-monitor.log ]] && cat /var/log/armbian-hardware-monitor.log || zcat /var/log/armbian-hardware-monitor.log.1.gz 2> /dev/null
109+
[[ -f /boot/armbianEnv.txt ]] && LOGLEVEL=$(awk -F'=' '/^verbosity/ {print $2}' /boot/armbianEnv.txt)
110+
LOGLEVEL=${LOGLEVEL:-1}
111+
if [ ${LOGLEVEL} -gt 4 ]; then
112+
VERBOSE='-v'
113+
which lshw > /dev/null 2>&1 && (
114+
echo -e "\n### lshw:"
115+
lshw -quiet -sanitize -numeric
116+
)
117+
fi
118+
lsusb > /dev/null 2>&1 && (
119+
echo -e "\n### lsusb:\n"
120+
lsusb ${VERBOSE} 2> /dev/null
121+
echo ""
122+
lsusb -t 2> /dev/null
123+
)
124+
lspci > /dev/null 2>&1 && (
125+
echo -e "\n### lspci:\n"
126+
lspci ${VERBOSE} 2> /dev/null
127+
)
128+
nvme > /dev/null 2>&1 && (
129+
echo -e "\n### nvme:\n"
130+
nvme list 2> /dev/null
131+
)
132+
[ -z $SUDO_USER ] || echo -e "\n### Group membership of $(groups $SUDO_USER)"
133+
echo -en "\n### Userland"
134+
[[ -f /etc/armbian-release ]] && echo -en " generated with Armbian Build Framework"
135+
echo -en ":\n"
136+
echo -e "\n$(grep PRETTY_NAME /etc/os-release)"
137+
echo -e "\n### Installed packages:\n\n$(dpkg -l | grep -E "openmediavault|armbian| linux-")"
138+
KernelVersion=$(awk -F" " '{print $3}' < /proc/version)
139+
case ${KernelVersion} in
140+
3.*)
141+
[[ -e /boot/script.bin ]] && echo -e "\n### fex settings: $(ls -la /boot/script.bin)\n\n$(bin2fex /boot/script.bin 2> /dev/null)"
142+
;;
143+
esac
144+
echo -e "\n### Loaded modules:\n\n$(lsmod)"
145+
[[ -f /var/log/nand-sata-install.log ]] && echo -e "\n### nand-sata-install.log:\n\n$(cat /var/log/nand-sata-install.log)"
146+
echo -e "\n### Current sysinfo:\n\n$(command -v iostat >/dev/null 2>&1 && iostat -p ALL | grep -v "^loop")\n\n$(vmstat -w)\n\n$(free -h)\n\n$(zramctl 2> /dev/null)\n\n$(uptime)\n\n$(dmesg | tail -n 250)"
147+
echo -e "\n"
148+
[[ "$(id -u)" -eq "0" ]] && for sysfsnode in /proc/sys/vm/*; do sysctl $(echo ${sysfsnode} | sed 's|/proc/sys/vm/|vm.|'); done
149+
echo -e "\n### interrupts:\n$(cat /proc/interrupts)"
150+
ls /tmp/armbianmonitor_checks_* > /dev/null 2>&1 || return 0
151+
for file in /tmp/armbianmonitor_checks_*; do
152+
echo -e "\n### \c"
153+
ls "${file}" | cut -f1 -d.
154+
echo
155+
cat "${file}"
156+
done
157+
} # CollectSupportInfo
158+
159+
Main "$@"

packages/bsp/common/usr/bin/armbianmonitor

Lines changed: 21 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,6 @@
8181
#
8282
############################################################################
8383

84-
# Config:
85-
declare -a paste_servers=("paste.armbian.com" "paste.next.armbian.com" "paste.armbian.de")
86-
if [[ "${PASTE_SERVER_HOST}" != "" ]]; then
87-
echo "Using custom paste server: '${PASTE_SERVER_HOST}'"
88-
paste_servers=("${PASTE_SERVER_HOST}" "${paste_servers[@]}")
89-
fi
90-
9184
Main() {
9285
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
9386

@@ -156,52 +149,24 @@ ParseOptions() {
156149
NetworkMonitorMode ${OPTARG}
157150
exit 0
158151
;;
159-
u)
160-
# Upload /var/log/armbian-hardware-monitor.log with additional support info
161-
# NOTE(rpardini): was here. briefly. just because this uses the paste server and I want ANSI dmesgs
162-
# check if curl binary is available in path, if not try to install it. use command, not which
163-
if ! command -v curl > /dev/null 2>&1; then
164-
echo "curl not found in PATH. Trying to install it." >&2
165-
apt-get -f -y install curl
152+
u | U)
153+
# DEPRECATED: Support info collection has been moved to armbian-debug
154+
cat << 'EOF'
155+
156+
The -u and -U options are deprecated. This functionality has been moved to the
157+
dedicated 'armbian-debug' tool.
158+
159+
Launching armbian-debug now...
160+
EOF
161+
# Check if armbian-debug exists
162+
if [ -x /usr/bin/armbian-debug ]; then
163+
exec /usr/bin/armbian-debug
164+
elif [ -x "$(dirname "$0")/armbian-debug" ]; then
165+
exec "$(dirname "$0")/armbian-debug"
166+
else
167+
echo "Error: armbian-debug not found." >&2
168+
exit 1
166169
fi
167-
# loop over the paste_servers; first to work wins.
168-
for paste_server in "${paste_servers[@]}"; do # defined at top of file
169-
echo "Collecting info and sending to ${paste_server}, wait..."
170-
declare -i counter=0
171-
{
172-
LC_ALL=C date # include timestamp
173-
echo "-----------------------------------------------------------------------------------------------------------------------------"
174-
dmesg --color=always # output in ANSI color. The paste service handles this.
175-
echo "-----------------------------------------------------------------------------------------------------------------------------"
176-
CollectSupportInfo || echo "Error collecting support info via CollectSupportInfo"
177-
} |
178-
# we obfuscate IPv4 addresses somehow but not too much, MAC addresses have to remain
179-
# in clear since otherwise the log becomes worthless due to randomly generated
180-
# addresses here and there that might conflict
181-
sed -E 's/([0-9]{1,3}\.)([0-9]{1,3}\.)([0-9]{1,3}\.)([0-9]{1,3})/XXX.XXX.\3\4/g' |
182-
curl -s --fail --data-binary @- "https://${paste_server}/log"
183-
# Check PIPESTATUS to know if everything worked. Any non-zero exit status means something didn't work.
184-
for i in "${PIPESTATUS[@]}"; do
185-
counter=$((counter + 1))
186-
if [[ $i -ne 0 ]]; then
187-
echo "Failed grabbing info (pipe ${counter} result ${i}) and sending to server ${paste_server}."
188-
continue 2 # continue the outer loop (paste_servers)
189-
fi
190-
done
191-
echo -e "Please post the URL in the forum where you've been asked for.\n"
192-
exit 0
193-
done
194-
195-
;;
196-
197-
U)
198-
# Send support info to stdout to be uploaded manually. Add line numbers to prevent
199-
# users being creative and supressing everything that's important
200-
CollectSupportInfo |
201-
sed -E 's/([0-9]{1,3}\.)([0-9]{1,3}\.)([0-9]{1,3}\.)([0-9]{1,3})/XXX.XXX.\3\4/g' |
202-
awk '!NF{$0=" "}1' | nl -
203-
echo -e "\nPlease upload the ${BOLD}whole output${NC} above to an online pasteboard service\nand provide the URL in the forum where you have been asked for this.\n"
204-
exit 0
205170
;;
206171
d)
207172
# monitors write activity to disk
@@ -266,7 +231,7 @@ DisplayUsage() {
266231
# grep "^#" "$0" | grep -v "^#\!/bin/bash" | sed 's/^#//'
267232
# fi
268233
echo
269-
echo "Usage: $(basename $0) [-h] [-b] [-c \$path] [-d \$device] [-D] [-m] [-u]"
234+
echo "Usage: $(basename $0) [-h] [-c \$path] [-d \$device] [-D] [-m] [-n] [-v] [-z]"
270235
echo
271236
echo "Options:"
272237
echo " -c /path/to/test Performs disk health/performance tests"
@@ -276,10 +241,12 @@ DisplayUsage() {
276241
echo " -M Provides simple CLI monitoring - fixed-line output"
277242
echo " -n Provides simple CLI network monitoring - scrolling output"
278243
echo " -N Provides simple CLI network monitoring - fixed-line output"
279-
echo " -u Tries to upload armbian-hardware-monitor.log for support purposes"
280244
echo " -v Tries to verify installed package integrity"
281245
echo " -z Runs a quick 7-zip benchmark to estimate CPU performance"
282246
echo
247+
echo "Note: The -u/-U options for support info upload are deprecated."
248+
echo " Use the 'armbian-debug' command instead."
249+
echo
283250

284251
} # DisplayUsage
285252

@@ -686,67 +653,6 @@ CreateTempDir() {
686653
done
687654
} #CreateTempFiles
688655

689-
CollectSupportInfo() {
690-
[[ -s /var/log/armbian-hardware-monitor.log ]] && cat /var/log/armbian-hardware-monitor.log || zcat /var/log/armbian-hardware-monitor.log.1.gz 2> /dev/null
691-
[[ -f /boot/armbianEnv.txt ]] && LOGLEVEL=$(awk -F'=' '/^verbosity/ {print $2}' /boot/armbianEnv.txt)
692-
LOGLEVEL=${LOGLEVEL:-1}
693-
if [ ${LOGLEVEL} -gt 4 ]; then
694-
VERBOSE='-v'
695-
which lshw > /dev/null 2>&1 && (
696-
echo -e "\n### lshw:"
697-
lshw -quiet -sanitize -numeric
698-
)
699-
fi
700-
lsusb > /dev/null 2>&1 && (
701-
echo -e "\n### lsusb:\n"
702-
lsusb ${VERBOSE} 2> /dev/null
703-
echo ""
704-
lsusb -t 2> /dev/null
705-
)
706-
lspci > /dev/null 2>&1 && (
707-
echo -e "\n### lspci:\n"
708-
lspci ${VERBOSE} 2> /dev/null
709-
)
710-
nvme > /dev/null 2>&1 && (
711-
echo -e "\n### nvme:\n"
712-
nvme list 2> /dev/null
713-
)
714-
[ -z $SUDO_USER ] || echo -e "\n### Group membership of $(groups $SUDO_USER)"
715-
echo -en "\n### Userland"
716-
[[ -f /etc/armbian-release ]] && echo -en " generated with Armbian Build Framework"
717-
echo -en ":\n"
718-
echo -e "\n$(grep PRETTY_NAME /etc/os-release)"
719-
echo -e "\n### Installed packages:\n\n$(dpkg -l | grep -E "openmediavault|armbian| linux-")"
720-
KernelVersion=$(awk -F" " '{print $3}' < /proc/version)
721-
case ${KernelVersion} in
722-
3.*)
723-
[[ -e /boot/script.bin ]] && echo -e "\n### fex settings: $(ls -la /boot/script.bin)\n\n$(bin2fex /boot/script.bin 2> /dev/null)"
724-
;;
725-
esac
726-
echo -e "\n### Loaded modules:\n\n$(lsmod)"
727-
[[ -f /var/log/nand-sata-install.log ]] && echo -e "\n### nand-sata-install.log:\n\n$(cat /var/log/nand-sata-install.log)"
728-
echo -e "\n### Current system health:\n\n$("$0" -s | grep -E "^Time|^[0-9]")"
729-
stress -t 3 -c $(grep -c processor /proc/cpuinfo) --backoff 250 > /dev/null 2>&1 &
730-
"$0" -s | grep "^[0-9]"
731-
# Include name resolving information only if upload is not possible
732-
fping ix.io 2> /dev/null | grep -q alive ||
733-
[ -f /etc/resolv.conf ] && echo -e "\n### resolv.conf\n\n$(
734-
ls -la /etc/resolv.conf
735-
cat /etc/resolv.conf
736-
)" ||
737-
echo -e "\n### resolv.conf does not exist or readable"
738-
echo -e "\n### Current sysinfo:\n\n$(command -v iostat >/dev/null 2>&1 && iostat -p ALL | grep -v "^loop")\n\n$(vmstat -w)\n\n$(free -h)\n\n$(zramctl 2> /dev/null)\n\n$(uptime)\n\n$(dmesg | tail -n 250)"
739-
echo -e "\n"
740-
[[ "$(id -u)" -eq "0" ]] && for sysfsnode in /proc/sys/vm/*; do sysctl $(echo ${sysfsnode} | sed 's|/proc/sys/vm/|vm.|'); done
741-
echo -e "\n### interrupts:\n$(cat /proc/interrupts)"
742-
ls /tmp/armbianmonitor_checks_* > /dev/null 2>&1 || return
743-
for file in /tmp/armbianmonitor_checks_*; do
744-
echo -e "\n### \c"
745-
ls "${file}" | cut -f1 -d.
746-
echo
747-
cat "${file}"
748-
done
749-
} # CollectSupportInfo
750656

751657
CheckCard() {
752658
if [ "$(id -u)" = "0" ]; then

0 commit comments

Comments
 (0)