#!/bin/sh

set -e

TOMB=/usr/bin/tomb

# tomb writes non-error output to stderr.
# That's why we redirect it to stdout by 2>&1.
zsh -e $TOMB dig   -s 20 test.tomb 2>&1
# Make sure the kdf binaries are used during key generation by applying --kdf
zsh -e $TOMB forge --unsafe -f --tomb-pwd somepw --kdf 1 test.key 2>&1
# Stop test here if the environment has no loop device available
if ! losetup -f >/dev/null 2>&1; then
	echo No loop device available, cutting test short.
	exit 0
fi
# Continue test with commands requiring a loop device
zsh -e $TOMB lock  --unsafe -f --tomb-pwd somepw -k test.key test.tomb 2>&1
zsh -e $TOMB open  --unsafe -f --tomb-pwd somepw -k test.key test.tomb 2>&1
echo Copying some data into the opened tomb ...
cp -a test.key /media/test
echo Opened tomb\'s content:
ls -la /media/test
zsh -e $TOMB close test 2>&1
