#!/bin/bash

set -e

if [ -z "$1" ]; then
  echo "Usage: $0 <volume_filename>"
  exit 1
fi

FILE="/data/$1"
MAPPER_NAME="encrypted_volume"
MOUNT_POINT="/mnt/${MAPPER_NAME}"
dd if=/dev/zero of="$FILE" bs=1M count=10


echo "Setting up LUKS on $FILE..."
cryptsetup luksFormat "$FILE"
cryptsetup close "$MAPPER_NAME" || true

cryptsetup open "$FILE" "$MAPPER_NAME"

mkfs.ext4 /dev/mapper/"$MAPPER_NAME"

