~ubuntu-branches/ubuntu/saucy/dahdi-tools/saucy

« back to all changes in this revision

Viewing changes to build_tools/dump_sys_state

  • Committer: Stefan Lesicnik
  • Date: 2011-05-08 12:22:46 UTC
  • mfrom: (2.1.4 sid)
  • Revision ID: stefan@lsd.co.za-20110508122246-lh6k2x1uy8pl3vdi
Tags: 1:2.4.1-1ubuntu1
* Merge from Debian. Remaining changes:
  - Bug Fix: If linux-headers are not installed, don't block, and print
    information for the user.
  - added debian/dahdi.postinst
  - added --error-handler=init_failed to debian/rules
  - Changes from Debian:
    - debian/control: Change Maintainer
    - debian/control: Removed Uploaders field.
    - debian/control: Removed Debian Vcs-Svn entry and replaced with
      ubuntu-voip Vcs-Bzr, to reflect divergence in packages.
    - debian/control: Package dahdi Depends on dahdi-dkms | dahdi-source
* debian/control: Added gawk as dependency for dkms build (LP: #493304)
* New upstream release (Closes: #581076, #582094).
* Patches hardware_rescan, perl_fix_noserial, perl_fix_transportdir,
  astribank_allow_ignoreend, init_unload_modules and wcb4xxp_extra_trunk
  dropped: merged upstream.
* dahdi-linux 2.3.0 is required (extra config options for dahdi_cfg).
* Convert to dpkg v.3 format.
* Standards version: 3.9.1.0 (No change needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
# dump_sys_state: dump some /sys and /proc files to a directory.
 
4
# $Id: dump_sys_state 8211 2010-03-02 14:55:22Z tzafrir $
 
5
#
 
6
# Written by Tzafrir Cohen <tzafrir.cohen@xorcom.com>
 
7
# Copyright (C) 2009, Xorcom
 
8
#
 
9
# All rights reserved.
 
10
#
 
11
# This program is free software; you can redistribute it and/or modify
 
12
# it under the terms of the GNU General Public License as published by
 
13
# the Free Software Foundation; either version 2 of the License, or
 
14
# (at your option) any later version.
 
15
#
 
16
# This program is distributed in the hope that it will be useful,
 
17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
19
# GNU General Public License for more details.
 
20
#
 
21
# You should have received a copy of the GNU General Public License
 
22
# along with this program; if not, write to the Free Software
 
23
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
24
# 02110-1301, USA
 
25
 
 
26
# The DAHDI-perl modules will use such a dump instead of the files from
 
27
# the real system if DAHDI_VIRT_TOP is set to the root.
 
28
#
 
29
#  ./build_tools/dump_sys_state my_sys_state
 
30
#
 
31
#  # And then later:
 
32
#  DAHDI_VIRT_TOP="$PWD/my_sys_state" dahdi_genconf
 
33
 
 
34
name=dahdi_sys_state_dump
 
35
 
 
36
usage() {
 
37
  echo "$0: dump system data for Dahdi-Perl"
 
38
  echo "Usage: $0 [<name>]]"
 
39
  echo ""
 
40
  echo "<name>: name of directory/tarball to create. Default: $name"
 
41
}
 
42
 
 
43
output_tar() {
 
44
  gzip -9 >$name.tar.gz
 
45
}
 
46
 
 
47
output_cpio() {
 
48
  gzip -9 >$name.cpio.gz
 
49
}
 
50
 
 
51
output_dir() {
 
52
  rm -rf $name
 
53
  mkdir -p $name
 
54
  cd $name
 
55
  #tar xf -
 
56
  cpio -id
 
57
}
 
58
 
 
59
# Give usage message on expected texts
 
60
case $1 in 
 
61
  help | -* ) usage; exit 1;;
 
62
esac
 
63
 
 
64
if [ "$1" != '' ]; then
 
65
  name="$1"
 
66
fi
 
67
 
 
68
# funky permissions on procfs. Sadly rm -f does not kill them.
 
69
if [ -d "$name" ]; then
 
70
  chmod -R u+w "$name"
 
71
fi
 
72
rm -rf "$name"
 
73
mkdir -p "$name"
 
74
 
 
75
# delete a (potentially empty) list of files
 
76
rm_files() {
 
77
        xargs rm -f rm_files_non_existing_file
 
78
}
 
79
 
 
80
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/"
 
83
fi
 
84
 
 
85
if [ -d /proc/dahdi ]; then
 
86
        mkdir -p "$name/proc/dahdi"
 
87
        if find /proc/dahdi -type f >/dev/null; then
 
88
                cp -a /proc/dahdi/* "$name/proc/dahdi/" 
 
89
        fi
 
90
fi
 
91
 
 
92
if [ -d /proc/xpp ]; then
 
93
        mkdir -p "$name/proc/xpp"
 
94
        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
 
97
        fi
 
98
fi
 
99
 
 
100
# FIXME: the following grab tons of files from sysfs. Any way to do with
 
101
# less information?
 
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
 
105
 
 
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
 
110
        fi
 
111
done
 
112
 
 
113
# Remove PCI devices of irelevan classes:
 
114
irrelevant_devs() {
 
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
 
127
                        0x0c0500 | # SMBus
 
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?)
 
136
                )$}x;
 
137
                # Leave out just the name of the node:
 
138
                s{/[^/]*$}{};
 
139
                print;
 
140
                print "\n"
 
141
        '
 
142
}
 
143
 
 
144
# FIXME: deleting those seems to remove common 'vendor' directories
 
145
# and mess things up. Skip it for now.
 
146
#rm -rf `irrelevant_devs`
 
147