review jenkins scripts

Change-Id: I420910bd2d30e96605ecf3acb779ce726c75d912
diff --git a/contrib/jenkins-osmo-bts-octphy.sh b/contrib/jenkins-osmo-bts-octphy.sh
index 0a5a88c..4284262 100755
--- a/contrib/jenkins-osmo-bts-octphy.sh
+++ b/contrib/jenkins-osmo-bts-octphy.sh
@@ -1,94 +1,65 @@
 #!/bin/sh
+set -x -e
 
-set -e
+base="$PWD"
+prefix="$base/inst-osmo-bts-octphy"
 
-OPTION_DO_CLONE=0
-OPTION_DO_CLEAN=0
-OPTION_DO_TEST=1
+rm -f "$base/osmo-bts-octphy*.tgz"
 
-PREFIX=`pwd`/inst-osmo-bts-octphy
-
-# NOTE Make sure either 'octphy-2g-headers' (prefered) or
-# 'octsdr-2g' is listed among the repositories
-
-octbts_repos="libosmocore
+deps="
+libosmocore
 libosmo-abis
-openbsc/openbsc
-octphy-2g-headers
-osmo-bts"
+osmo-bts
+"
 
-clone_repos() {
-	repos="$1"
-	for repo in $repos; do
-		if [ -e $repo ]; then
-			continue
-		fi
-		if [ "$repo" = "libosmocore" ]; then
-			url="git://git.osmocom.org/libosmocore.git"
-		elif [ "$repo" = "libosmo-abis" ]; then
-			url="git://git.osmocom.org/libosmo-abis.git"
-		elif [ "$repo" = "libosmo-netif" ]; then
-			url="git://git.osmocom.org/libosmo-netif.git"
-		elif [ "$repo" = "openbsc/openbsc" ]; then
-			url="git://git.osmocom.org/openbsc"
-		elif [ "$repo" = "octphy-2g-headers" ]; then
-			url="git://git.osmocom.org/octphy-2g-headers"
-		elif [ "$repo" = "octsdr-2g" ]; then
-			# NOTE acutally we only need the headers from the octphy-2g-headers
-			# repository but this (private) repository contains more recent versions
-			url="ssh://git@git.admin.sysmocom.de/octasic/octsdr-2g"
-		elif [ "$repo" = "osmo-bts" ]; then
-			url="git://git.osmocom.org/osmo-bts.git"
-		else
-			exit 2
-		fi
-		git clone $url
-	done
+have_repo() {
+	repo="$1"
+	cd "$base"
+	if [ ! -e "$repo" ]; then
+		set +x
+		echo "MISSING REPOSITORY: $repo"
+		echo "should be provided by the jenkins workspace"
+		exit 1
+	fi
+	cd "$repo"
+	git clean -dxf
+	cd "$base"
 }
 
-main() {
-	repos="$1"
-	if [ $OPTION_DO_CLONE -eq 1 ]; then	clone_repos "$repos"; fi
-	rm -rf $PREFIX
-	mkdir -p $PREFIX
-	for repo in $repos; do
-		if [ "$repo" = "openbsc/openbsc" ]; then
-			continue
-		fi
-		if [ "$repo" = "octphy-2g-headers" ]; then
-			OCTPHY_INCDIR=`pwd`/octphy-2g-headers
-			continue
-		fi
-		if [ "$repo" = "octsdr-2g" ]; then
-			cd $repo
-			git checkout 5c7166bab0a0f2d8a9664213d18642ae305e7004
-			cd -
-			OCTPHY_INCDIR=`pwd`/octsdr-2g/software/include
-			continue
-		fi
-		cd $repo
-		if [ $OPTION_DO_CLEAN  -eq 1 ]; then	git clean -dxf; fi
-		echo "$(git rev-parse HEAD) $repo" >> "$PREFIX/osmo-bts-octphy_git_hashes.txt"
-		autoreconf -fi
-		if [ "$repo" != "libosmocore" ]; then
-			export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig
-			export LD_LIBRARY_PATH=$PREFIX/lib:/usr/local/lib
-		fi
-		config_opts=""
-		case "$repo" in
-		'osmo-bts')	config_opts="$config_opts --enable-octphy --with-octsdr-2g=$OCTPHY_INCDIR"
-		esac
-		./configure --prefix=$PREFIX $config_opts
-		make -j8
-		if [ $OPTION_DO_TEST -eq 1 ]; then	make check; fi
-		make install
-		cd ..
-	done
-}
+# for gsm_data_shared.*
+have_repo openbsc
 
-set -x
-main "$octbts_repos"
+# octphy headers
+have_repo octphy-2g-headers
 
-# build the archive that is going to be copied to the tester and then to the BTS
-rm -f $WORKSPACE/osmo-bts-octphy*.tgz
-tar czf $WORKSPACE/osmo-bts-octphy.build-$BUILD_NUMBER.tgz inst-osmo-bts-octphy
+
+rm -rf "$prefix"
+mkdir -p "$prefix"
+
+export PKG_CONFIG_PATH="$prefix/lib/pkgconfig"
+export LD_LIBRARY_PATH="$prefix/lib"
+
+for dep in $deps; do
+	have_repo "$dep"
+	cd "$dep"
+	rm -rf *
+	git checkout .
+
+	echo "$(git rev-parse HEAD) $dep" >> "$prefix/osmo-bts-octphy_git_hashes.txt"
+
+	autoreconf -fi
+
+	config_opts=""
+
+	case "$repo" in
+	'osmo-bts')	config_opts="$config_opts --enable-octphy --with-octsdr-2g=$base/octphy-2g-headers" ;;
+	esac
+
+	./configure --prefix="$prefix" $config_opts
+	make -j8
+	make install
+done
+
+# build the archive that is going to be copied to the tester
+cd "$prefix"
+tar czf "$base/osmo-bts-octphy.build-${BUILD_NUMBER}.tgz" *