I am trying to decrypt a LUKS partition when I plug in an external HDD. Thus, I have configured the udev rules with the following:
ACTION=="add", KERNEL=="sdb1", SUBSYSTEM=="block", ATTR{size}=="1048576000", RUN+="/home/user/myfile.sh
myfile.sh script:
password=`su - user -c 'export DISPLAY=:0;kdialog --password "Decrypt HDD"'`
sleep 5
echo "$password" | cryptsetup luksOpen /dev/sdb1 backups
mount /dev/mapper/backups /media/backups/
The script read the password through kdialog, after decrypt the partition and mount it. If I run manually it works. The problem is that when I plug in the USB, the kdialog is launched but the /dev/sdb1 encrypted partition is not detected until the script has finished. Therefore the cryptsetup luksOpen and mount do not anything (because are launched before the encrypted partition is detected)...
The file with the udev rules is 90-crypt.rules in /etc/udev/rules.d