There are quite a few different ways you could approach this with systemd.
One is you could create a new independent service unit that had a Before=mediacenter.service declaration in it, that would cause the mediacenter service (/usr/bin/mediacenter which launches kodi) to be delayed until your service finished and exited.
A much simpler approach would be to add an ExecStartPre= line in the service unit for mediacenter at /lib/systemd/system/mediacenter.service:
This is not recommended because when we update the Kodi package your changes would be overwritten. However systemd has a neat feature called “drop-ins” which let you override or add additional lines to systemd units in a separate file that won’t be overridden:
This line effectively gets merged with whatever we have in /lib/systemd/system/mediacenter.service and your changes won’t be lost during upgrades.
With an ExecStartPre line you must specify the full path to the executable/script and it doesn’t execute within a shell - eg the script itself must have #!/bin/bash or similar at the start or you would need to call it via a shell.
Keep in mind your script must return a success (0) return code otherwise the service unit will be aborted as failed and Kodi won’t load.
The return code of a bash script is the return code of the last command run in the script, or if you use exit you can put the return code after exit, such as exit 0 to explicitly set the return code.
I mention it because in many cases the return code of a script will be ignored but any script run by systemd when starting a service has to succeed (return code 0) for the service as a whole to succeed in starting up.
exit 0 at the end (assuming your script only ever exits at the end of the script) will always return a success code even if some commands in the script failed, yes.
That might or might not be what you want depending on circumstances.