summaryrefslogtreecommitdiff
path: root/build_tools/dump_sys_state
blob: 12e864fe6fc4b4bcae9fb95c91a9b81ae01ddca1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/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

mydir=`dirname $0`
dahdi_sysfs_copy="$mydir/dahdi_sysfs_copy"

# Give usage message on expected texts

if [ "$#" -ne 0 ]; then
	echo >&2 "Usage: $0"
	exit 1
fi

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

topdir="$tmpdir/$id"

if [ -r /proc/bus/usb/devices ]; then
	mkdir -p "$topdir/proc/bus/usb"
	cp -a /proc/bus/usb/devices "$topdir/proc/bus/usb/"
fi

if [ -d /proc/dahdi ]; then
	mkdir -p "$topdir/proc/dahdi"
	if find /proc/dahdi -type f >/dev/null; then
		cp -a /proc/dahdi/* "$topdir/proc/dahdi/"
	fi
fi

if [ -d /proc/xpp ]; then
	mkdir -p "$topdir/proc/xpp"
	if find /proc/xpp -type f >/dev/null; then
		cp -a /proc/xpp/* "$topdir/proc/xpp/"
		find "$topdir/proc/xpp" -type f -name command -exec rm -f '{}' ';'
	fi
fi

"$dahdi_sysfs_copy" "$topdir"
echo -n >&2 "tarball ... "
( cd "$tmpdir" && tar czf - . ) > "$tarball";
echo >&2 "ready in '$tarball'"