allow packages to be provided locally or fetched from alternate branches

refs #1895

Change-Id: Idae33f3af5091413c915c5081d505bacea957c5d
diff --git a/install_helpers/common.sh b/install_helpers/common.sh
new file mode 100644
index 0000000..5a78668
--- /dev/null
+++ b/install_helpers/common.sh
@@ -0,0 +1,50 @@
+#!/bin/bash
+
+if [[ -f repos.conf ]]; then
+  source repos.conf
+fi
+
+# Check out the repository of the specified package from Gerrit or a local repository.
+#
+# Parameters:
+#   name of package used in repository names (e.g., ndn-cxx or NFD)
+#   name of package used in variable names (e.g., NDNCXX or NFD)
+#
+# This function changes the working directory to the directory containing the package source.
+prepare_repo() {
+  local PACKAGE_NAME=$1
+  local PACKAGE_VAR=PACKAGE_$2
+  local PACKAGE_SOURCE=${!PACKAGE_VAR}
+  if [[ -z $PACKAGE_SOURCE ]]; then
+    PACKAGE_SOURCE=branch:master
+  fi
+
+  local SOURCE=${PACKAGE_SOURCE%%:*}
+  local LOCATION=${PACKAGE_SOURCE#*:}
+  if [[ $SOURCE == branch || $SOURCE == gerrit ]]; then
+    if [[ $SOURCE == branch ]]; then
+      local GERRIT_BRANCH=$LOCATION
+    else
+      local GERRIT_CHANGE=${LOCATION%%,*}
+      local GERRIT_PATCHSET=${LOCATION#*,}
+      local GERRIT_BRANCH="refs/changes/$(printf '%02d' $(($GERRIT_CHANGE % 100)))/$GERRIT_CHANGE/$GERRIT_PATCHSET"
+    fi
+
+    echo "Checking out from Gerrit: $GERRIT_BRANCH"
+    cd prepare
+    git init $PACKAGE_NAME
+    cd $PACKAGE_NAME
+    git pull --depth 1 https://gerrit.named-data.net/$PACKAGE_NAME $GERRIT_BRANCH
+  elif [[ $SOURCE == local ]]; then
+    echo "Using local copy of $PACKAGE_NAME"
+    if [[ ! -d packages/$PACKAGE_NAME ]]; then
+      echo "ERROR: No local copy of package $PACKAGE_NAME could be found in prepare"
+      exit 1
+    fi
+    cp -r packages/$PACKAGE_NAME prepare
+    cd prepare/$PACKAGE_NAME
+  else
+    echo "SYNTAX ERROR: Package $PACKAGE_NAME has incorrectly formatted source: $PACKAGE_SOURCE"
+    exit 2
+  fi
+}
diff --git a/install_helpers/install_NFD.py b/install_helpers/install_NFD.py
deleted file mode 100644
index ff4db7b..0000000
--- a/install_helpers/install_NFD.py
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/usr/bin/python2
-import os
-
-# Install NFD
-def run():
-    print "\nINSTALLING NFD"
-    print "**************"
-    os.system("git clone --depth 1 https://github.com/named-data/NFD")
-    os.chdir("NFD")
-    os.system("git submodule init && git submodule update")
-    os.system("./waf configure --with-other-tests")
-    os.system("./waf")
-    os.system("sudo ./waf install")
-    os.system("sudo cp /usr/local/etc/ndn/nfd.conf.sample /usr/local/etc/ndn/nfd.conf")
-    os.system("sudo mkdir /usr/local/etc/ndn/keys/")
-    os.system("ndnsec-cert-dump -i `ndnsec-get-default` > ~/default.ndncert")
-    os.system("sudo mv ~/default.ndncert /usr/local/etc/ndn/keys")
-    os.chdir("..")
diff --git a/install_helpers/install_NFD.sh b/install_helpers/install_NFD.sh
new file mode 100755
index 0000000..d6bfc62
--- /dev/null
+++ b/install_helpers/install_NFD.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+source install_helpers/common.sh
+
+echo
+echo "INSTALLING NFD"
+echo "**************"
+
+prepare_repo NFD NFD
+git submodule update --init --depth 1
+./waf configure --with-other-tests
+./waf
+sudo ./waf install
+sudo cp /usr/local/etc/ndn/nfd.conf.sample /usr/local/etc/ndn/nfd.conf
+sudo mkdir -p /usr/local/etc/ndn/keys
+ndnsec-cert-dump -i "$(ndnsec-get-default)" | sudo tee /usr/local/etc/ndn/keys/default.ndncert > /dev/null
diff --git a/install_helpers/install_dependencies.py b/install_helpers/install_dependencies.py
deleted file mode 100644
index 6c5d1f3..0000000
--- a/install_helpers/install_dependencies.py
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/usr/bin/python2
-import os
-
-# Install Dependencies & Necessary Tools
-def run():
-    print "\nINSTALLING DEPENDENCIES"
-    print "***********************"
-    os.system("sudo apt-get -qq update")
-    os.system("sudo apt-get -qq install build-essential git libboost-all-dev libcrypto++-dev libpcap-dev pkg-config libsqlite3-dev socat bind9 libssl-dev")
diff --git a/install_helpers/install_dependencies.sh b/install_helpers/install_dependencies.sh
new file mode 100755
index 0000000..e9b6e7d
--- /dev/null
+++ b/install_helpers/install_dependencies.sh
@@ -0,0 +1,9 @@
+#!/bin/bash
+# Install dependencies and necessary tools
+
+echo
+echo "INSTALLING DEPENDENCIES"
+echo "***********************"
+
+sudo apt-get -qq update
+sudo apt-get -qq install build-essential git libboost-all-dev libpcap-dev pkg-config libsqlite3-dev socat bind9 libssl-dev
diff --git a/install_helpers/install_infoedit.py b/install_helpers/install_infoedit.py
deleted file mode 100644
index ba8624b..0000000
--- a/install_helpers/install_infoedit.py
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/usr/bin/python2
-import os
-
-# Install infoedit
-def run():
-    print "\nINSTALLING infoedit"
-    print "**************"
-    os.system("git clone --depth 1 https://github.com/NDN-Routing/infoedit.git")
-    os.chdir("infoedit")
-    os.system("make")
-    os.system("sudo make install")
-    os.chdir("..")
diff --git a/install_helpers/install_infoedit.sh b/install_helpers/install_infoedit.sh
new file mode 100755
index 0000000..bad7360
--- /dev/null
+++ b/install_helpers/install_infoedit.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+echo
+echo "INSTALLING infoedit"
+echo "*******************"
+
+cd prepare
+git clone --depth 1 https://github.com/NDN-Routing/infoedit.git
+cd infoedit
+make
+sudo make install
diff --git a/install_helpers/install_ndncxx.py b/install_helpers/install_ndncxx.py
deleted file mode 100644
index 74495f5..0000000
--- a/install_helpers/install_ndncxx.py
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/usr/bin/python2
-import os
-
-# Install ndn-cxx
-def run():
-    print "\nINSTALLING ndn-cxx"
-    print "**********************"
-    os.system("git clone --depth 1 https://github.com/named-data/ndn-cxx")
-    os.chdir("ndn-cxx")
-    os.system("./waf configure")
-    os.system("./waf")
-    os.system("sudo ./waf install")
-    os.system("mkdir -p ~/.ndn")
-    os.system("sudo ldconfig")
-    os.chdir("..")
diff --git a/install_helpers/install_ndncxx.sh b/install_helpers/install_ndncxx.sh
new file mode 100755
index 0000000..0cfd091
--- /dev/null
+++ b/install_helpers/install_ndncxx.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+source install_helpers/common.sh
+
+echo
+echo "INSTALLING ndn-cxx"
+echo "******************"
+
+prepare_repo ndn-cxx NDNCXX
+./waf configure
+./waf
+sudo ./waf install
+sudo ldconfig
+mkdir -p ~/.ndn
diff --git a/install_helpers/install_ndntools.py b/install_helpers/install_ndntools.py
deleted file mode 100644
index d4d0b92..0000000
--- a/install_helpers/install_ndntools.py
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/usr/bin/python2
-import os
-
-# Install ndn-tools
-def run():
-    print "\nINSTALLING ndn-tools"
-    print "***********************"
-    os.system("git clone --depth 1 https://github.com/named-data/ndn-tools")
-    os.chdir("ndn-tools")
-    os.system("./waf configure")
-    os.system("./waf")
-    os.system("sudo ./waf install")
-    os.chdir("..")
diff --git a/install_helpers/install_ndntools.sh b/install_helpers/install_ndntools.sh
new file mode 100755
index 0000000..62022d9
--- /dev/null
+++ b/install_helpers/install_ndntools.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+source install_helpers/common.sh
+
+echo
+echo "INSTALLING ndn-tools"
+echo "********************"
+
+prepare_repo ndn-tools NDNTOOLS
+./waf configure
+./waf
+sudo ./waf install
diff --git a/install_helpers/install_ndntraffic.py b/install_helpers/install_ndntraffic.py
deleted file mode 100644
index f8e85ab..0000000
--- a/install_helpers/install_ndntraffic.py
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/usr/bin/python2
-import os
-
-# Install ndn-traffic-generator
-def run():
-    print "\nINSTALLING ndn-traffic-generator"
-    print "********************************"
-    os.system("git clone --depth 1 https://github.com/named-data/ndn-traffic-generator")
-    os.chdir("ndn-traffic-generator")
-    os.system("./waf configure")
-    os.system("./waf")
-    os.system("sudo ./waf install")
-    os.chdir("..")
diff --git a/install_helpers/install_ndntraffic.sh b/install_helpers/install_ndntraffic.sh
new file mode 100755
index 0000000..75ab556
--- /dev/null
+++ b/install_helpers/install_ndntraffic.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+source install_helpers/common.sh
+
+echo
+echo "INSTALLING ndn-traffic-generator"
+echo "********************************"
+
+prepare_repo ndn-traffic-generator NDNTRAFFIC
+./waf configure
+./waf
+sudo ./waf install
diff --git a/install_helpers/install_repo.py b/install_helpers/install_repo.py
deleted file mode 100644
index 8748274..0000000
--- a/install_helpers/install_repo.py
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/usr/bin/python2
-import os
-
-# Install repo-ng
-def run():
-    print "\nINSTALLING repo-ng"
-    print "***********************"
-    os.system("git clone --depth 1 https://github.com/named-data/repo-ng")
-    os.chdir("repo-ng")
-    os.system("./waf configure")
-    os.system("./waf")
-    os.system("sudo ./waf install")
-    os.chdir("..")
diff --git a/install_helpers/install_repong.sh b/install_helpers/install_repong.sh
new file mode 100755
index 0000000..fa3ae99
--- /dev/null
+++ b/install_helpers/install_repong.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+source install_helpers/common.sh
+
+echo
+echo "INSTALLING repo-ng"
+echo "******************"
+
+prepare_repo repo-ng REPONG
+./waf configure
+./waf
+sudo ./waf install
diff --git a/install_helpers/setup_preparation_folder.py b/install_helpers/setup_preparation_folder.py
deleted file mode 100644
index 777fb73..0000000
--- a/install_helpers/setup_preparation_folder.py
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/usr/bin/python2
-import os
-from os.path import expanduser
-
-# Setup Preparation Folder
-def run():
-    print "\nSETTING UP PREPARATION FOLDER"
-    print "******************************"
-    home = expanduser("~")
-    os.chdir(home)
-    os.system("rm -rf nfd_prepare")
-    os.mkdir("nfd_prepare")
-    os.chdir("nfd_prepare")
-
diff --git a/install_helpers/setup_preparation_folder.sh b/install_helpers/setup_preparation_folder.sh
new file mode 100755
index 0000000..194622d
--- /dev/null
+++ b/install_helpers/setup_preparation_folder.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+echo
+echo "SETTING UP PREPARATION FOLDER"
+echo "*****************************"
+
+rm -rf prepare
+mkdir prepare
diff --git a/install_helpers/setup_security.py b/install_helpers/setup_security.py
deleted file mode 100644
index 4d550cd..0000000
--- a/install_helpers/setup_security.py
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/usr/bin/python2
-import os
-
-# Configure Security Environment Using ndnsec
-def run():
-    print "\nCONFIGURING SECURITY ENVIRONMENT WITH ndnsec"
-    print "********************************************"
-    os.system("ndnsec-keygen -n '/tmp/nfd_integration_tests/' | ndnsec-install-cert -")
diff --git a/install_helpers/setup_security.sh b/install_helpers/setup_security.sh
new file mode 100755
index 0000000..c3bfcf8
--- /dev/null
+++ b/install_helpers/setup_security.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+# Configure security environment using ndnsec
+
+echo
+echo "CONFIGURING SECURITY ENVIRONMENT WITH ndnsec"
+echo "********************************************"
+
+ndnsec-keygen -n /tmp/nfd_integration_tests/ | ndnsec-install-cert -