dotfiles/.bin/mount-cryptoffs
2025-01-05 09:22:42 +01:00

33 lines
744 B
Bash
Executable File

#!/bin/sh
_dev=${1:-sd2}
if mount | grep -q "/mnt"
then
echo "already mounted"
mount | grep "/mnt"
exit 1
fi
# check if already decrypted
_biodev=$(doas bioctl softraid0 | grep -B1 $_dev | head -1 | awk '{print $5}' \
|| exit 1)
# if not
if [ -z "$_biodev" ]
then
# decrypt
pass Local/hagibis-usb-nvme | doas bioctl -s -c C -l ${_dev}a softraid0
# and read again
_biodev=$(doas bioctl softraid0 | grep -B1 $_dev | head -1 | awk '{print $5}' \
|| exit 1)
fi
# it still might not be there (wrong password etc..)
if [ -n "$_biodev" ]
then
echo "${_dev}a attached as $_biodev"
# mount biodev
doas mount /dev/${_biodev}a /mnt \
&& echo "${_biodev}a mounted to /mnt"
fi