Big thanks to @fiwswe!
Even though he probably would have been faster by writing that script himself, he took the time to open up issues and explain stuff to a noob like me
The script is no longer bash but now shell and has little to do with the original.
It should work on OPNsense, macOS and Linux.