I’ve been googling this on and off for a while. I’m certain it is possible, but I keep disappearing down rabbit holes of overly complex solutions, or those using long defunct add-ons.
I simply want to add menu entries to run arbitrary bash scripts, to save needing to ssh in to mount and dismount veracrypted volumes on external drives. Nothing fancy required, although display of a simple message dialog would be useful.
I can’t think of a simple way to do that other than writing a custom add-on.
Is there a reason why something like systemd automounts, or autofs couldn’t be setup to mount these drives when connected automatically? Just like a regular drive.
No reason other than lack of knowledge on my part…
My scripts aready uniquely identify the drive which is connected, so I’ll investigate the options you’ve suggested.
As long as you’re using systemd-based fstab mounts, I’d have thought a systemd service “unit” would do the trick (though you’ll probably need one unit file per disk).
In the /etc/fstab you’d need to associate the disk’s UUID with its mount point. See here.
Then for each mount point, create a .service file in /etc/systemd/system. I think the name can be arbitrary but it’s better to associate it with the mount point name, so I’ve called this one mnt-test.service since it’s for a mount point of /mnt/test.
osmc@osmc:~$ cat /etc/systemd/system/mnt-test.service
[Unit]
Description=Run script when /mnt/test is mounted
Requires=mnt-test.mount
After=mnt-test.mount
[Service]
ExecStart=/home/osmc/logit.sh
Type=forking
[Install]
WantedBy=mnt-test.mount
My script logit.sh just writes a message to the system journal, BTW.
Remember to enable it (sudo systemctl enable mnt-test.sh).
I can’t guarantee that it’ll work first time but it should be a step in the right direction. One caveat: if you’re using autofs, then this isn’t going to work.
Ive done something similar, using the osmc skin you can just add an entry to the sub menu of one of the main menu items…eg, Settings.
From there you can select ‘Change action’, then ‘Custom item’, then enter:
XBMC.RunScript(/home/osmc/path/to/script.py)
One caveat is I think its a Kodi limitation that only python scripts can be run like this, but you can simply call your bash script from the python script via:
import os
os.system('path/to/bash.sh')
or something similar…adding a Kodi notification via the script is pretty straightforward as well.
@retroresolution for your use, are your disks completely veracrypt’ed, or are they files on a normally formatted disk? From your example script, I’m guessing that the partition is encrypted?
Ideally I’d like to run them via a menu, but otherwise they’d need to run on connection of a usb device (with a switch statement to select the correct decryption key for the appropriate device), and on shutdown.
You could use a udev rule to do it on connection of a USB device.
Otherwise it’s not unfeasible to do it via a Kodi menu option. But putting it on the main menu will be skin dependent.
The entire partition is encrypted. On a couple of disks there are two partitions, encrypted with unique keys. Some have an additional small unencrypted fat32 40MB spacer partition.