#!/bin/sh

set -e

TOMB=/usr/bin/tomb

# 'dig' and 'forge' call dd which write non-error output to stderr
# that's why we redirect it to stdout by 2>&1
zsh -e $TOMB dig   -s 20 x.tomb 2>&1
# Make sure the kdf binaries are used during key generation by applying --kdf
zsh -e $TOMB forge --unsafe -f --tomb-pwd x --kdf 1 x.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 x -k x.key x.tomb
zsh -e $TOMB open  --unsafe -f --tomb-pwd x -k x.key x.tomb
echo Copying some data into the opened tomb
cp -a x.key /media/x
echo Opened tomb\'s content:
ls -la /media/x
zsh -e $TOMB close x
