1+ #! /bin/sh
2+
3+ # Support Data Collection Script for Buildroot Devices
4+ # Creates a zip file with system information for troubleshooting
5+
6+ set -e
7+
8+ # Configuration
9+ COLLECTION_DIR=" /tmp/support_data_$( date +%Y%m%d_%H%M%S) "
10+ OUTPUT_DIR=" /media/dvr"
11+ SCRIPT_NAME=" collect_support_data.sh"
12+ OUTPUT_PREFIX=" openipc_support_data"
13+ TIMESTAMP=$( date +%Y%m%d_%H%M%S)
14+ OUTPUT_FILE=" ${OUTPUT_DIR} /${OUTPUT_PREFIX} _${TIMESTAMP} .zip"
15+ MAX_LOG_SIZE=1048576 # 1MB max per log file
16+
17+ # Colors for output (if supported)
18+ RED=' \033[0;31m'
19+ GREEN=' \033[0;32m'
20+ YELLOW=' \033[1;33m'
21+ NC=' \033[0m' # No Color
22+
23+ # Create collection directory
24+ mkdir -p " ${COLLECTION_DIR} "
25+ cd " ${COLLECTION_DIR} "
26+
27+ echo_colored () {
28+ echo -e " ${2}${1}${NC} "
29+ }
30+
31+ collect_file () {
32+ local src=" $1 "
33+ local dest=" $2 "
34+
35+ if [ -e " $src " ]; then
36+ cp " $src " " $dest " 2> /dev/null || {
37+ echo " Warning: Could not copy $src " >&2
38+ echo " Permission denied or file busy" > " $dest .access_error"
39+ }
40+ else
41+ echo " File not found: $src " > " $dest .not_found"
42+ fi
43+ }
44+
45+ collect_log () {
46+ local log_path=" $1 "
47+ local dest_name=" $2 "
48+
49+ if [ -f " $log_path " ]; then
50+ local size=$( stat -c%s " $log_path " 2> /dev/null || echo " 0" )
51+ if [ " $size " -gt " $MAX_LOG_SIZE " ]; then
52+ echo " Log truncated (original: ${size} bytes)" > " ${dest_name} "
53+ tail -c " ${MAX_LOG_SIZE} " " $log_path " >> " ${dest_name} "
54+ echo " " >> " ${dest_name} "
55+ echo " ... [truncated] ..." >> " ${dest_name} "
56+ head -c 10240 " $log_path " >> " ${dest_name} "
57+ else
58+ cp " $log_path " " ${dest_name} " 2> /dev/null || {
59+ echo " Could not copy log: $log_path " > " ${dest_name} .error"
60+ }
61+ fi
62+ fi
63+ }
64+
65+ echo_colored " Starting support data collection..." " $GREEN "
66+ echo_colored " Output will be saved to: ${OUTPUT_FILE} " " $YELLOW "
67+
68+ # 1. SYSTEM INFORMATION
69+ echo_colored " Collecting system information..." " $GREEN "
70+ mkdir -p system_info
71+
72+ # Basic system info
73+ uname -a > system_info/uname.txt 2>&1
74+ cat /proc/version > system_info/proc_version.txt 2>&1
75+ cat /etc/os-release 2> /dev/null > system_info/os_release.txt || echo " No os-release found" > system_info/os_release.txt
76+ cat /etc/issue 2> /dev/null > system_info/issue.txt || echo " No issue file found" > system_info/issue.txt
77+
78+ # CPU/Memory info
79+ cat /proc/cpuinfo > system_info/cpuinfo.txt 2>&1
80+ cat /proc/meminfo > system_info/meminfo.txt 2>&1
81+ free -h > system_info/free.txt 2>&1
82+
83+ # Uptime and load
84+ uptime > system_info/uptime.txt 2>&1
85+ cat /proc/loadavg > system_info/loadavg.txt 2>&1
86+
87+ # 2. HARDWARE INFORMATION
88+ echo_colored " Collecting hardware information..." " $GREEN "
89+ mkdir -p hardware
90+
91+ # PCI and USB devices
92+ lspci 2> /dev/null > hardware/lspci.txt || echo " lspci not available" > hardware/lspci.txt
93+ lsusb 2> /dev/null > hardware/lsusb.txt || echo " lsusb not available" > hardware/lsusb.txt
94+
95+ # Block devices and mounts
96+ blkid 2> /dev/null > hardware/blkid.txt || echo " blkid not available" > hardware/blkid.txt
97+ df -h > hardware/df.txt 2>&1
98+ mount > hardware/mount.txt 2>&1
99+ cat /proc/mounts > hardware/proc_mounts.txt 2>&1
100+
101+ # Network interfaces
102+ ip link show > hardware/network_interfaces.txt 2>&1
103+ ip addr show > hardware/ip_addr.txt 2>&1
104+
105+ # 3. KERNEL AND DRIVERS
106+ echo_colored " Collecting kernel and driver information..." " $GREEN "
107+ mkdir -p kernel
108+
109+ # Kernel modules
110+ lsmod 2> /dev/null > kernel/lsmod.txt || echo " lsmod not available" > kernel/lsmod.txt
111+ cat /proc/modules 2> /dev/null > kernel/proc_modules.txt || echo " No /proc/modules" > kernel/proc_modules.txt
112+
113+ # Kernel messages
114+ dmesg > kernel/dmesg.txt 2>&1
115+ tail -n 1000 /var/log/kern.log 2> /dev/null > kernel/kern_log.txt || echo " No kern.log" > kernel/kern_log.txt
116+
117+ # Kernel parameters
118+ cat /proc/cmdline > kernel/cmdline.txt 2>&1
119+ sysctl -a 2> /dev/null > kernel/sysctl.txt || echo " sysctl not available" > kernel/sysctl.txt
120+
121+ # 4. NETWORK INFORMATION
122+ echo_colored " Collecting network information..." " $GREEN "
123+ mkdir -p network
124+
125+ # Network configuration
126+ ip route show > network/route.txt 2>&1
127+ cat /etc/resolv.conf 2> /dev/null > network/resolv.conf || echo " No resolv.conf" > network/resolv.conf
128+ cat /etc/hosts 2> /dev/null > network/hosts || echo " No hosts file" > network/hosts
129+
130+ # Network connections
131+ ss -tulnp 2> /dev/null > network/ss.txt || netstat -tulnp 2> /dev/null > network/netstat.txt || echo " No network stat tool" > network/netstat.txt
132+
133+ # Firewall rules
134+ iptables -L -n -v 2> /dev/null > network/iptables.txt || echo " iptables not available" > network/iptables.txt
135+
136+ # Wlan devices
137+ iw dev 2> /dev/null > network/iw.txt || echo " iw not available" > network/iw.txt
138+
139+ # 5. PROCESS INFORMATION
140+ echo_colored " Collecting process information..." " $GREEN "
141+ mkdir -p processes
142+
143+ ps aux > processes/ps_aux.txt 2>&1
144+ top -b -n 1 > processes/top.txt 2>&1
145+
146+ # Service status (if systemd or init.d)
147+ if command -v systemctl > /dev/null 2>&1 ; then
148+ systemctl list-units --type=service > processes/services.txt 2>&1
149+ systemctl status > processes/systemctl_status.txt 2>&1
150+ elif [ -d " /etc/init.d" ]; then
151+ ls -la /etc/init.d/ > processes/initd_services.txt 2>&1
152+ fi
153+
154+ # 6. LOG FILES
155+ echo_colored " Collecting log files..." " $GREEN "
156+ mkdir -p logs
157+
158+ # System logs
159+ collect_log " /var/log/messages" " logs/messages.log"
160+ collect_log " /var/log/syslog" " logs/syslog.log"
161+ collect_log " /var/log/dmesg" " logs/dmesg.log"
162+ collect_log " /var/log/auth.log" " logs/auth.log"
163+ collect_log " /var/log/daemon.log" " logs/daemon.log"
164+
165+ # Application logs (common locations)
166+ for log in /var/log/* .log; do
167+ if [ -f " $log " ]; then
168+ base_name=$( basename " $log " )
169+ collect_log " $log " " logs/${base_name} "
170+ fi
171+ done
172+
173+ # 7. CONFIGURATION FILES
174+ echo_colored " Collecting configuration files..." " $GREEN "
175+ mkdir -p configs
176+
177+ # Common config files
178+ collect_file " /etc/fstab" " configs/fstab"
179+ collect_file " /etc/network/interfaces" " configs/network_interfaces"
180+ for file in /etc/network/interfaces.d/* ; do
181+ mkdir -p configs/network_interfaces.d/
182+ collect_file " $file " " configs/network_interfaces.d/$( basename $file ) "
183+ done
184+ for file in /etc/* wpa* .conf; do
185+ psk=$( grep -o ' psk="[^"]*"' " $file " | sed ' s/psk="//;s/"//' )
186+ if [ -n " $psk " ]; then
187+ psk_hash=$( echo -n " $psk " | sha256sum | cut -d" " -f1)
188+ sed " s/psk=\" $psk \" /psk=\" sha256sum($psk_hash )\" /" " $file " > " configs/$( basename $file ) "
189+ fi
190+ done
191+ collect_file " /etc/hostname" " configs/hostname"
192+ collect_file " /etc/timezone" " configs/timezone"
193+ collect_file " /etc/passwd" " configs/passwd"
194+ collect_file " /etc/group" " configs/group"
195+ collect_file " /etc/shadow" " configs/shadow"
196+ collect_file " /etc/shells" " configs/shells"
197+
198+ # Buildroot specific
199+ collect_file " /etc/buildroot-version" " configs/buildroot_version"
200+ collect_file " /etc/buildroot-build" " configs/buildroot_build"
201+
202+ # 8. PACKAGE INFORMATION
203+ echo_colored " Collecting package information..." " $GREEN "
204+ mkdir -p packages
205+
206+ # 9. ENVIRONMENT VARIABLES
207+ echo_colored " Collecting environment information..." " $GREEN "
208+ mkdir -p environment
209+
210+ env > environment/env.txt 2>&1
211+ set > environment/set.txt 2>&1
212+ printenv > environment/printenv.txt 2>&1
213+
214+ # 10. CUSTOM CHECKS
215+ echo_colored " Running custom checks..." " $GREEN "
216+ mkdir -p custom_checks
217+
218+ # Disk usage
219+ du -sh / 2> /dev/null | head -5 > custom_checks/disk_usage.txt || true
220+
221+ # Inode usage
222+ df -i > custom_checks/inode_usage.txt 2>&1
223+
224+ # List filesysten
225+ find / 2> /dev/null > custom_checks/file_list.txt
226+
227+ # 11. CREATE SUMMARY REPORT
228+ echo_colored " Creating summary report..." " $GREEN "
229+ cat > summary_report.txt << EOF
230+ SUPPORT DATA COLLECTION REPORT
231+ =============================
232+ Collection Time: $( date)
233+ Hostname: $( hostname 2> /dev/null || echo ' unknown' )
234+ Kernel: $( uname -r)
235+ Architecture: $( uname -m)
236+
237+ SYSTEM OVERVIEW:
238+ - Uptime: $( uptime -p 2> /dev/null || cat /proc/uptime | awk ' {print int($1/86400)" days "int(($1%86400)/3600)" hours"}' )
239+ - Load Average: $( cat /proc/loadavg 2> /dev/null || echo ' N/A' )
240+ - Memory: $( free -h | awk ' /^Mem:/ {print $3 "/" $2}' )
241+ - Storage: $( df -h / | awk ' NR==2 {print $3 "/" $2 " (" $5 " used)"}' )
242+
243+ NETWORK:
244+ - Interfaces: $( ip link show | grep -c ' ^[0-9]:' )
245+ - IP Addresses: $( ip addr show | grep -c ' inet ' )
246+
247+ PROCESSES:
248+ - Total: $( ps aux | wc -l)
249+ - Users: $( ps aux | awk ' {print $1}' | sort -u | wc -l)
250+
251+ COLLECTED DATA:
252+ - System Info: $( ls -1 system_info/ 2> /dev/null | wc -l) files
253+ - Hardware Info: $( ls -1 hardware/ 2> /dev/null | wc -l) files
254+ - Kernel Info: $( ls -1 kernel/ 2> /dev/null | wc -l) files
255+ - Network Info: $( ls -1 network/ 2> /dev/null | wc -l) files
256+ - Log Files: $( ls -1 logs/ 2> /dev/null | wc -l) files
257+ - Configuration: $( ls -1 configs/ 2> /dev/null | wc -l) files
258+
259+ NOTES:
260+ This archive contains troubleshooting data from your device.
261+ Share this file with support for assistance.
262+
263+ EOF
264+
265+ # 12. CREATE README
266+ cat > README.txt << 'EOF '
267+ DEVICE SUPPORT DATA COLLECTION
268+ ==============================
269+
270+ This archive contains system information collected for troubleshooting purposes.
271+
272+ CONTENTS:
273+ 1. system_info/ - Basic system information
274+ 2. hardware/ - Hardware and device information
275+ 3. kernel/ - Kernel and driver information
276+ 4. network/ - Network configuration and status
277+ 5. processes/ - Running processes and services
278+ 6. logs/ - System and application logs
279+ 7. configs/ - Configuration files
280+ 8. packages/ - Installed package information
281+ 9. environment/ - Environment variables
282+ 10. custom_checks/ - Additional diagnostic checks
283+
284+ FILES:
285+ - summary_report.txt - Overview of collected data
286+ - collection_script.sh - Copy of the collection script
287+
288+ SECURITY NOTES:
289+ - This archive may contain sensitive information
290+ - Review contents before sharing
291+ - The script does not collect:
292+ * Personal user files
293+ * Browser history
294+ * Passwords (except hashed from /etc/shadow)
295+ * Encryption keys
296+
297+ EOF
298+
299+ # 13. SAVE THE SCRIPT ITSELF
300+ cp " $0 " " ${COLLECTION_DIR} /collection_script.sh"
301+
302+ # 14. CREATE ZIP ARCHIVE
303+ echo_colored " Creating archive: ${OUTPUT_FILE} " " $GREEN "
304+ cd " ${COLLECTION_DIR} /.."
305+ if command -v zip > /dev/null 2>&1 ; then
306+ zip -rq " ${OUTPUT_FILE} " " $( basename ${COLLECTION_DIR} ) "
307+ echo_colored " Archive created successfully!" " $GREEN "
308+ echo_colored " Size: $( du -h ${OUTPUT_FILE} | cut -f1) " " $YELLOW "
309+ echo_colored " Please upload this file to support: ${OUTPUT_FILE} " " $YELLOW "
310+ else
311+ echo_colored " Warning: zip command not found. Creating tar archive instead." " $YELLOW "
312+ OUTPUT_FILE=" ${OUTPUT_FILE% .zip} .tar.gz"
313+ tar -cf - " $( basename ${COLLECTION_DIR} ) " | gzip -9 > " ${OUTPUT_FILE} "
314+ echo_colored " Archive created: ${OUTPUT_FILE} " " $GREEN "
315+ fi
316+
317+ # 15. CLEANUP
318+ echo_colored " Cleaning up temporary files..." " $GREEN "
319+ rm -rf " ${COLLECTION_DIR} "
320+
321+ # 16. FINAL INSTRUCTIONS
322+ cat << EOF
323+
324+ ============================================
325+ SUPPORT DATA COLLECTION COMPLETE
326+ ============================================
327+ Archive created: ${OUTPUT_FILE}
328+
329+ NEXT STEPS:
330+ 1. Check the file size is reasonable (typically 1-10MB)
331+ 2. Review the contents if privacy is a concern
332+ 3. Upload to your support portal
333+ 4. Provide this filename with your support request
334+
335+ EOF
336+
337+ exit 0
0 commit comments