git.infertux.com sysechk / master sysechk
master

Tree @master (Download .tar.gz)

sysechk @masterraw · history · blame

#!/bin/bash

#    This file is part of System Security Checker
#    Copyright (C) 2011-2016  Infertux <infertux@infertux.com>
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program 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 Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

export TESTS=tests
export REPORTS=reports

. $(dirname $0)/lib/sysechk.sh
cd $(dirname $0)

$VERBOSE && echo "Purging old reports…"
rm -f $REPORTS/*

$VERBOSE && echo "Running tests…"
[ "$(ls -A $TESTS)" ] || FATAL "No tests found!"

set +e
# execute all tests in parallel, yeah Bash!
find $TESTS -name "*.sh" -print0 | xargs -0 -n1 -P0 ./lib/run_test.sh "$ARGS"
xcode=$?
set -e

fail=$(wc -l reports/*.txt | tail -1 | awk '{print $1}')
reports=$(ls $REPORTS | wc -w)
echo -ne "\x1b\x5b\x32\x4b" # send VT100 escape code ^[[2K to erase the line
echo "$reports tests ran in $SECONDS seconds."

if [ $fail -eq 0 ]; then
    SUCCESS "All tests passed, your system seems quite secure!"
else
    WARNING "$fail problems detected:"
    grep '' $REPORTS/*.txt | sed -r 's@.*/(.*)\.txt:(.*)$@\1 \t\2@' >&2
fi

# create the output file if requested
[ "$OUTPUT_FILE" ] && \
    find $REPORTS -name "*.txt" -not -empty | sed -r 's@.*/(.*)\.txt$@\1@' > $OUTPUT_FILE

$VERBOSE && echo "Done."

exit $fail