Cryptsetup script post Opkg install

Hello all- I recently installed cryptsetup through Opkg and I am now trying to automount my external drives.

The code below works when copy pasting it line by line via ssh and everything mounts but for some reason it does not work in autostart.sh. I have tried everything from creating the autostart.sh file directly in ssh and setting it executable to doing it on my personal computer via a microsd adapter. Here is my script:

#!/bin/bash
(
 sleep 30
 cryptsetup luksOpen -d /storage/.config/keyfile /dev/disk/by-uuid/5d52d255-beb0-4de9-8ab6-cf7f6ad56b9a external1
 cryptsetup luksOpen -d /storage/.config/keyfile /dev/disk/by-uuid/208fea3b-9d50-45aa-b370-kf46952384a6 external2
 cryptsetup luksOpen -d /storage/.config/keyfile /dev/disk/by-uuid/85be45b1-9329-4f0c-9ebd-93905f665ac4 external3
 cryptsetup luksOpen -d /storage/.config/keyfile /dev/disk/by-uuid/2357606b-644b-44a4-abc9-23451f8bd355 external4
 cryptsetup luksOpen -d /storage/.config/keyfile /dev/disk/by-uuid/0892be8e-a55a-4790-ad22-4587f7aea6aa external5
 cryptsetup luksOpen -d /storage/.config/keyfile /dev/disk/by-uuid/844e81c9-8e3c-4401-b690-22c07f7db83d external6
 cryptsetup luksOpen -d /storage/.config/keyfile /dev/disk/by-uuid/97ca5d87-49c9-4c9c-acbb-87193df26fe4 external7
 mount -t ext4 /dev/mapper/external1 /storage/NFS/Disk1
 mount -t ext4 /dev/mapper/external2 /storage/NFS/Disk2
 mount -t ext4 /dev/mapper/external3 /storage/NFS/Disk3
 mount -t ext4 /dev/mapper/external4 /storage/NFS/Disk4
 mount -t ext4 /dev/mapper/external5 /storage/NFS/Disk5
 mount -t ext4 /dev/mapper/external6 /storage/NFS/Disk6
 mount -t ext4 /dev/mapper/external7 /storage/NFS/Disk7
) &

I guess the next thing I am going to try is renaming autostart.sh to mountz.sh and attempting to call it via systemd. Any help would be appreciated!

Try with full path for cryptsetup program like

/opt/bin/cryptsetup

Thank you for the reply. How would I modify my script above?

Just replace cryptsetup with /opt/bin/cryptsetup.
But first check if /opt/bin/cryptsetup really exist there. If not adjust path.

Is there an easy way to check where it is installed? The above did not work and I checked /opt/bin and I did not see it there. Also checked /usr/sbin and a couple of other spots.

EDIT: Just ran type -a cryptsetup and it looks like it is in /opt/sbin/cryptsetup

EDIT 2: using /opt/sbin/cryptsetup did not work either

EDIT 3: It looks like I am getting a syntax error on my autostart.sh script as it says unexpected newline

Use UNIX formatted autostart.sh

dos2unix /storage/.config/autostart.sh

Seems this is your problem #1.

To see what is wrong with this script run

journalctl -u kodi-autostart -l --no-pager

Well after all of that- It looks like it was a faulty USB hub. I installed lsblk via opkg and noticed that only a couple of my drives were registered. I swapped out the hub and they are all there now.

In addition, autostart.sh had been incorrectly typed in leading to the formatting error but if using the code above, it worked. Thanks for the help @vpeter!

1 Like

To clarify- after I rebooted it did not work again so I actually had to add /opt/sbin/cryptsetup to the startup script and remove cryptsetup for it to actually work.