#!/bin/sh

#
# Script to save the powersave logfiles. Intended to use for bugreports.
# So when something went wrong with powersave you simply have to execute
# this script. The resulting tarball in the current working directory
# contains the powersave logfiles.
#
# At the moment the logfiles are /var/log/suspend2disk.log and
# /var/log/suspend2ram.log. This may change in the future.
#
# Author:  Holger Macht
# Contact: hmacht@suse.de
#

LOGDIR="/var"
LOGFILES="log/suspend2disk.log log/suspend2ram.log log/standby.log"
STATEFILES="`echo lib/suspend2{disk,ram}-state{,.resume} lib/standby-state{,.resume}`"
ARCHIVE="./powersave_logs.tar.gz"

echo -e "\nTrying to save powersave logfiles..."

CWD=`pwd`
pushd /var >/dev/null
tar -czf $CWD/$ARCHIVE $LOGFILES $STATEFILES >/dev/null 2>&1
popd >/dev/null
RESULT=`tar -tzf $ARCHIVE`

if test "$RESULT" != ""; then
    echo -e "\nFile(s) saved to $ARCHIVE:"
    for i in $RESULT; do
	echo -e "\t $LOGDIR/$i"
    done

    echo -e "--> done\n"
else
    rm $ARCHIVE
    echo -e "\nFile(s) which could not be saved:"
    for i in $LOGFILES; do
        echo -e "\t $LOGDIR/$i"
    done
    echo -e "--> failed\n"
fi
