#!/usr/bin/env bash

set -e
[ -n "$DEBUG" ] && set -x

base_dir=$(readlink -nf $(dirname $0)/..)
stages_dir=$base_dir/stages

mnt=$(echo "$1" | sed -e 's#/*$##')
spec=$2
settings_file=$3

# Generate settings for every stage in the spec
function stage() {
  echo "=== Configuring '$1' stage ==="
  if [ -x $stages_dir/$1/config.sh ]
  then
    $stages_dir/$1/config.sh $settings_file
  fi
}

source $settings_file
source $spec

#################################################

previous_stage=

# Apply stage for every stage in the spec
function stage() {
  echo "=== Applying '$1' stage ==="
  echo "== Started $(date) =="

  mkdir -p $mnt/work

  $stages_dir/$1/apply.sh $mnt/work

  previous_stage=$1
}

source $settings_file
source $spec

#!/usr/bin/env bash

set -e
[ -n "$DEBUG" ] && set -x

base_dir=$(readlink -nf $(dirname $0)/..)
stages_dir=$base_dir/stages

mnt=$(echo "$1" | sed -e 's#/*$##')
spec=$2
settings_file=$3

function stage_direct() {
  local stage=$1
  local mnt_work=$mnt/work

  mkdir -p $mnt_work

  # Apply stage
  $stages_dir/$stage/apply.sh $mnt_work
}

# Generate settings for every stage in the spec
function stage() {
  echo "=== Configuring '$1' stage ==="
  if [ -x $stages_dir/$1/config.sh ]
  then
    $stages_dir/$1/config.sh $settings_file
  fi
}

source $settings_file
source $spec

previous_stage=

function stage() {
  echo "=== Applying '$1' stage ==="
  echo "== Started $(date) =="
  stage_direct $1

  previous_stage=$1
}

source $settings_file
source $spec

--- 
+++ 
@@ -9,6 +9,16 @@
 mnt=$(echo "$1" | sed -e 's#/*$##')
 spec=$2
 settings_file=$3
+
+function stage_direct() {
+  local stage=$1
+  local mnt_work=$mnt/work
+
+  mkdir -p $mnt_work
+
+  # Apply stage
+  $stages_dir/$stage/apply.sh $mnt_work
+}
 
 # Generate settings for every stage in the spec
 function stage() {
@@ -22,18 +32,12 @@
 source $settings_file
 source $spec
 
-#################################################
-
 previous_stage=
 
-# Apply stage for every stage in the spec
 function stage() {
   echo "=== Applying '$1' stage ==="
   echo "== Started $(date) =="
-
-  mkdir -p $mnt/work
-
-  $stages_dir/$1/apply.sh $mnt/work
+  stage_direct $1
 
   previous_stage=$1
 }
Simplify bash code to prep for ruby conversion

Signed-off-by: Colin Humphreys <cdf09037082c3e7e963137b94e9d1be99cdeeaca@pivotallabs.com>
