refactor: DRY the sh scripts with functions