Skip to content

Commit

Permalink
rewrite save_y2logs
Browse files Browse the repository at this point in the history
I originally just wanted to add linuxrc.log but ended up rewriting the script as
it suffered too much from copy-and-paste programming.

It now also supports uncompressed and xz-compressed tar archives and goes for xz
compression as default.

It now also logs /var/log/linuxrc.log, /var/log/wickedd.log, and /etc/X11/xorg.conf.d/.
  • Loading branch information
wfeldt committed Nov 24, 2015
1 parent 02d43f4 commit 7f0406b
Showing 1 changed file with 90 additions and 60 deletions.
150 changes: 90 additions & 60 deletions scripts/save_y2logs
Original file line number Diff line number Diff line change
Expand Up @@ -7,110 +7,140 @@

usage()
{
echo "Usage: $0 [<tgz-file-name>|<bzip2-file-name>]" >&2
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
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
TARGET=`mktemp --suffix .tar.gz /tmp/y2log-XXXXXX`
COMPRESSION=--gzip
# choose some good default
if [ -x /usr/bin/xz ] ; then
SUFFIX=.tar.xz
COMPRESSION=xz
elif [ -x /usr/bin/gzip ] ; then
SUFFIX=.tar.gz
COMPRESSION=gzip
elif [ -x /usr/bin/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)
TARGET="$1"
COMPRESSION=
;;

*.tgz|*.tar.gz)
TARGET="$1"
COMPRESSION=--gzip
COMPRESSION=gzip
;;

*.tar.bz2)
*.tar.xz)
TARGET="$1"
COMPRESSION=--bzip2
COMPRESSION=xz
;;

if [ ! -x /usr/bin/bzip2 ]; then
echo "FATAL: /usr/bin/bzip2 not available" >&2
# This might easily happen in the inst-sys
exit 3
fi
*.tar.bz2)
TARGET="$1"
COMPRESSION=bzip2
;;

*)
echo "FATAL: Uncompressed archives not supported" >&2
echo "Use one of: .tgz .tar.gz .tar.bz2" >&2
echo "FATAL: argument is not a (compressed) tar file." >&2
echo "Use one of these suffixes: .tar .tgz .tar.gz .tar.xz .tar.bz2" >&2
exit 4
esac
fi

# check for compression program
if [ "$COMPRESSION" -a ! -x "/usr/bin/$COMPRESSION" ]; then
echo "FATAL: /usr/bin/$COMPRESSION not available" >&2
exit 3
fi

TMPDIR=`mktemp -d` || ( echo "FATAL: Failed to create a temporary directory" >&2; exit 5 );
LIST=YaST2

if [ -f /var/log/evms-engine.log ]; then
LIST="$LIST $( cd /var/log/; ls evms-engine.*)"
fi

if [ -x /bin/dmesg ]; then
dmesg > $TMPDIR/dmesg
LIST="$LIST $TMPDIR/dmesg"
fi
# 1. gather some information in $TMPDIR

if [ -f /var/log/zypp/history ]; then
LIST="$LIST $( cd /var/log/; ls zypp/history*)"
# last kernel messages, if any
if [ -x /bin/dmesg ]; then
dmesg > $TMPDIR/dmesg
LIST_TMP="$LIST_TMP 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="$LIST $TMPDIR/install.inf"
sed 's/\(^WlanESSID: \|^WlanKey: \|^RootPassword: \|^VNCPassword: \|^Password: \).*$/\1XXXXXX/' </etc/install.inf >$TMPDIR/install.inf
LIST_TMP="$LIST_TMP install.inf"
fi

if [ -f /etc/X11/xorg.conf ]; then
LIST="$LIST /etc/X11/xorg.conf"
# 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

if [ -f /etc/X11/xorg.conf.install ]; then
LIST="$LIST /etc/X11/xorg.conf.install"
# installed packages
if [ -f /var/lib/rpm/Packages ]; 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

if [ -f /var/log/Xorg.0.log ]; then
LIST="$LIST /var/log/Xorg.0.log"
# rename, so people can see it
if [ -f /.packages.root ]; then
cp /.packages.root $TMPDIR/_packages.root
LIST_TMP="$LIST_TMP _packages.root"
fi

if [ -f /var/log/zypper.log ]; then
LIST="$LIST /var/log/zypper.log"
fi

if [ -f /var/log/pk_backend_zypp ]; then
LIST="$LIST /var/log/pk_backend_zypp"
fi
# 2. things from /var/log relevant for us

if [ -f /var/log/pbl.log ]; then
LIST="$LIST /var/log/pbl.log"
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
LIST="$LIST /mnt/var/log/pbl.log"
fi
VAR_LOG_FILES='\
YaST2 \
Xorg.0.log \
zypper.log zypp/history* pk_backend_zypp \
pbl.log linuxrc.log wickedd.log \
evms-engine.* \
'
cd /var/log
for i in $VAR_LOG_FILES ; do
[ -e "$i" ] && LIST_VAR="$LIST_VAR $i"
done
cd /

if [ -f /.packages.root ]; then
LIST="$LIST /.packages.root"
fi

RPM_LIST="rpm-qa"
if [ -f /var/lib/rpm/Packages ]; then
rpm -qa --qf '%{NAME}-%{VERSION}-%{RELEASE}\t\t\t(%{VENDOR})\t%{DISTRIBUTION}\n' 2>/dev/null | sort >/var/log/$RPM_LIST
fi
# 3. any other files

if [ -f /var/log/$RPM_LIST ]; then
LIST="$LIST $RPM_LIST"
fi
FILES='\
etc/X11/xorg.conf etc/X11/xorg.conf.install \
etc/X11/xorg.conf.d \
'
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" $COMPRESSION --dereference -C / $LIST -C /var/log $LIST_VAR -C $TMPDIR $LIST_TMP
err=$?

echo "Saving y2logs to $TARGET" >&2
rm -rf $TMPDIR

tar cf "$TARGET" $COMPRESSION --directory=/var/log --dereference $LIST && rm -rf $TMPDIR && exit 0
[ $err != 0 ] && echo "FATAL: Error creating archive $TARGET" >&2

echo "FATAL: Error creating archive $TARGET" >&2
exit 2
exit $err

0 comments on commit 7f0406b

Please sign in to comment.