ACC SHELL

Path : /sbin/
File Upload :
Current File : //sbin/save_y2logs

#!/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>

usage()
{
    echo "Usage: $0 <tgz-file-name>|<bzip2-file-name>" >&2
    echo "" >&2
    echo "Copies the YaST2 logs to a compressed tar archive." >&2
    exit 1
}

test -z "$1" && usage

case "$1" in
    -*)
	usage
	;;

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

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

	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
	;;

    *)
	echo "FATAL: Uncompressed archives not supported" >&2
	echo "Use one of: .tgz .tar.gz .tar.bz2"          >&2
	exit 4
esac

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

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

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"
fi

if [ -f /etc/X11/xorg.conf ]; then
    LIST="$LIST /etc/X11/xorg.conf"
fi

if [ -f /var/log/Xorg.0.log ]; then
    LIST="$LIST /var/log/Xorg.0.log"
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

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

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

echo "Saving y2logs to $TARGET" >&2

tar cf "$TARGET" $COMPRESSION --directory=/var/log $LIST && rm -rf $TMPDIR && exit 0

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

ACC SHELL 2018