Automatically install packages used in script

I had comparable requirements to yours. See below links.