-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcrash_report.sh
executable file
·93 lines (73 loc) · 2.9 KB
/
crash_report.sh
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/sh
##############################################################################
## Copyright (c) 2006-2011, Calaos. All Rights Reserved.
##
## This file is part of Calaos Home.
##
## Calaos Home 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 3 of the License, or
## (at your option) any later version.
##
## Calaos Home 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 Foobar; if not, write to the Free Software
## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
##
##############################################################################
## crash reporter. compress backtrace with system info and send it to calaos.fr
BTPATH="/mnt/ext3/backtraces"
mkdir -p $BTPATH
if [ $# -gt 1 ] ; then
process="$1"
dump_id="$2"
if [ ! -f $BTPATH/$dump_id.dmp ] ; then
echo "Can't find file $BTPATH/$dump_id.dmp"
exit 1;
fi
#create an archive of system files
(cd $BTPATH ;
mkdir -p $dump_id ;
cd $dump_id ;
cp ../$dump_id.dmp /etc/calaos/io.xml /etc/calaos/rules.xml /etc/calaos/local_config.xml /etc/calaos/simple_scenarios.xml /var/log/message* /etc/BUILD /etc/VERSION . ;
tar -cjf ../bt_${process}_${dump_id}.tar.bz2 * )
#clean everything
rm -fr $BTPATH/$dump_id $BTPATH/$dump_id.dmp
exit 0;
fi
#Lock file, avoid multiple instance of the script
test -f /tmp/.send_backtrace.lock && logger -t crash_report -- "script already running? exiting..." && exit 1
touch /tmp/.send_backtrace.lock
CALAOS_URL="https://www.calaos.fr/calaos_network/api.php"
HWID=`/sbin/calaos_config get hwid`
CNUSER=`/sbin/calaos_config get cn_user`
CNPASS=`/sbin/calaos_config get cn_pass`
if [ "$HWID" = "" ] ; then
exit 1;
fi
if [ "$CNUSER" = "" ] ; then
exit 1;
fi
if [ "$CNPASS" = "" ] ; then
exit 1;
fi
for bt in `ls ${BTPATH}/bt_*.tar.bz2` ; do
btname=`basename $bt`;
encoded=`uuencode -m $bt $btname`;
JSON="{\"cn_user\":\"${CNUSER}\",\"cn_pass\":\"${CNPASS}\",\"hwid\":\"${HWID}\",\"action\":\"upload_backtrace\"}"
curl --form "json=$JSON;type=application/json" --form file=@$bt --insecure --silent --output /dev/null $CALAOS_URL
if [ $? -eq 1 ]
then
logger -t crash_report -- "Error sending crash backtrace"
exit 1;
fi
logger -t crash_report -- "Crash report $bt successfully sent."
#delete backtrace
rm -f $bt
done
#remove the lock
rm -f /tmp/.send_backtrace.lock