Include bash scripts to be consumed by plugin

I'm building a plugin that enables a user to pair bluetooth devices in the Octoprint UI. The operations uses bluetoothctl among others.

I would like my plugin to execute scripts to configure bluetooth devices (scanning, pairing, connecting). This will include passing data from these commands/scripts into octoprint. Could any one point me in the right direction before I spend to much of my time on this?

Another thing is that I would like to add groups to the pi user. In this case it's the bluetooth group to enable communication from bluetooth devices.

You can run system commands from Python using the subprocess module, if you'd rather less DIY there's some utilities built on this in octoprint.util.commandline. Not sure how well documented they are, if you can see them on docs.octoprint.org, or if you'll have to use the source code.

To add a group to a user you need to use sudo, which means you need to prompt the user to get the system password (don't store it). I do this in the WS281x LED Status plugin with a setup wizard, to add the user to the gpio group.

In general to run system commands you can do it in Python using the libraries. In OctoPrint plugins should always require explicit user action to run a system command, so that you don't modify the system without their consent.

Apologies for not providing links to the above, I'm travelling with just my phone. If you need clarification please ask.

Here's where Charlie is mentioning it happening in his plugin.

and here is an example of where it's being called I think.

Thank you for your quick response. This will give me a great start.