Skip to content

Commit 230574b

Browse files
authored
Merge pull request #1325 from kernelkit/support-extra
Support collection fixes and additions [skip ci] Signed-off-by: Joachim Wiberg <[email protected]>
2 parents c56a9f2 + 5420fb0 commit 230574b

File tree

3 files changed

+75
-41
lines changed

3 files changed

+75
-41
lines changed

board/aarch64/styx-dcp-sc-28p/rootfs/usr/share/product/dcp-sc-28p/etc/finit.d/available/iitod.conf renamed to board/aarch64/styx-dcp-sc-28p/rootfs/usr/share/product/styx,dcp-sc-28p/etc/finit.d/available/iitod.conf

File renamed without changes.

doc/support.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,20 @@ provides a convenient way to collect comprehensive system diagnostics.
55
This command gathers configuration files, logs, network state, and other
66
system information into a single compressed archive.
77

8+
> [!NOTE]
9+
> The `support collect` command should be run with `sudo` to collect
10+
> complete system information (kernel logs, hardware details, etc.).
11+
> Use the `--unprivileged` option to run as a regular user in degraded
12+
> data collection mode.
13+
814
## Collecting Support Data
915

1016
To collect support data and save it to a file:
1117

1218
```bash
13-
admin@host:~$ support collect > support-data.tar.gz
14-
(admin@host) Password: ***********
19+
admin@host:~$ sudo support collect > support-data.tar.gz
1520
Starting support data collection from host...
21+
Collecting to: /var/lib/support
1622
This may take up to a minute. Please wait...
1723
Tailing /var/log/messages for 30 seconds (please wait)...
1824
Log tail complete.
@@ -24,7 +30,7 @@ admin@host:~$ ls -l support-data.tar.gz
2430
The command can also be run remotely via SSH from your workstation:
2531

2632
```bash
27-
$ ssh admin@host support collect > support-data.tar.gz
33+
$ ssh admin@host 'sudo support collect' > support-data.tar.gz
2834
...
2935
```
3036

@@ -38,8 +44,9 @@ For secure transmission of support data, the archive can be encrypted
3844
with GPG using a password:
3945

4046
```bash
41-
admin@host:~$ support collect -p mypassword > support-data.tar.gz.gpg
47+
admin@host:~$ sudo support collect -p mypassword > support-data.tar.gz.gpg
4248
Starting support data collection from host...
49+
Collecting to: /var/lib/support
4350
This may take up to a minute. Please wait...
4451
...
4552
Collection complete. Creating archive...
@@ -52,8 +59,8 @@ but the local ssh client may then echo the password.
5259

