These are interesting questions... it seems your are trying to achieve multi-tenance with one Gluu instance.
This is a feature that a lot of customers have been asking for over the years. We have a back-of-the-envelope design to support it (see attached png).
I think the script approach would be kind of hacky at scale. It would be worthwhile to have a conversation about this.