62 lines
1.4 KiB
Bash
62 lines
1.4 KiB
Bash
|
#!/bin/bash
|
||
|
|
||
|
# This script is meant to find ram-errors via the
|
||
|
# use of LUKS.
|
||
|
# Usage: ./ramtest.sh <numberOfRuns>
|
||
|
|
||
|
if
|
||
|
which pwgen >/dev/null && which dd >/dev/null && which cryptsetup >/dev/null
|
||
|
then
|
||
|
echo "pwgen, dd and luks available. Continue."
|
||
|
else
|
||
|
echo "pwgen, dd and/or luks not installed. Aborting."
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
if [[ -n $1 ]] && [[ $1 =~ ^[0-9]+$ ]]
|
||
|
then
|
||
|
COUNT=$1
|
||
|
echo "Number of runs is $COUNT"
|
||
|
else
|
||
|
echo "Value not a number or no value given"
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
TMPDIR=$(mktemp -d)
|
||
|
echo "Creating temp-dir $TMPDIR"
|
||
|
|
||
|
PW=$(pwgen 64 -1)
|
||
|
PWFILE="$TMPDIR/pw"
|
||
|
|
||
|
echo $PW > $PWFILE
|
||
|
|
||
|
echo "Creating temporary image with the size 1000MB"
|
||
|
dd if=/dev/urandom of=$TMPDIR/ramtest.img bs=1M count=1000 2>/dev/null
|
||
|
|
||
|
echo "Formatting image with luks"
|
||
|
cryptsetup luksFormat $TMPDIR/ramtest.img < $PWFILE
|
||
|
> $TMPDIR/log
|
||
|
for i in $(seq 1 $COUNT)
|
||
|
do
|
||
|
echo "Run number $i of $COUNT"
|
||
|
cryptsetup luksOpen --test-passphrase $TMPDIR/ramtest.img < $PWFILE 2>/dev/null
|
||
|
RES=$?
|
||
|
if [[ $RES -eq 0 ]]
|
||
|
then
|
||
|
echo "0" >> $TMPDIR/log
|
||
|
else
|
||
|
echo "1" >> $TMPDIR/log
|
||
|
fi
|
||
|
unset RES
|
||
|
done
|
||
|
|
||
|
echo -e "\n\
|
||
|
Result: \n\
|
||
|
Number of runs: $COUNT \n\
|
||
|
Successful runs: $(grep ^0$ $TMPDIR/log | wc -l) \n\
|
||
|
Unsuccessful runs: $(grep ^1$ $TMPDIR/log | wc -l) \n"
|
||
|
|
||
|
echo "Removing temp-dir $TMPDIR"
|
||
|
rm -Rf $TMPDIR
|
||
|
exit 0
|