I am writing a script that unlocks a LUKS encryped partition (or file) using the command:
cryptsetup luksOpen /path/to/file mappername
Here, mappername
is a name I have to provide for a file that will be placed at /dev/mapper/
and which then will be mounted to access the encrypted data.
But, in a script, how can I be sure that the name is available? It also seems that it is not possible (please correct me if I am wrong here!) to provide a custom path to place the mapper somewhere else, where I know the names of other files. If the name is already in use, the above command will fail.
This situation is also similar to the creation of a temporary file, where race conditions may occur between checking whether the file exists and the actual creation. Thus, what is the proper way to achieve this?