-
Notifications
You must be signed in to change notification settings - Fork 43
/
save_y2logs
executable file
·155 lines (123 loc) · 3.63 KB
/
save_y2logs
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/bash
#
# save_y2logs - save YaST2 logs to a compressed tar file
# to attach it to a Bugzilla bug report
#
# Author: Stefan Hundhammer <sh@suse.de>
PATH=/usr/sbin:/usr/bin:/sbin:/bin
usage()
{
echo "Usage: ${0##*/} [ARCHIVE_NAME]" >&2
echo "" >&2
echo "Copies the YaST2 logs to a (compressed) tar archive." >&2
echo "If file name is missing it is generated by the script." >&2
exit 1
}
if test -z "$1"; then
# choose some good default
if [ "$(type -p xz)" ] ; then
SUFFIX=.tar.xz
COMPRESSION=xz
elif [ "$(type -p gzip)" ] ; then
SUFFIX=.tar.gz
COMPRESSION=gzip
elif [ "$(type -p bzip2)" ] ; then
SUFFIX=.tar.bz2
COMPRESSION=bzip2
else
SUFFIX=.tar
COMPRESSION=
fi
TARGET=`mktemp --suffix $SUFFIX /tmp/y2log-XXXXXX`
else
case "$1" in
-*)
usage
;;
*.tar)
COMPRESSION=
;;
*.tgz|*.tar.gz)
COMPRESSION=gzip
;;
*.txz|*.tar.xz)
COMPRESSION=xz
;;
*.tar.bz2)
COMPRESSION=bzip2
;;
*)
echo "FATAL: argument is not a (compressed) tar file." >&2
echo "Use one of these suffixes: .tar .tgz .tar.gz .txz .tar.xz .tar.bz2" >&2
exit 4
esac
# use full path
TARGET=$(readlink -m "$1")
fi
# check for compression program
if [ "$COMPRESSION" -a -z "$(type -p $COMPRESSION)" ]; then
echo "FATAL: $COMPRESSION not available" >&2
exit 3
fi
TMPDIR=`mktemp -d` || ( echo "FATAL: Failed to create a temporary directory" >&2; exit 5 );
# 1. gather some information in $TMPDIR
# last kernel messages, if any
if [ "$(type -p dmesg)" ]; then
dmesg > $TMPDIR/dmesg
LIST_TMP="$LIST_TMP dmesg"
fi
if [ "$(type -p journalctl)" ]; then
journalctl --dmesg > $TMPDIR/journalctl-dmesg
LIST_TMP="$LIST_TMP journalctl-dmesg"
fi
# strip sensitive information
if [ -f /etc/install.inf ]; then
sed 's/\(^WlanESSID: \|^WlanKey: \|^RootPassword: \|^VNCPassword: \|^Password: \).*$/\1XXXXXX/' </etc/install.inf >$TMPDIR/install.inf
LIST_TMP="$LIST_TMP install.inf"
fi
# if storing logs at the end of installation after bootloader fail, try to store pbl log from target system
if [ -f /mnt/var/log/pbl.log ]; then
cp /mnt/var/log/pbl.log $TMPDIR/pbl-target.log
LIST_TMP="$LIST_TMP pbl-target.log"
fi
# installed packages
if [ -f /var/lib/rpm/Packages -a "$(type -p rpm)" ]; then
rpm -qa --qf '%{NAME}-%{VERSION}-%{RELEASE}\t\t\t(%{VENDOR})\t%{DISTRIBUTION}\n' 2>/dev/null | sort >/$TMPDIR/rpm-qa
LIST_TMP="$LIST_TMP rpm-qa"
fi
# rename, so people can see it
if [ -f /.packages.root ]; then
cp /.packages.root $TMPDIR/_packages.root
LIST_TMP="$LIST_TMP _packages.root"
fi
# 2. things from /var/log relevant for us
VAR_LOG_FILES='\
YaST2 \
Xorg.0.log \
zypper.log zypp/history* pk_backend_zypp \
pbl.log linuxrc.log wickedd.log \
evms-engine.* \
boot.msg messages udev.log \
'
cd /var/log
for i in $VAR_LOG_FILES ; do
[ -e "$i" ] && LIST_VAR="$LIST_VAR $i"
done
cd /
# 3. any other files
FILES='\
etc/X11/xorg.conf etc/X11/xorg.conf.install \
etc/X11/xorg.conf.d linuxrc.config etc/os-release \
'
for i in $FILES ; do
[ -e "$i" ] && LIST="$LIST $i"
done
echo "Saving YaST logs to $TARGET" >&2
[ -n "$COMPRESSION" ] && COMPRESSION="--$COMPRESSION"
tar cf "$TARGET" --warning=no-file-changed $COMPRESSION --dereference -C / $LIST -C /var/log $LIST_VAR -C $TMPDIR $LIST_TMP
err=$?
rm -rf $TMPDIR
# tar returns 1 when content of tarball is older than the current system. Happen when something still writting to logs or memsampler (bsc#1182710#c2)
[ $err == 1 ] && echo "Warning: logs modified during save. Yast is probably running. Content of tarball can be older than current content." >&2 && err=0
[ $err != 0 ] && echo "FATAL: Error creating archive $TARGET" >&2
exit $err