5360
> [!TIP]
5461
> To hide the encryption password for an SSH session, the script supports
55-
> reading from stdin:
56-
> `echo "$MYSECRET" | ssh user@device support collect -p >
62+
> reading from stdin:
63+
> `echo "$MYSECRET" | ssh user@device 'sudo support collect -p' >
5764
> file.tar.gz.gpg`
5865
5966
After transferring the resulting file to your workstation, decrypt it

src/bin/support

Lines changed: 62 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -96,31 +96,37 @@ cmd_collect()
9696
;;
9797
*)
9898
echo "Error: Unknown option '$1'" >&2
99-
echo "Usage: $prognm collect [--log-sec|-s N] [--password|-p PASSWORD]" >&2
99+
echo "Usage: $prognm collect [-s N] [-p PASSWORD]" >&2
100100
exit 1
101101
;;
102102
esac
103103
done
104104

105-
# Determine if we need sudo and if it's available
106-
SUDO=""
107-
if [ "$(id -u)" -ne 0 ]; then
108-
if command -v sudo >/dev/null 2>&1; then
109-
SUDO="sudo"
110-
fi
111-
fi
112-
113105
# If WORK_DIR not set globally, try /var/lib/support first (more space,
114106
# persistent across user sessions). Fall back to $HOME if we can't create/write there
115107
if [ -z "$WORK_DIR" ]; then
116108
if [ -w /var/lib/support ] 2>/dev/null; then
109+
# Already writable, use it
117110
WORK_DIR="/var/lib/support"
118-
elif mkdir -p /var/lib/support 2>/dev/null; then
119-
WORK_DIR="/var/lib/support"
120-
elif [ -n "$SUDO" ] && $SUDO mkdir -p /var/lib/support 2>/dev/null && \
121-
$SUDO chown "$(id -u):$(id -g)" /var/lib/support 2>/dev/null; then
122-
WORK_DIR="/var/lib/support"
123-
else
111+
elif [ ! -e /var/lib/support ]; then
112+
# Doesn't exist, try to create it
113+
if mkdir -p /var/lib/support 2>/dev/null; then
114+
WORK_DIR="/var/lib/support"
115+
fi
116+
elif [ -d /var/lib/support ]; then
117+
# Exists but not writable, try to fix permissions (requires root)
118+
# Try chmod first (might just be permission issue), then chown if needed
119+
if chmod 755 /var/lib/support 2>/dev/null && \
120+
chown "$(id -u):$(id -g)" /var/lib/support 2>/dev/null; then
121+
# Verify it's actually writable now
122+
if [ -w /var/lib/support ] 2>/dev/null; then
123+
WORK_DIR="/var/lib/support"
124+
fi
125+
fi
126+
fi
127+
128+
# Fall back to $HOME if we couldn't set up /var/lib/support
129+
if [ -z "$WORK_DIR" ]; then
124130
WORK_DIR="${HOME}"
125131
echo "Warning: Cannot write to /var/lib/support, using home directory instead." >&2
126132
echo " (This may fill up your home directory on systems with limited space)" >&2
@@ -145,7 +151,11 @@ cmd_collect()
145151
trap cleanup EXIT INT TERM
146152

147153
# Create collection directory
148-
mkdir -p "${COLLECT_DIR}"
154+
if ! mkdir -p "${COLLECT_DIR}"; then
155+
echo "Error: Cannot create collection directory: ${COLLECT_DIR}" >&2
156+
echo " Check permissions for ${WORK_DIR}" >&2
157+
exit 1
158+
fi
149159

150160
# Helper function to run commands with output to specific file
151161
collect()
@@ -251,7 +261,7 @@ cmd_collect()
251261
fi
252262

253263
# Kernel and system state
254-
collect system/dmesg.txt ${SUDO} dmesg
264+
collect system/dmesg.txt dmesg
255265
collect system/free.txt free -h
256266
collect system/stat.txt cat /proc/stat
257267
collect system/softirqs.txt cat /proc/softirqs
@@ -295,10 +305,10 @@ cmd_collect()
295305
ip -o link show | grep 'link/ether' | awk -F': ' '{print $2}' > "${COLLECT_DIR}/.iface-list" 2>> "${EXEC_LOG}"
296306
if [ -s "${COLLECT_DIR}/.iface-list" ]; then
297307
while IFS= read -r iface; do
298-
# ethtool typically needs root/sudo
299-
collect "network/ethtool/${iface}.txt" ${SUDO} ethtool "$iface"
300-
collect "network/ethtool/stats-${iface}.txt" ${SUDO} ethtool -S "$iface"
301-
collect "network/ethtool/module-${iface}.txt" ${SUDO} ethtool -m "$iface"
308+
# ethtool typically needs root
309+
collect "network/ethtool/${iface}.txt" ethtool "$iface"
310+
collect "network/ethtool/stats-${iface}.txt" ethtool -S "$iface"
311+
collect "network/ethtool/module-${iface}.txt" ethtool -m "$iface"
302312
done < "${COLLECT_DIR}/.iface-list"
303313
fi
304314
rm -f "${COLLECT_DIR}/.iface-list"
@@ -311,7 +321,7 @@ cmd_collect()
311321

312322
# Firewall rules
313323
if command -v nft >/dev/null 2>&1; then
314-
collect network/nftables.txt ${SUDO} nft list ruleset
324+
collect network/nftables.txt nft list ruleset
315325
fi
316326

317327
# FRR routing information
@@ -527,7 +537,10 @@ usage()
527537
{
528538
echo "Usage: $prognm [global-options] <command> [options]"
529539
echo ""
540+
echo "Note: Run with 'sudo' for complete data collection (dmesg, ethtool, etc.)"
541+
echo ""
530542
echo "Global options:"
543+
echo " -u, --unprivileged Allow running without root (some data will be missing)"
531544
echo " -w, --work-dir PATH Use PATH as working directory for collection/cleanup"
532545
echo " (default: /var/lib/support with fallback to \$HOME)"
533546
echo ""
@@ -547,23 +560,29 @@ usage()
547560
echo " -d, --days N Remove directories older than N days (default: 7)"
548561
echo ""
549562
echo "Examples:"
550-
echo " $prognm collect > support-data.tar.gz"
551-
echo " $prognm collect -p > support-data.tar.gz.gpg"
552-
echo " $prognm collect --password mypass > support-data.tar.gz.gpg"
553-
echo " $prognm --work-dir /tmp/ram collect > support-data.tar.gz"
554-
echo " ssh user@device $prognm collect > support-data.tar.gz"
555-
echo " $prognm clean --dry-run"
556-
echo " $prognm clean --days 30"
557-
echo " $prognm --work-dir /tmp/ram clean"
563+
echo " sudo $prognm collect > support-data.tar.gz"
564+
echo " sudo $prognm collect -p > support-data.tar.gz.gpg"
565+
echo " sudo $prognm collect --password mypass > support-data.tar.gz.gpg"
566+
echo " sudo $prognm --work-dir /tmp/ram collect > support-data.tar.gz"
567+
echo " ssh user@device 'sudo $prognm collect' > support-data.tar.gz"
568+
echo " $prognm -u collect > support-data.tar.gz (degraded)"
569+
echo " sudo $prognm clean --dry-run"
570+
echo " sudo $prognm clean --days 30"
571+
echo " sudo $prognm --work-dir /tmp/ram clean"
558572
exit 1
559573
}
560574

561575
# Main command dispatcher
562576
# Parse global options first
563577
WORK_DIR=""
578+
ALLOW_UNPRIVILEGED=0
564579

565580
while [ $# -gt 0 ]; do
566581
case "$1" in
582+
-u|--unprivileged)
583+
ALLOW_UNPRIVILEGED=1
584+
shift
585+
;;
567586
-w|--work-dir)
568587
if [ -z "$2" ]; then
569588
echo "Error: --work-dir requires a path argument" >&2
@@ -591,11 +610,19 @@ command="$1"
591610
shift
592611

593612
case "$command" in
594-
collect)
595-
cmd_collect "$@"
596-
;;
597-
clean)
598-
cmd_clean "$@"
613+
collect|clean)
614+
# Check if running as root (uid 0)
615+
if [ "$(id -u)" -ne 0 ] && [ "$ALLOW_UNPRIVILEGED" -eq 0 ]; then
616+
echo "Error: This command should be run with 'sudo' for complete data collection." >&2
617+
echo " Use -u/--unprivileged to run as a regular user in degraded mode." >&2
618+
exit 1
619+
fi
620+
621+
if [ "$command" = "collect" ]; then
622+
cmd_collect "$@"
623+
else
624+
cmd_clean "$@"
625+
fi
599626
;;
600627
help|--help|-h)
601628
usage

0 commit comments

Comments
 (0)