2010-08-18 21:49:24 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# dump_sys_state: dump some /sys and /proc files to a directory.
|
|
|
|
# $Id$
|
|
|
|
#
|
|
|
|
# Written by Tzafrir Cohen <tzafrir.cohen@xorcom.com>
|
|
|
|
# Copyright (C) 2009, Xorcom
|
|
|
|
#
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
# 02110-1301, USA
|
|
|
|
|
|
|
|
# The DAHDI-perl modules will use such a dump instead of the files from
|
|
|
|
# the real system if DAHDI_VIRT_TOP is set to the root.
|
|
|
|
#
|
|
|
|
# ./build_tools/dump_sys_state my_sys_state
|
|
|
|
#
|
|
|
|
# # And then later:
|
|
|
|
# DAHDI_VIRT_TOP="$PWD/my_sys_state" dahdi_genconf
|
|
|
|
|
2012-03-16 04:41:49 +08:00
|
|
|
mydir=`dirname $0`
|
|
|
|
dahdi_sysfs_copy="$mydir/dahdi_sysfs_copy"
|
2010-08-18 21:49:24 +08:00
|
|
|
|
|
|
|
# Give usage message on expected texts
|
|
|
|
|
2012-03-16 04:41:49 +08:00
|
|
|
if [ "$#" -ne 0 ]; then
|
|
|
|
echo >&2 "Usage: $0"
|
|
|
|
exit 1
|
2010-08-18 21:49:24 +08:00
|
|
|
fi
|
|
|
|
|
2012-03-16 04:41:49 +08:00
|
|
|
id="sys_dump.`hostname`_`date +%F_%H.%M.%S`"
|
|
|
|
tarball="$id.tar.gz"
|
|
|
|
|
|
|
|
tmpdir=`mktemp -td 'dahdi_dump.XXXXXX'`
|
|
|
|
echo -n >&2 "Creating ... "
|
|
|
|
trap "[ -d '$tmpdir' ] && rm -rf '$tmpdir'" 0 1 2 15
|
2010-08-18 21:49:24 +08:00
|
|
|
|
2012-03-16 04:41:49 +08:00
|
|
|
topdir="$tmpdir/$id"
|
2010-08-18 21:49:24 +08:00
|
|
|
|
|
|
|
if [ -r /proc/bus/usb/devices ]; then
|
2012-03-16 04:41:49 +08:00
|
|
|
mkdir -p "$topdir/proc/bus/usb"
|
|
|
|
cp -a /proc/bus/usb/devices "$topdir/proc/bus/usb/"
|
2010-08-18 21:49:24 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -d /proc/dahdi ]; then
|
2012-03-16 04:41:49 +08:00
|
|
|
mkdir -p "$topdir/proc/dahdi"
|
2010-08-18 21:49:24 +08:00
|
|
|
if find /proc/dahdi -type f >/dev/null; then
|
2012-03-16 04:41:49 +08:00
|
|
|
cp -a /proc/dahdi/* "$topdir/proc/dahdi/"
|
2010-08-18 21:49:24 +08:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -d /proc/xpp ]; then
|
2012-03-16 04:41:49 +08:00
|
|
|
mkdir -p "$topdir/proc/xpp"
|
2010-08-18 21:49:24 +08:00
|
|
|
if find /proc/xpp -type f >/dev/null; then
|
2012-03-16 04:41:49 +08:00
|
|
|
cp -a /proc/xpp/* "$topdir/proc/xpp/"
|
|
|
|
find "$topdir/proc/xpp" -type f -name command -exec rm -f '{}' ';'
|
2010-08-18 21:49:24 +08:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2012-03-16 04:41:49 +08:00
|
|
|
"$dahdi_sysfs_copy" "$topdir"
|
|
|
|
echo -n >&2 "tarball ... "
|
|
|
|
( cd "$tmpdir" && tar czf - . ) > "$tarball";
|
|
|
|
echo >&2 "ready in '$tarball'"
|