jenkins: extract common parts of build scripts to separate file

Have all complexity in one common shell script, greatly simplify the individual
scripts.

This allows to provide a specific branch or git hash to build instead of
current master. Some scripts allowed to provide branch names before, this now
also allows using git hashes directly.

Environment variables can be used to override the git hash/branch to use for
specific repositories.

Motivation for this patch: we need this to investigate failure causes more
easily.

Change-Id: I5ac2f90d006a1b2f6c246976346d852a70c89089
diff --git a/contrib/jenkins-build-osmo-msc.sh b/contrib/jenkins-build-osmo-msc.sh
index f7808ff..53a23fe 100755
--- a/contrib/jenkins-build-osmo-msc.sh
+++ b/contrib/jenkins-build-osmo-msc.sh
@@ -1,62 +1,8 @@
 #!/bin/sh
 set -e -x
-
 base="$PWD"
-prefix="$base/inst-osmo-msc"
-
-rm -f "$base/osmo-msc*.tgz"
-
-git_url="git://git.osmocom.org"
-
-have_repo() {
-	repo="$1"
-	branch="${2-master}"
-
-	cd "$base"
-	if [ ! -d "$repo" ]; then
-		git clone "$git_url/$repo" -b "$branch" "$repo"
-	fi
-	cd "$repo"
-	rm -rf *
-	git fetch origin
-	git checkout .
-	git checkout "$branch"
-	git reset --hard origin/"$branch"
-	git rev-parse HEAD
-
-	cd "$base"
-}
-
-build_repo() {
-	dep="$1"
-	branch="${2-master}"
-
-	have_repo "$dep" "$branch"
-
-	cd "$dep"
-
-	echo "$(git rev-parse HEAD) $dep" >> "$prefix/osmo-msc_git_hashes.txt"
-
-	config_opts=""
-
-	case "$dep" in
-	'openbsc')
-		config_opts="$config_opts --enable-smpp --enable-osmo-bsc --enable-nat --enable-iu"
-		cd openbsc/
-	;;
-	esac
-
-	autoreconf -fi
-	./configure --prefix="$prefix" $config_opts
-	make -j8 || make  # libsmpp34 can't build in parallel
-	make install
-}
-
-rm -rf "$prefix"
-mkdir -p "$prefix"
-
-export PKG_CONFIG_PATH="$prefix/lib/pkgconfig"
-export LD_LIBRARY_PATH="$prefix/lib"
+name="osmo-msc"
+. "$(dirname "$0")/jenkins-build-common.sh"
 
 build_repo libosmocore
 build_repo libosmo-abis
@@ -66,17 +12,6 @@
 build_repo libosmo-sccp neels/aoip # TEMPORARY BRANCH
 build_repo libasn1c
 build_repo osmo-iuh neels/sigtran # TEMPORARY BRANCH
-build_repo openbsc aoip
+build_repo openbsc aoip --enable-smpp --enable-osmo-bsc --enable-nat --enable-iu
 
-# don't package documentation -- the libosmocore docs can be up to 16 Mb large,
-# a significant amount compared to the binaries
-rm -rf "$prefix/share/doc"
-
-# build the archive that is going to be copied to the tester
-rm "$base"/*.tgz "$base"/*.md5 || true
-cd "$prefix"
-this="osmo-msc.build-${BUILD_NUMBER-$(date +%Y-%m-%d_%H_%M_%S)}"
-tar="${this}.tgz"
-tar czf "$base/$tar" *
-cd "$base"
-md5sum "$tar" > "${this}.md5"
+create_bin_tgz