I just created an installer script for the same code you posted that will set things up for Budgie, Gnome and MATE.
https://github.com/kz6fittycent/nvidia-optimus-manager
It's just my fork of the original code. PR submitted, just not accepted yet.
I use this on my own laptop with Nvidia GPU.