#!/bin/bash
set -euo pipefail

# apt-get install mdadm cryptsetup lvm2
# mdadm --assemble --scan
#
# @felix: See git blame for multiple devices.

md=/dev/md2
crypt=crypt2024-02
raid_dev=/dev/raid2024-02/storage
TARGET=/media/storage

cryptsetup luksOpen $md $crypt

# wait until block device is available
# to trigger this manually, run `vgchange -a y raid` (activate vg)
while [[ ! -b $raid_dev ]]; do
  echo -n '.'
  sleep 0.25
done
echo
mkdir -p $TARGET
sudo mount $raid_dev $TARGET
ls $TARGET
