Remove old scripts, default formulas list from bootstrap.sh + doc update

Change-Id: Ie0910b1180823f8fe06e3c85c20035d79bb5336d
diff --git a/README.rst b/README.rst
index 153dd2f..7aca650 100644
--- a/README.rst
+++ b/README.rst
@@ -18,6 +18,7 @@
 * validate reclass the model / pillar for all nodes
 
 TL;DR:
+======
 
 Bootstrap salt-minion:
 
@@ -31,6 +32,43 @@
   install_salt_minion_pkg
 
 
+Common procedure
+================
+
+Download the deploy scripts to the ``/srv/salt/scripts`` directory:
+
+   .. code-block:: bash
+
+      git clone https://github.com/salt-formulas/salt-formulas-scripts /srv/salt/scripts
+
+Install reclass (optional):
+
+.. note:: For bootstrap you may wish to use the forked version with some nice features (as ignore_class_notfound) from
+          master or develop branch of https://github.com/salt-formulas/reclass.
+
+.. code-block:: bash
+
+  RECLASS_VERSION=dev
+  cd /srv/salt/scripts
+  source /srv/salt/scripts.bootstrap.sh
+  install_reclass
+
+.. note:: To ignore missing classes on bootstrap export the following variables
+          ``export RECLASS_IGNORE_CLASS_NOTFOUND=True; export RECLASS_IGNORE_CLASS_REGEXP="service.*"``
+
+If you are not using forked reclass (with ingnore_class_notfound option enabled) you have to set
+environment variable FORMULAS_SALT_MASTER containing list of all formulas required on salt master.
+For example you may require to pre-install the following:
+
+.. code-block:: bash
+
+  export FORMULAS_SALT_MASTER="linux salt reclass maas memcached openssh ntp  sphinx \
+    grafana libvirt rsyslog glusterfs postfix xtrabackup freeipa prometheus telegraf \
+    elasticsearch kibana rundeck devops-portal rsync docker keepalived aptly jenkins \
+    gerrit artifactory influxdb horizon nginx collectd heka mysql"
+
+
+Run the ``bootstrap.sh`` script from ``/srv/salt/scripts`` with the ``MASTER_HOSTNAME=$SALT_MASTER_FQDN`` parameter to
 Bootstrap salt-master:
 
 .. code-block:: bash
@@ -38,21 +76,8 @@
   cd /srv/salt/scripts
   CLUSTER_NAME=regionOne HOSTNAME=cfg01 DOMAIN=infra.ci.local ./bootstrap.sh
 
-.. note:
-  Creates /srv/salt/scripts/.salt-master-setup.sh.passed if succesfully passed the "setup script" 
-  with the aim to avoid subsequent setup.
-
-
-**salt-master-setup.sh** (DEPRECATED, use bootstrap.sh instead)
-
-Script to install and configure salt *minion* but mostly *salt master* with *salt-formulas* common prerequisites in mind.
-Configuration driven by environment variables, see source for more details...
-
-
-**salt-master-init.sh** (DEPRECATED, use bootstrap.sh instead)
-
-Script to bootstrap *salt master* and verify the model. To install salt master uses ``salt-master-setup.sh``.
-Configuration driven by environment variables.
+.. note:: Creates /srv/salt/scripts/.salt-master-setup.sh.passed if succesfully passed the "setup script"
+          with the aim to avoid subsequent setup.
 
 
 **formula-fetch.sh**
@@ -108,6 +133,7 @@
 
     # reclass
     export RECLASS_ADDRESS=<repo url>   ## if not already cloned in /srv/salt/reclass >
+    export RECLASS_VERSION=dev
 
     # formula
     export FORMULAS_BRANCH=master
@@ -132,7 +158,8 @@
     export CLUSTER_NAME=<%= cluster %>
     
     # workarounds
-    export RECLASS_IGNORE_CLASS_NOTFOUND=False
+    export RECLASS_IGNORE_CLASS_NOTFOUND=True
+    export RECLASS_IGNORE_CLASS_REGEXP="service.*"
     export EXTRA_FORMULAS="prometheus telegraph"
 
   
diff --git a/bootstrap.sh b/bootstrap.sh
index dc024c3..8f82cc8 100755
--- a/bootstrap.sh
+++ b/bootstrap.sh
@@ -61,7 +61,7 @@
 export FORMULAS_BRANCH=${FORMULAS_BRANCH:-master}
 export FORMULAS_SOURCE=${FORMULAS_SOURCE:-pkg} # pkg/git
 # essential set of formulas (known to by used on cfg01 node for most setups)
