refactor the code of build.sh for perl and python cartridges