WORKSPACE="/vagrant"
GIT_BRANCH="master"
SERVER_NAME="localhost"
ENV_FILE="$WORKSPACE/atmo-extras/clank_init/build_env/variables.yml@vagrant"

# Before running, ensure that `/vagrant` is present
# - if there isn't a `/vagrant` - someone might be 
#   trying to run this from the host of the vm - 
#   which is just a bag-of-hurt

#0. Begin, eh
cd "$WORKSPACE"


#sudo mkdir -p /opt/dev/atmosphere
#sudo chown vagrant:vagrant -R /opt/dev/atmosphere
#sudo mkdir -p /opt/env/atmo
#sudo chown vagrant:vagrant -R /opt/env/atmo


#1. Clone repos - pre-flight handles this
# ensure `atmo-extras` in place
# ensure `clank` in place

#2. Prepare execution of ratchet
virtualenv ratchet_env
. ratchet_env/bin/activate
pip install -r clank/ratchet_requirements.txt

#3. Running ratchet
cd "$WORKSPACE/clank"
PYTHONUNBUFFERED=1 python ratchet.py --workspace $WORKSPACE --env_file $ENV_FILE --skip "troposphere"

#4. Chown to vagrant, activate and run!
cd "$WORKSPACE"
sudo chown -R vagrant:vagrant .
cd "/opt/dev/atmosphere"
. "/opt/env/atmo/bin/activate"


WORKSPACE="/vagrant"
GIT_BRANCH="master"
SERVER_NAME="localhost"
ENV_FILE="$WORKSPACE/atmo-extras/clank_init/build_env/variables.yml@vagrant"




# screw it - I'm writing functions...
create_if_does_not_exist() {
    if [ ! -d "$1" ]; then
        echo "making directory & chown-ing... ";
        sudo mkdir -p "$1";
        sudo chown vagrant:vagrant -R "$1";
    fi
}

# Before running, ensure that `/vagrant` is present
# - if there isn't a `/vagrant` - someone might be 
#   trying to run this from the host of the vm - 
#   which is just a bag-of-hurt

#0. Begin, eh
cd "$WORKSPACE"

create_if_does_not_exist "/opt/dev/atmosphere"
create_if_does_not_exist "/opt/env/atmo"


#1. Clone repos - pre-flight handles this
# ensure `atmo-extras` in place
# ensure `clank` in place

#2. Prepare execution of ratchet
virtualenv ratchet_env
. ratchet_env/bin/activate
pip install -r clank/ratchet_requirements.txt

#3. Running ratchet
cd "$WORKSPACE/clank"
PYTHONUNBUFFERED=1 python ratchet.py --workspace $WORKSPACE --env_file $ENV_FILE --skip "troposphere"

#4. Chown to vagrant, activate and run!
cd "$WORKSPACE"
sudo chown -R vagrant:vagrant .
cd "/opt/dev/atmosphere"
. "/opt/env/atmo/bin/activate"


Create the canonical paths for atmosphere
Create the canonical paths for atmosphere

Oddly, clank wants these paths available before they are created by
roles. This appears to have something to do with `--workspace`,
however the vagrant BUILD_ENV has `JENKINS: false` and does not set
the JENKINS_WORKSPACE variable. It is likely because the line calling
out to `ratchet.py` is not inspected $? (or ratchet.py is *not*
bubbling up the exit code).
