This PR contains the changes from #3039 and #3040 which should be merged first. The purpose is to add the main command line script from #2976.