Can't really help with the OSD method as we don't deploy via OSD anymore (too much work to create an account, then disabled the secure boot settings and finally boot from usb), but here's what was working on High Sierra, Mojave, and Catalina from within the OS.
#!/bin/bash
###functions
function...