Files
CodeSnoeperd/bash/copy_keyfile
2025-03-10 19:28:44 +10:30

27 lines
691 B
Bash

#!/bin/bash
#/usr/local/bin/copy_keyfile
# Copy over the encryption key and mount the external drive
# Try to copy over the encryption key. Give up after three minutes.
for attempt in $(seq 1 6); do
# Attempt to copy the file
if scp unraid@192.168.10.204:keyfile /dev/shm/keyfile; then
# Exit the loop on success
break
else
# Wait before retrying
sleep 30
fi
done
# Check if the loop completed successfully
if [ $? -ne 0 ]; then
echo "Failed to copy the encryption key after multiple attempts." >&2
exit 1 # Exit with failure code 1
fi
# Mount the drive
cryptsetup --key-file /dev/shm/keyfile luksOpen /dev/sdb1 corin
mount /dev/mapper/corin /media/corin