#!/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` # need to loop through the find results, find the TPM info, and then look for the recovery password id # need to use csplit on the metadata # csplit -f ${bitlockerPartition} -n 1 Desktop/dislocker-metadata.txt "/=======\[ Datum ... informations \]=======/" '{*}' bitlockerRecoveryKeyID=`dislocker-metadata -V ${bitlockerPartition} | awk '/Recovery Key GUID:/ {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