Updates

  * Deduplicate salt_bootstrap.sh
  * Deduplicate bootstrap.saltstack.com.sh
  * Push day01 to use offline salt_bootstrap.sh
  * Misc udpates

Change-Id: I89fa2efa73b81a7663581a132207b9a8117e4ae7
diff --git a/common/ubuntu_salt_bootstrap.sh b/common/ubuntu_salt_bootstrap.sh
new file mode 100644
index 0000000..ad3757e
--- /dev/null
+++ b/common/ubuntu_salt_bootstrap.sh
@@ -0,0 +1,58 @@
+#!/bin/bash -xe
+
+CLUSTER_NAME=${CLUSTER_NAME:-lost_cluster_name_variable}
+CLUSTER_MODEL=${CLUSTER_MODEL:-https://github.com/Mirantis/mcp-offline-model.git}
+CLUSTER_MODEL_REF=${CLUSTER_MODEL_REF:-master}
+FORMULA_VERSION=${FORMULA_VERSION:-testing}
+SALTSTACK_GPG=${SALTSTACK_GPG:-"https://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3/SALTSTACK-GPG-KEY.pub"}
+SALTSTACK_REPO=${SALTSTACK_REPO:-"http://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3 xenial main"}
+APT_MIRANTIS_GPG=${APT_MIRANTIS_GPG:-"http://apt.mirantis.com/public.gpg"}
+APT_MIRANTIS_SALT_REPO=${APT_MIRANTIS_SALT_REPO:-"http://apt.mirantis.com/xenial/ $FORMULA_VERSION salt"}
+GIT_SALT_FORMULAS_SCRIPTS=${GIT_SALT_FORMULAS_SCRIPTS:-"https://github.com/salt-formulas/salt-formulas-scripts"}
+GIT_SALT_FORMULAS_SCRIPTS_REF=${GIT_SALT_FORMULAS_SCRIPTS_REF:-master}
+
+wget -O - ${SALTSTACK_GPG} | sudo apt-key add -
+wget -O - ${APT_MIRANTIS_GPG} | apt-key add -
+echo "deb [arch=amd64] ${SALTSTACK_REPO}"  > /etc/apt/sources.list.d/saltstack.list
+apt-get update
+apt-get install git-core -y
+
+for g_host in ${CLUSTER_MODEL} ${GIT_SALT_FORMULAS_SCRIPTS} ; do
+  _tmp_host=$(echo ${g_host} | awk -F/ '{print $3}')
+  ssh-keyscan -T 1 -H ${_tmp_host} >> ~/.ssh/known_hosts || true
+done
+
+if [[ ! -d /srv/salt/reclass ]]; then
+  git clone --recursive ${CLUSTER_MODEL} /srv/salt/reclass
+  pushd /srv/salt/reclass/
+    git checkout ${CLUSTER_MODEL_REF}
+  popd
+fi
+
+if [[ ! -d /srv/salt/scripts ]]; then
+  git clone --recursive ${GIT_SALT_FORMULAS_SCRIPTS} /srv/salt/scripts
+  pushd /srv/salt/scripts/
+    git checkout ${GIT_SALT_FORMULAS_SCRIPTS_REF}
+  popd
+fi
+
+# bootstrap.sh opts
+export FORMULAS_SOURCE=pkg
+export HOSTNAME=${BS_HOSTNAME:-lost_bs_hostname_variable}
+export DOMAIN="${CLUSTER_NAME}.local"
+export EXTRA_FORMULAS=${EXTRA_FORMULAS:-"ntp aptly nginx iptables docker git maas jenkins"}
+export APT_REPOSITORY=" deb [arch=amd64] ${APT_MIRANTIS_SALT_REPO} "
+export APT_REPOSITORY_GPG=${APT_MIRANTIS_GPG}
+if [[ ! -z "${PACKER_OFFLINE_BUILD}" ]];then
+  echo "INFO: build in offline detected!"
+  export BOOTSTRAP_SALTSTACK_COM="file:///tmp/bootstrap.saltstack.com.sh"
+  # extra opts will push bootstrap script NOT install upstream repos.
+  export BOOTSTRAP_SALTSTACK_OPTS=${BOOTSTRAP_SALTSTACK_OPTS:- -dXr $BOOTSTRAP_SALTSTACK_VERSION }
+fi
+#
+
+if [[ ! -f /srv/salt/scripts/bootstrap.sh ]]; then
+  echo "ERROR: File /srv/salt/scripts/bootstrap.sh not found"
+  exit 1
+fi
+bash -x /srv/salt/scripts/bootstrap.sh || true