I had a similar question a while back about making sure some scripts only run on production.
Yes, the gateway scripts I make have to meet some environment criteria as part of the first if condition to run. Basically the gist is you have a config.json file, or add environment variables, to both machines and read from that to see where you are running. Read through the thread to see how to do this.
I cannot help you with that second question unfortunately.