Files
homelab-scripts/dislocker.sh

34 lines
1.3 KiB
Bash

#!/bin/bash
# Variables
bitlockerPartitionMountPoint="/mnt/bitlocker"
dislockerFileMountPoint="/mnt/bitlocker/dislocker-file"
unlockedBitlockerMountPoint="/mnt/unlockedBitlocker"
# get list of drives and find ones labeled with bitlocker
bitlockerPartition=`dislocker-find`
bitlockerRecoveryKeyID=`dislocker-metadata -V ${bitlockerPartition} | awk '/Recovery Key GUI:/ {print $10; exit}' | sed "s/'//g"`
# confirm drive
# make temp directories
mkdir ${bitlockerPartitionMountPoint}
mkdir ${unlockedBitlockerMountPoint}
# ask for the recovery key with dashses
# regex to match bitlocker key "^[0-9]{6}-[0-9]{6}-[0-9]{6}-[0-9]{6}-[0-9]{6}-[0-9]{6}-[0-9]{6}-[0-9]{6}$"
regex="^[0-9]{6}-[0-9]{6}-[0-9]{6}-[0-9]{6}-[0-9]{6}-[0-9]{6}-[0-9]{6}-[0-9]{6}$"
while : ; do
read -p "Enter recovery key with dashes for bitlocker recovery ID ${bitlockerRecoveryKeyID}: " bitlockerRecoveryKey
[[ ${bitlockerRecoveryKey} =~ ${regex} ]] || break
done
# try unlocking the drive
dislocker -v -V ${bitlockerPartition} -p${bitlockerRecoveryKey} -- ${bitlockerPartitionMountPoint}
# test if the dislockerFileMountPoint was created
if [ -f ${dislockerFileMountPoint} ]; then
# mount the file
mount -o loop,ro ${dislockerFileMountPoint} ${unlockedBitlockerMountPoint}
echo "The drive was unlocked and is availabe at ${unlockedBitlockerMountPoint}"
fi