31
31
# # And then later:
32
32
# DAHDI_VIRT_TOP="$PWD/my_sys_state" dahdi_genconf
34
name=dahdi_sys_state_dump
37
echo "$0: dump system data for Dahdi-Perl"
38
echo "Usage: $0 [<name>]]"
40
echo "<name>: name of directory/tarball to create. Default: $name"
48
gzip -9 >$name.cpio.gz
35
dahdi_sysfs_copy="$mydir/dahdi_sysfs_copy"
59
37
# Give usage message on expected texts
61
help | -* ) usage; exit 1;;
64
if [ "$1" != '' ]; then
68
# funky permissions on procfs. Sadly rm -f does not kill them.
69
if [ -d "$name" ]; then
75
# delete a (potentially empty) list of files
77
xargs rm -f rm_files_non_existing_file
39
if [ "$#" -ne 0 ]; then
44
id="sys_dump.`hostname`_`date +%F_%H.%M.%S`"
47
tmpdir=`mktemp -td 'dahdi_dump.XXXXXX'`
48
echo -n >&2 "Creating ... "
49
trap "[ -d '$tmpdir' ] && rm -rf '$tmpdir'" 0 1 2 15
80
53
if [ -r /proc/bus/usb/devices ]; then
81
mkdir -p "$name/proc/bus/usb"
82
cp -a /proc/bus/usb/devices "$name/proc/bus/usb/"
54
mkdir -p "$topdir/proc/bus/usb"
55
cp -a /proc/bus/usb/devices "$topdir/proc/bus/usb/"
85
58
if [ -d /proc/dahdi ]; then
86
mkdir -p "$name/proc/dahdi"
59
mkdir -p "$topdir/proc/dahdi"
87
60
if find /proc/dahdi -type f >/dev/null; then
88
cp -a /proc/dahdi/* "$name/proc/dahdi/"
61
cp -a /proc/dahdi/* "$topdir/proc/dahdi/"
92
65
if [ -d /proc/xpp ]; then
93
mkdir -p "$name/proc/xpp"
66
mkdir -p "$topdir/proc/xpp"
94
67
if find /proc/xpp -type f >/dev/null; then
95
cp -a /proc/xpp/* "$name/proc/xpp/"
96
find "$name/proc/xpp" -type f -name command | rm_files
68
cp -a /proc/xpp/* "$topdir/proc/xpp/"
69
find "$topdir/proc/xpp" -type f -name command -exec rm -f '{}' ';'
100
# FIXME: the following grab tons of files from sysfs. Any way to do with
102
pci_dev_pat='/sys/devices/pci*'
103
mkdir -p "$name/sys/devices"
104
cp -a $pci_dev_pat "$name/sys/devices/" 2>/dev/null
106
for bus in astribanks xpds pci pci_express usb; do
107
if [ -d /sys/bus/$bus ]; then
108
mkdir -p "$name/sys/bus/"
109
cp -a /sys/bus/$bus "$name/sys/bus/" 2>/dev/null
113
# Remove PCI devices of irelevan classes:
115
grep . "$name"/$pci_dev_pat/0*/class "$name"/$pci_dev_pat/0*/0*/class \
116
| perl -n -e '# Perl provides commented regexes:
117
next unless m{/class:( # The following is a list of device classes
118
# that can be safely removed:
119
0x060000 | # Host bridge
120
0x030000 | # VGA compatible controller
121
0x038000 | # Display controller
122
0x040300 | # Audio device
123
0x060401 | # PCI bridge
124
0x060100 | # ISA bridge
125
0x01018a | # IDE interface
126
0x01018f | # IDE interface
128
0x060700 | # CardBus bridge
129
0x0c0010 | # FireWire (IEEE 1394)
130
# The following are not to be removed:
131
#0x0c0300 | # USB Controller (UHCI?)
132
#0x060400 | # PCI bridge
133
#0x0c0320 | # USB Controller (EHCI?)
134
#0x020000 | # Ethernet controller
135
#0x0c0010 | # Network controller: (Wifi?)
137
# Leave out just the name of the node:
144
# FIXME: deleting those seems to remove common 'vendor' directories
145
# and mess things up. Skip it for now.
146
#rm -rf `irrelevant_devs`
73
"$dahdi_sysfs_copy" "$topdir"
74
echo -n >&2 "tarball ... "
75
( cd "$tmpdir" && tar czf - . ) > "$tarball";
76
echo >&2 "ready in '$tarball'"