scripts: Extract reusable functions to a common module
A new script to mirror upstream repository will use this as well.
Related to T2225