#!/bin/sh

set -e

DEBIAN_TREE='/usr/local/src/debian'
DISLOCKER_RESOURCE_TREE=$DEBIAN_TREE/tmp/dislocker

# Check for needed resources
if [ ! -d $DEBIAN_TREE ]; then
	echo "tree '$DEBIAN_TREE' is missing"
	exit 77
fi
for cmd in dislocker tree mount umount mkdir rmdir sleep; do 
	if ! command -v $cmd >/dev/null; then
		echo "command '$cmd' is missing"
		exit 77
	fi
done

# Create mount points
mkdir /mnt/dislocked
mkdir /mnt/content

# Do the actual tests
dislocker \
	-V $DISLOCKER_RESOURCE_TREE/sg64mp1.raw \
	-p$(cat $DISLOCKER_RESOURCE_TREE/sg64m-recovery-key.txt) \
	-- \
	/mnt/dislocked
tree /mnt/
mount -o loop /mnt/dislocked/dislocker-file /mnt/content
tree /mnt/content

# Drop mount points
umount /mnt/content
rmdir /mnt/content
umount /mnt/dislocked
rmdir /mnt/dislocked