-FORMULAS_SALT_MASTER=${FORMULAS_SALT_MASTER:- $EXTRA_FORMULAS maas memcached openssh ntp nginx collectd sensu heka sphinx mysql grafana libvirt rsyslog glusterfs postfix xtrabackup freeipa prometheus telegraf elasticsearch kibana rundeck devops-portal rsync docker keepalived aptly jenkins gerrit artifactory influxdb horizon}
+FORMULAS_SALT_MASTER=${FORMULAS_SALT_MASTER:- $EXTRA_FORMULAS}
 # minimal set of formulas for salt-master bootstrap
 declare -a FORMULAS_SALT_MASTER=(linux reclass salt git $(echo $FORMULAS_SALT_MASTER))
 export FORMULAS_SALT_MASTER
diff --git a/salt-master-init.sh b/salt-master-init.sh
deleted file mode 100755
index 4d4ac1c..0000000
--- a/salt-master-init.sh
+++ /dev/null
@@ -1,290 +0,0 @@
-#!/usr/bin/env bash
-
-# generate and validate reclass-salt-model
-# expected to be executed in isolated environment, ie: docker
-
-if [[ $DEBUG =~ ^(True|true|1|yes)$ ]]; then
-    set -x
-    SALT_LOG_LEVEL="--state-verbose=true -ldebug"
-fi
-
-## Env Options
-options() {
-    export LC_ALL=C
-    SALT_LOG_LEVEL="${SALT_LOG_LEVEL:- --state-verbose=false -lerror}"
-    SALT_OPTS="${SALT_OPTS:- --timeout=120 --state-output=changes --retcode-passthrough --force-color $SALT_LOG_LEVEL }"
-    RECLASS_ROOT=${RECLASS_ROOT:-/srv/salt/reclass}
-    BOOTSTRAP_SALTSTACK=${BOOTSTRAP_SALTSTACK:-True}
-    BOOTSTRAP_SALTSTACK_OPTS=${BOOTSTRAP_SALTSTACK_OPTS:- -dX stable 2016.3 }
-    SALT_STATE_RETRY=${SALT_STATE_RETRY:-3}
-
-    # try to source local environment & configuration
-    # shopt -u dotglob
-    for path in / . /srv/salt /tmp/kitchen /srv/salt/reclass/classes/cluster /srv/salt/reclass/classes/cluster/${CLUSTER_NAME}; do
-      export $(find $path -maxdepth 1 -name '*.env' 2> /dev/null | xargs --no-run-if-empty cat ) > /dev/null
-    done;
-
-    export MAGENTA='\033[0;95m'
-    export YELLOW='\033[1;33m'
-    export BLUE='\033[0;35m'
-    export CYAN='\033[0;96m'
-    export RED='\033[0;31m'
-    export NC='\033[0m' # No Color'
-}
-
-## Functions
-log_info() {
-    echo -e "${YELLOW}[INFO] $* ${NC}"
-}
-
-log_warn() {
-    echo -e "${MAGENTA}[WARN] $* ${NC}"
-}
-
-log_err() {
-    echo -e "${RED}[ERROR] $* ${NC}" >&2
-}
-
-_atexit() {
-    RETVAL=$?
-    trap true INT TERM EXIT
-
-    if [ $RETVAL -ne 0 ]; then
-        log_err "Execution failed"
-    else
-        log_info "Execution successful"
-    fi
-    return $RETVAL
-}
-
-retry() {
-    local tries
-    if [[ $1 =~ ^[0-9]+$ ]]; then
-        tries=$1; shift
-    else
-        tries=3
-    fi
-    for i in $(seq 1 $tries); do
-        "$@" && return 0 || sleep $i
-    done
-    return 1
-}
-
-## Main
-
-system_config() {
-    log_info "System configuration"
-
-    # salt-formulas custom modules dependencies, etc:
-    $SUDO apt install -qqq -y iproute2 curl sudo apt-transport-https python-psutil python-apt python-m2crypto python-oauth python-pip &>/dev/null
-
-    $SUDO mkdir -p $RECLASS_ROOT/classes/service
-    $SUDO mkdir -p /root/.ssh
-    echo -e "Host *\n\tStrictHostKeyChecking no\n" | $SUDO tee ~/.ssh/config >/dev/null
-    echo -e "Host *\n\tStrictHostKeyChecking no\n" | $SUDO tee /root/.ssh/config >/dev/null
-    echo "127.0.1.2  salt" | $SUDO tee -a /etc/hosts >/dev/null
-
-    if [[ $BOOTSTRAP_SALTSTACK =~ ^(True|true|1|yes)$ ]]; then
-        curl -L https://bootstrap.saltstack.com | $SUDO sh -s -- -M ${BOOTSTRAP_SALTSTACK_OPTS} &>/dev/null || true
-    fi
-
-    which reclass || $SUDO apt install -qqq -y reclass
-
-    which reclass-salt || {
-      test -e /usr/share/reclass/reclass-salt && {
-        ln -fs /usr/share/reclass/reclass-salt /usr/bin
-      }
-    }
-}
-
-
-saltmaster_bootstrap() {
-
-    log_info "Salt master, minion setup (salt-master-setup.sh)"
-    test -n "$MASTER_HOSTNAME" || (echo "missing \$MASTER_HOSTNAME" && return)
-
-    pgrep salt-master | sed /$$/d | xargs --no-run-if-empty -i{} $SUDO kill -9 {}
-    pkill -9 salt-minion
-    SCRIPTS=$(dirname $0)
-    test -e ${SCRIPTS}/salt-master-setup.sh || \
-        curl -sL "https://raw.githubusercontent.com/salt-formulas/salt-formulas-scripts/master/salt-master-setup.sh" |$SUDO tee ${SCRIPTS}/salt-master-setup.sh > /dev/null;
-        $SUDO chmod +x *.sh;
-    test -e ${SCRIPTS}/.salt-master-setup.sh.passed || {
-        export SALT_MASTER=localhost
-        export MINION_ID=${MASTER_HOSTNAME}
-        if ! [[ $DEBUG =~ ^(True|true|1|yes)$ ]]; then
-          SALT_MASTER_SETUP_OUTPUT='/dev/stdout'
-        fi
-        #if ! $SUDO ${SCRIPTS}/salt-master-setup.sh master &> ${SALT_MASTER_SETUP_OUTPUT:-/tmp/salt-master-setup.log}; then
-        if ! $SUDO ${SCRIPTS}/salt-master-setup.sh master; then
-          #cat /tmp/salt-master-setup.log
-          log_err "salt-master-setup.sh failed."
-          exit 1
-        else
-          $SUDO touch ${SCRIPTS}/.salt-master-setup.sh.passed
-        fi
-    }
-
-    log_info "Clean up generated"
-    cd $RECLASS_ROOT
-    $SUDO rm -rf $RECLASS_ROOT/nodes/_generated/*
-
-    log_info "Re/starting salt services"
-    pgrep salt-master | sed /$$/d | xargs --no-run-if-empty -i{} $SUDO kill -9 {}
-    pkill -9 salt-minion
-    sleep 1
-    $SUDO service salt-master restart
-    $SUDO service salt-minion restart
-    sleep 10
-}
-
-# Init salt master
-saltmaster_init() {
-
-    log_info "Runing saltmaster states"
-    test -n "$MASTER_HOSTNAME" || echo "missing \$MASTER_HOSTNAME" && return 
-
-    set -e
-    $SUDO salt-call saltutil.sync_all >/dev/null
-
-    # TODO: Placeholder update saltmaster spec (nodes/FQDN.yml) to be able to bootstrap with minimal configuration
-    # (ie: with linux, git, salt formulas)
-
-    #log_info "Verify SaltMaster, before salt-master is fully initialized"
-    #if ! $SUDO reclass-salt -p ${MASTER_HOSTNAME} &> /tmp/${MASTER_HOSTNAME}.pillar;then
-    #   log_warn "Node verification before initialization failed."; cat /tmp/${MASTER_HOSTNAME}.pillar;
-    #fi
-
-    log_info "State: salt.master.env"
-    if ! $SUDO salt-call ${SALT_OPTS} -linfo state.apply salt.master.env; then
-      log_err "State salt.master.env failed, keep your eyes wide open."
-    fi
-
-    log_info "State: salt.master.pillar"
-    retry ${SALT_STATE_RETRY} $SUDO salt-call ${SALT_OPTS} state.apply salt.master.pillar pillar='{"reclass":{"storage":{"data_source":{"engine":"local"}}}}'
-    # Note: sikp reclass data dir states
-    #       in order to avoid pull from configured repo/branch
-
-    # Revert temporary SaltMaster minimal configuration, if any
-    pushd $RECLASS_ROOT
-    if [ $(git diff --name-only nodes | sort | uniq | wc -l) -ge 1 ]; then
-      git status || true
-      log_warn "Locally modified $RECLASS_ROOT/nodes found. (Possibly salt-master minimized setup from salt-master-setup.sh call)"
-      log_info "Checkout HEAD state of $RECLASS_ROOT/nodes/*."
-      git checkout -- $RECLASS_ROOT/nodes || true
-      log_info "Re-Run states: salt.master.env and salt.master.pillar according the HEAD state."
-      log_info "State: salt.master.env"
-      if ! $SUDO salt-call ${SALT_OPTS} -linfo state.apply salt.master.env; then
-        log_err "State salt.master.env failed, keep your eyes wide open."
-      fi
-      log_info "State: salt.master.pillar"
-      retry ${SALT_STATE_RETRY} $SUDO salt-call ${SALT_OPTS} state.apply salt.master.pillar pillar='{"reclass":{"storage":{"data_source":{"engine":"local"}}}}'
-    fi
-    popd
-
-    log_info "State: salt.master.storage.node"
-    set +e
-    $SUDO salt-call ${SALT_OPTS} state.apply reclass.storage.node
-    ret=$?
-    set -e
-
-    if [[ $ret -eq 2 ]]; then
-        log_err "State reclass.storage.node failed with exit code 2 but continuing."
-    elif [[ $ret -ne 0 ]]; then
-        log_err "State reclass.storage.node failed with exit code $ret"
-        exit 1
-    fi
-
-    log_info "Re/starting salt services"
-    $SUDO sed -i 's/^master:.*/master: localhost/' /etc/salt/minion.d/minion.conf
-    $SUDO service salt-minion restart >/dev/null
-    $SUDO salt-call ${SALT_OPTS} saltutil.sync_all >/dev/null
-
-    verify_salt_master
-    set +e
-
-}
-
-
-function verify_salt_master() {
-    set -e
-
-    log_info "Verify Salt master"
-    test -n "$MASTER_HOSTNAME" || echo "missing \$MASTER_HOSTNAME" && return 
-
-    if [[ $VERIFY_SALT_CALL =~ ^(True|true|1|yes)$ ]]; then
-      $SUDO salt-call ${SALT_OPTS} --id=${MASTER_HOSTNAME} grains.item roles > /tmp/${MASTER_HOSTNAME}.grains.item.roles
-      $SUDO salt-call ${SALT_OPTS} --id=${MASTER_HOSTNAME} state.show_lowstate > /tmp/${MASTER_HOSTNAME}.state.show_state
-      $SUDO salt-call --no-color grains.items
-      $SUDO salt-call --no-color pillar.data
-    fi
-    if ! $SUDO reclass --nodeinfo ${MASTER_HOSTNAME} > /tmp/${MASTER_HOSTNAME}.reclass.nodeinfo; then
-        log_err "For more details see full log /tmp/${MASTER_HOSTNAME}.reclass.nodeinfo"
-        exit 1
-    fi
-}
-
-function verify_salt_minion() {
-  set -e
-  node=$1
-  log_info "Verifying ${node}"
-  if [[ $VERIFY_SALT_CALL =~ ^(True|true|1|yes)$ ]]; then
-    $SUDO salt-call ${SALT_OPTS} --id=${node} grains.item roles > /tmp/${node}.grains.item.roles
-    $SUDO salt-call ${SALT_OPTS} --id=${node} state.show_lowstate > /tmp/${node}.state.show_lowstate
-  fi
-  if ! $SUDO reclass --nodeinfo ${node} > /tmp/${node}.reclass.nodeinfo; then
-      log_err "For more details see full log /tmp/${node}.reclass.nodeinfo"
-      if [[ ${BREAK_ON_VERIFICATION_ERROR:-yes} =~ ^(True|true|1|yes)$ ]]; then
-        exit 1
-      fi
-  fi
-}
-
-function verify_salt_minions() {
-    #set -e
-    NODES=$(find $RECLASS_ROOT/nodes/ -name "*.yml" | grep -v "cfg")
-    log_info "Verifying minions: $(echo ${NODES}|xargs)"
-
-    # Parallel
-    #echo $NODES | parallel --no-notice -j 2 --halt 2 "verify_salt_minion \$(basename {} .yml) > {}.pillar_verify"
-    #ls -lrta *.pillar_verify | tail -n 1 | xargs -n1 tail -n30
-
-    function filterFails() {
-        grep -v '/grains' | tee -a $1 | tail -n20
-    }
-
-    log_info "Verify nodes"
-    passed=0
-    for node in ${NODES}; do
-        node=$(basename $node .yml)
-
-        # filter first in cluster.. ctl-01, mon-01, etc..
-        if [[ "${node//.*}" =~ 01 || "${node//.*}" =~ 02  ]] ;then
-            verify_salt_minion ${node} || continue
-        else
-            echo Skipped $node.
-        fi
-        passed=$(($passed+1))
-    done
-    # fail on failures
-    total=$(echo $NODES | xargs --no-run-if-empty -n1 echo |wc -l)
-    test ! $passed -lt $total || log_err "Results: $passed of $total passed."
-    test ! $passed -lt $total || {
-      tail -n50 /tmp/*.pillar_verify
-      return 1
-    }
-}
-
-
-options
-# detect if file is being sourced
-[[ "$0" != "$BASH_SOURCE"  ]] || {
-    log_info "Bootstrap & verification of SaltMaster and configured minions."
-    trap _atexit INT TERM EXIT
-    system_config
-
-    saltmaster_bootstrap &&\
-    saltmaster_init &&\
-
-    verify_salt_minions
-}
diff --git a/salt-master-setup.sh b/salt-master-setup.sh
deleted file mode 100755
index 525e826..0000000
--- a/salt-master-setup.sh
+++ /dev/null
@@ -1,429 +0,0 @@
-#!/bin/bash -e
-
-# Installs Salt and configure minimal SaltMaster or Minion to be used with:
-# - http://github.com/salt-formulas
-# - http://github.com/salt-formulas/salt-formula-salt (salt.master sls)
-
-# TODO:
-# - use PPA repository as formula source
-# - support for spm/yum
-
-# Source specific env vars.
-for path in /srv/salt . /srv/salt/reclass/classes/cluster /srv/salt/reclass/classes/cluster/${CLUSTER_NAME}; do
-  export $(find $path -maxdepth 1 -name '*.env' 2> /dev/null | xargs --no-run-if-empty cat ) > /dev/null
-done;
-
-# DEAULTS
-# salt apt repository
-test -e /etc/lsb-release && eval $(cat /etc/lsb-release)
-which lsb_release && DISTRIB_CODENAME=${DISTRIB_CODENAME:-$(lsb_release -cs)}
-#
-export APT_REPOSITORY="deb [arch=amd64] http://apt.mirantis.com/${DISTRIB_CODENAME} ${DISTRIB_REVISION:-stable} salt"
-export APT_REPOSITORY_GPG=${APT_REPOSITORY_GPG:-http://apt.mirantis.com/public.gpg}
-
-# reclass
-export RECLASS_ADDRESS=${RECLASS_ADDRESS:-https://github.com/salt-formulas/openstack-salt.git} # https/git
-
-# formula
-export FORMULAS_BASE=${FORMULAS_BASE:-https://github.com/salt-formulas}
-export FORMULAS_PATH=${FORMULAS_PATH:-/usr/share/salt-formulas}
-export FORMULAS_BRANCH=${FORMULAS_BRANCH:-master}
-export FORMULAS_SOURCE=${FORMULAS_SOURCE:-pkg} # pkg/git
-# essential set of formulas (known to by used on cfg01 node for most setups)
-FORMULAS_SALT_MASTER=${FORMULAS_SALT_MASTER:- $EXTRA_FORMULAS memcached openssh ntp nginx collectd sensu heka sphinx mysql grafana libvirt rsyslog glusterfs postfix xtrabackup freeipa prometheus telegraf elasticsearch kibana rundeck devops-portal horizon}
-# minimal set of formulas for salt-master bootstrap
-declare -a FORMULAS_SALT_MASTER=(linux reclass salt git $(echo $FORMULAS_SALT_MASTER))
-export FORMULAS_SALT_MASTER
-
-# system / host
-export HOSTNAME=${HOSTNAME:-cfg01}
-export DOMAIN=${DOMAIN:-bootstrap.local}
-
-# salt
-export SALT_MASTER=${SALT_MASTER:-127.0.0.1} # ip or fqdn
-export MINION_ID=${MINION_ID:-${HOSTNAME}.${DOMAIN}}
-
-# saltstack
-BOOTSTRAP_SALTSTACK=${BOOTSTRAP_SALTSTACK:-True}
-BOOTSTRAP_SALTSTACK_OPTS=${BOOTSTRAP_SALTSTACK_OPTS:- -dX stable 2016.3 }
-
-# ENVIRONMENT
-#############
-SALT_SOURCE=${SALT_SOURCE:-pkg}
-SALT_VERSION=${SALT_VERSION:-latest}
-
-
-if [ "$FORMULAS_SOURCE" == "git" ]; then
-  SALT_ENV=${SALT_ENV:-dev}
-elif [ "$FORMULAS_SOURCE" == "pkg" ]; then
-  SALT_ENV=${SALT_ENV:-prd}
-fi
-
-eval $(cat /etc/*release 2> /dev/null)
-PLATFORM_FAMILY=$(echo ${ID_LIKE// */} | tr A-Z a-z)
-
-case $PLATFORM_FAMILY in
-  debian )
-      PKGTOOL="$SUDO apt-get"
-      test ${VERSION_ID//\.*/} -ge 16 && {
-        SVCTOOL=service
-      } || { SVCTOOL=service
-      }
-    ;;
-  rhel )
-      PKGTOOL="$SUDO yum"
-      test ${VERSION_ID//\.*/} -ge 7 && {
-        SVCTOOL=systemctl
-      } || { SVCTOOL=service
-      }
-    ;;
-esac
-
-export PLATFORM_FAMILY
-export PKGTOOL
-export SVCTOOL
-
-# FUNCTIONS
-###########
-configure_pkg_repo()
-{
-
-    case $PLATFORM_FAMILY in
-      debian)
-          if [ -n "$APT_REPOSITORY_PPA" ]; then
-            which add-apt-repository || $SUDO apt-get install -y software-properties-common
-            $SUDO add-apt-repository -y ppa:${APT_REPOSITORY_PPA}
-          else
-            echo -e  "$APT_REPOSITORY " | $SUDO tee /etc/apt/sources.list.d/bootstrap.list >/dev/null
-            curl -sL $APT_REPOSITORY_GPG | $SUDO apt-key add -
-          fi
-          $SUDO apt-get clean
-          $SUDO apt-get update
-        ;;
-      rhel)
-          $SUDO yum install -y https://repo.saltstack.com/yum/redhat/salt-repo-latest-1.el${VERSION_ID}.noarch.rpm
-          $SUDO yum clean all
-        ;;
-    esac
-
-}
-
-configure_salt_master()
-{
-
-  echo "Configuring salt-master ..."
-
-  [ ! -d /etc/salt/master.d ] && mkdir -p /etc/salt/master.d
-  cat <<-EOF > /etc/salt/master.d/master.conf
-	file_roots:
-	  base:
-	  - /usr/share/salt-formulas/env
-	  prd:
-	  - /srv/salt/env/prd
-	  dev:
-	  - /srv/salt/env/dev
-	pillar_opts: False
-	open_mode: True
-	reclass: &reclass
-	  storage_type: yaml_fs
-	  inventory_base_uri: /srv/salt/reclass
-	ext_pillar:
-	  - reclass: *reclass
-	master_tops:
-	  reclass: *reclass
-EOF
-
-  echo "Configuring reclass ..."
-
-  [ ! -d /etc/reclass ] && mkdir /etc/reclass
-  cat <<-EOF > /etc/reclass/reclass-config.yml
-	storage_type: yaml_fs
-	pretty_print: True
-	output: yaml
-	inventory_base_uri: /srv/salt/reclass
-EOF
-
-  if [ ! -d /srv/salt/reclass ]; then
-    # No reclass at all, clone from given address
-    ssh-keyscan -H github.com >> ~/.ssh/known_hosts || true
-    if echo ${RECLASS_BRANCH:-master} | egrep -q "^refs"; then		
-        git clone ${RECLASS_ADDRESS} /srv/salt/reclass		
-        cd /srv/salt/reclass		
-        git fetch ${RECLASS_ADDRESS} ${RECLASS_BRANCH:-master} && git checkout FETCH_HEAD		
-        cd -		
-    else		
-        git clone -b ${RECLASS_BRANCH:-master} ${RECLASS_ADDRESS} /srv/salt/reclass;		
-    fi;
-  fi;
-
-  cd /srv/salt/reclass
-  if [ ! -d /srv/salt/reclass/classes/system/linux ]; then
-    # Possibly subrepo checkout needed
-    git submodule update --init --recursive
-  fi
-
-  #sed -ie "s#\(reclass_data_revision.\).*#\1 $RECLASS_BRANCH#" $(find nodes -name ${MASTER_HOSTNAME}.yml|tail -n1)
-
-  mkdir -vp /srv/salt/reclass/nodes
-  CONFIG=$(find /srv/salt/reclass/nodes -name ${MINION_ID}.yml| grep yml | tail -n1)
-  CONFIG=${CONFIG:-/srv/salt/reclass/nodes/${MINION_ID}.yml}
-  if [[ $SALT_MASTER_BOOTSTRAP_MINIMIZED =~ ^(True|true|1|yes)$ || ! -f "${CONFIG}" ]]; then
-  cat <<-EOF > ${CONFIG}
-	classes:
-	- service.git.client
-	- system.linux.system.single
-	- system.salt.master.single
-	- system.salt.master.$FORMULAS_SOURCE
-	- system.reclass.storage.salt
-	parameters:
-	  _param:
-	    reclass_data_repository: "$RECLASS_ADDRESS"
-	    reclass_data_revision: ${RECLASS_BRANCH:-master}
-	    salt_formula_branch: ${SALT_FORMULAS_BRANCH:-master}
-	    reclass_config_master: $SALT_MASTER
-	    single_address: $SALT_MASTER
-	    salt_master_host: $SALT_MASTER
-	    salt_master_base_environment: $SALT_ENV
-	    linux_system_codename: $DISTRIB_CODENAME
-	  linux:
-	    system:
-	      name: $MINION_ID
-	      domain: $DOMAIN
-	# ########
-EOF
-
-    if [ "$SALT_VERSION" == "latest" ]; then
-      VERSION=""
-    else
-      VERSION="version: $SALT_VERSION"
-    fi
-
-    cat <<-EOF >> ${CONFIG}
-		  salt:
-		    master:
-		      accept_policy: open_mode
-		      source:
-		        engine: $SALT_SOURCE
-		        $VERSION
-		    minion:
-		      source:
-		        engine: $SALT_SOURCE
-		        $VERSION
-		# ########
-		# vim: ft=yaml sw=2 ts=2 sts=2
-EOF
-  fi
-}
-
-configure_salt_minion()
-{
-  [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d
-  cat <<-EOF > /etc/salt/minion.d/minion.conf
-	master: $SALT_MASTER
-	id: $MINION_ID
-	EOF
-}
-
-
-install_salt_master_pkg()
-{
-    echo -e "\nPreparing base OS repository ...\n"
-
-    configure_pkg_repo
-
-    echo -e "\nInstalling salt master ...\n"
-
-    case $PLATFORM_FAMILY in
-      debian)
-          $SUDO apt-get install -y git
-	  which reclass || $SUDO apt install -qqq -y reclass
-          curl -L https://bootstrap.saltstack.com | $SUDO sh -s -- -M ${BOOTSTRAP_SALTSTACK_OPTS} &>/dev/null || true
-        ;;
-      rhel)
-          yum install -y git
-          which reclass || $SUDO yum install -y reclass
-          curl -L https://bootstrap.saltstack.com | $SUDO sh -s -- -M ${BOOTSTRAP_SALTSTACK_OPTS} &>/dev/null || true
-        ;;
-    esac
-    
-    which reclass-salt || {
-      test -e /usr/share/reclass/reclass-salt && {
-        ln -fs /usr/share/reclass/reclass-salt /usr/bin
-      }
-    }
-
-    configure_salt_master
-
-    echo -e "\nRestarting services ...\n"
-    [ -f /etc/salt/pki/minion/minion_master.pub ] && rm -f /etc/salt/pki/minion/minion_master.pub
-    $SVCTOOL salt-master restart
-}
-
-install_salt_master_pip()
-{
-    echo -e "\nPreparing base OS repository ...\n"
-
-    case $PLATFORM_FAMILY in
-      debian)
-          $SUDO apt-get install -y python-pip python-dev zlib1g-dev git
-	  which reclass || $SUDO apt-get install -y reclass
-        ;;
-      rhel)
-	  $SUDO yum install -y git
-	  which reclass || $SUDO yum install -y reclass
-        ;;
-    esac
-
-    echo -e "\nInstalling salt master ...\n"
-    # TODO: replace with saltstack bootstrap script
-    
-    if [ "$SALT_VERSION" == "latest" ]; then
-      pip install salt
-    else
-      pip install salt==$SALT_VERSION
-    fi
-
-    curl -Lo /etc/init.d/salt-master https://anonscm.debian.org/cgit/pkg-salt/salt.git/plain/debian/salt-master.init && chmod 755 /etc/init.d/salt-master
-    ln -s /usr/local/bin/salt-master /usr/bin/salt-master
-
-    which reclass-salt || {
-      test -e /usr/share/reclass/reclass-salt && {
-        ln -fs /usr/share/reclass/reclass-salt /usr/bin
-      }
-    }
-
-    configure_salt_master
-
-    echo -e "\nRestarting services ...\n"
-    [ -f /etc/salt/pki/minion/minion_master.pub ] && rm -f /etc/salt/pki/minion/minion_master.pub
-    $SVCTOOL salt-master restart
-}
-
-
-
-install_salt_minion_pkg()
-{
-
-    echo -e "\nInstalling salt minion ...\n"
-
-    case $PLATFORM_FAMILY in
-      debian)
-          curl -L https://bootstrap.saltstack.com | $SUDO sh -s -- ${BOOTSTRAP_SALTSTACK_OPTS} &>/dev/null || true
-      ;;
-      rhel)
-          curl -L https://bootstrap.saltstack.com | $SUDO sh -s -- ${BOOTSTRAP_SALTSTACK_OPTS} &>/dev/null || true
-      ;;
-    esac
-
-
-    configure_salt_minion
-
-    $SVCTOOL salt-minion restart
-}
-
-install_salt_minion_pip()
-{
-    echo -e "\nInstalling salt minion ...\n"
-
-    curl -Lo /etc/init.d/salt-minion https://anonscm.debian.org/cgit/pkg-salt/salt.git/plain/debian/salt-minion.init && chmod 755 /etc/init.d/salt-minion
-    ln -s /usr/local/bin/salt-minion /usr/bin/salt-minion
-
-    configure_salt_minion
-    $SVCTOOL salt-minion restart
-}
-
-
-install_salt_formula_pkg()
-{
-    configure_pkg_repo
-
-    case $PLATFORM_FAMILY in
-      debian)
-          echo "Configuring necessary formulas ..."
-
-          [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service
-          # Set essentials if FORMULAS_SALT_MASTER is not defined at all
-          [ -z ${FORMULAS_SALT_MASTER+x} ] && declare -a FORMULAS_SALT_MASTER=("linux" "reclass" "salt" "memcached")
-          for formula_service in "${FORMULAS_SALT_MASTER[@]}"; do
-              echo -e "\nConfiguring salt formula ${formula_service} ...\n"
-              [ ! -d "${FORMULAS_PATH}/env/${formula_service}" ] && \
-                  if ! $SUDO apt-get install -y salt-formula-${formula_service}; then
-                    echo -e "\nInstall salt-formula-${formula_service} failed.\n"
-                    exit 1
-                  fi
-              [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && \
-                  ln -sf ${FORMULAS_PATH}/reclass/service/${formula_service} /srv/salt/reclass/classes/service/${formula_service}
-          done
-        ;;
-      rhel)
-        # TODO
-      ;;
-    esac
-
-    [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env || echo ""
-    [ ! -L /srv/salt/env/prd ] && ln -s ${FORMULAS_PATH}/env /srv/salt/env/prd || echo ""
-}
-
-install_salt_formula_git()
-{
-    echo "Configuring necessary formulas ..."
-
-    [ ! -d /srv/salt/reclass/classes/service ] && mkdir -p /srv/salt/reclass/classes/service
-    # Set essentials if FORMULAS_SALT_MASTER is not defined at all
-    [ -z ${FORMULAS_SALT_MASTER+x} ] && declare -a FORMULAS_SALT_MASTER=("linux" "reclass" "salt" "memcached")
-    for formula_service in "${FORMULAS_SALT_MASTER[@]}"; do
-        echo -e "\nConfiguring salt formula ${formula_service} ...\n"
-        _BRANCH=${FORMULAS_BRANCH}
-        [ ! -d "${FORMULAS_PATH}/env/_formulas/${formula_service}" ] && {
-            if ! git ls-remote --exit-code --heads ${FORMULAS_BASE}/salt-formula-${formula_service}.git ${_BRANCH}; then
-              # Fallback to the master branch if the branch doesn't exist for this repository
-              _BRANCH=master
-            fi
-            if ! git clone ${FORMULAS_BASE}/salt-formula-${formula_service}.git ${FORMULAS_PATH}/env/_formulas/${formula_service} -b ${_BRANCH}; then
-              echo -e "\nCloning of ${FORMULAS_BASE}/salt-formula-${formula_service}.git failed.\n"
-              exit 1
-            fi
-          } || {
-            cd ${FORMULAS_PATH}/env/_formulas/${formula_service};
-            git fetch origin/${_BRANCH} || git fetch --all
-            git checkout ${_BRANCH} && git pull || git pull;
-            cd -
-        }
-        [ ! -L "/usr/share/salt-formulas/env/${formula_service}" ] && \
-            ln -sf ${FORMULAS_PATH}/env/_formulas/${formula_service}/${formula_service} /usr/share/salt-formulas/env/${formula_service}
-        [ ! -L "/srv/salt/reclass/classes/service/${formula_service}" ] && \
-            ln -sf ${FORMULAS_PATH}/env/_formulas/${formula_service}/metadata/service /srv/salt/reclass/classes/service/${formula_service}
-    done
-
-    [ ! -d /srv/salt/env ] && mkdir -p /srv/salt/env || echo ""
-    [ ! -L /srv/salt/env/dev ] && ln -s /usr/share/salt-formulas/env /srv/salt/env/dev || echo ""
-}
-
-# MAIN
-####
-[[ "$0" != "$BASH_SOURCE" ]] || {
-# unless file is being sourced
-
-  # DEBUGING
-  #set -x
-  #test -e $(dirname $0)/env/salt.env && source $(dirname $0)/env/salt.env
-  #set
-
-  # CLI
-  while [ x"$1" != x"" ]; do
-    which curl &>/dev/null || $PKGTOOL -y install curl &>/dev/null
-
-    case $1 in
-        master )
-          install_salt_master_$SALT_SOURCE
-          install_salt_minion_$SALT_SOURCE
-          install_salt_formula_$FORMULAS_SOURCE
-          ;;
-        minion )
-          install_salt_minion_$SALT_SOURCE
-          ;;
-    esac
-    shift
-  done
-  echo DONE
-}