| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# dump_sys_state: dump some /sys and /proc files to a directory. |
| 4 |
# $Id$ |
| 5 |
# |
| 6 |
# Written by Tzafrir Cohen <[email protected]> |
| 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 |
mydir=`dirname $0` |
| 35 |
dahdi_sysfs_copy="$mydir/dahdi_sysfs_copy" |
| 36 |
|
| 37 |
# Give usage message on expected texts |
| 38 |
|
| 39 |
if [ "$#" -ne 0 ]; then |
| 40 |
echo >&2 "Usage: $0" |
| 41 |
exit 1 |
| 42 |
fi |
| 43 |
|
| 44 |
id="sys_dump.`hostname`_`date +%F_%H.%M.%S`" |
| 45 |
tarball="$id.tar.gz" |
| 46 |
|
| 47 |
tmpdir=`mktemp -td 'dahdi_dump.XXXXXX'` |
| 48 |
echo -n >&2 "Creating ... " |
| 49 |
trap "[ -d '$tmpdir' ] && rm -rf '$tmpdir'" 0 1 2 15 |
| 50 |
|
| 51 |
topdir="$tmpdir/$id" |
| 52 |
|
| 53 |
if [ -r /proc/bus/usb/devices ]; then |
| 54 |
mkdir -p "$topdir/proc/bus/usb" |
| 55 |
cp -a /proc/bus/usb/devices "$topdir/proc/bus/usb/" |
| 56 |
fi |
| 57 |
|
| 58 |
if [ -d /proc/dahdi ]; then |
| 59 |
mkdir -p "$topdir/proc/dahdi" |
| 60 |
if find /proc/dahdi -type f >/dev/null; then |
| 61 |
cp -a /proc/dahdi/* "$topdir/proc/dahdi/" |
| 62 |
fi |
| 63 |
fi |
| 64 |
|
| 65 |
if [ -d /proc/xpp ]; then |
| 66 |
mkdir -p "$topdir/proc/xpp" |
| 67 |
if find /proc/xpp -type f >/dev/null; then |
| 68 |
cp -a /proc/xpp/* "$topdir/proc/xpp/" |
| 69 |
find "$topdir/proc/xpp" -type f -name command -exec rm -f '{}' ';' |
| 70 |
fi |
| 71 |
fi |
| 72 |
|
| 73 |
"$dahdi_sysfs_copy" "$topdir" |
| 74 |
echo -n >&2 "tarball ... " |
| 75 |
( cd "$tmpdir" && tar czf - . ) > "$tarball"; |
| 76 |
echo >&2 "ready in '$tarball'" |