<commit_before>#!/bin/sh
#
# Connect to a remote machine, build there and download output.
#
#  - remote environment needs to be setup and listening for SSH
#  - remote environment needs git installed
#  - process will install dependencies on the remote environment
#
# Date: 6-9-2014
# Author: <NAME> <<EMAIL>>
#
# Usage:
#   ./run_remote.sh [user@]hostname
#
set -e

REMOTE_HOST=$1
if [ "$REMOTE_HOST" == "" ]; then
    echo "Usage:"
    echo "  run_remote.sh <host/ip>"
    exit -1
fi

# Get ROOT Directory
ROOT=$(dirname $(dirname $(readlink -e $0)))

# Install git
# TODO: make this work for other OS like CentOS

ssh -t "$REMOTE_HOST" "sudo apt-get -y install git-core"

# Clone or update the repo
if ssh -q "$REMOTE_HOST" [ -d cf-php-buildpack-binary-build-scripts ]; then 
    ssh "$REMOTE_HOST" "cd cf-php-buildpack-binary-build-scripts; git pull"
else
    ssh "$REMOTE_HOST" "git clone https://github.com/dmikusa-pivotal/cf-php-buildpack-binary-build-scripts.git"
fi

# Update / install dependencies
ssh -t "$REMOTE_HOST" "cd cf-php-buildpack-binary-build-scripts; ./build/install-deps.sh"

# Run the build-all.sh script
ssh "$REMOTE_HOST" "cd cf-php-buildpack-binary-build-scripts; ./build/build-all.sh"

# Copy the binaries to the 
scp -r "$REMOTE_HOST:./cf-php-buildpack-binary-build-scripts/output/*" "$ROOT/output/"<commit_msg>Added remote_* functions to make script easier to read.  Also modified script to install script, if possible, otherwise it exits and prompts the user to install it.<commit_after>#!/bin/bash
#
# Connect to a remote machine, build there and download output.
#
#  - remote environment needs to be setup and listening for SSH
#  - remote environment needs git installed
#  - process will install dependencies on the remote environment
#
# Date: 6-9-2014
# Author: <NAME> <<EMAIL>>
#
# Usage:
#   ./run_remote.sh [user@]hostname
#
set -e

REMOTE_HOST=$1
if [ "$REMOTE_HOST" == "" ]; then
    echo "Usage:"
    echo "  run_remote.sh <host/ip>"
    exit -1
fi

# Get ROOT Directory
if [[ "$0" == /* ]]; then
    ROOT=$(dirname "$(dirname "$0")")
else
    ROOT=$(dirname $(dirname "$(pwd)/${0#./}"))
fi
echo "Root [$ROOT]"

function remote_test {
    ssh -q "$REMOTE_HOST" "$1"
    return $?
}

function remote_run {
    ssh -qt "$REMOTE_HOST" "$1"
    return $?
}

function remote_capture {
    CAPTURE=$(ssh -qt "$REMOTE_HOST" "$1")  # Returning "Ubuntu\n", not sure why
    return $?
}

# Install git
if ! remote_test "hash git 2\>/dev/null"; then
    echo "Git not installed on the remote host.  Attempting to install..."
    remote_capture "cat /etc/issue | cut -d ' ' -f 1 | tr -d '\n'"
    if [ "$CAPTURE" == "Ubuntu" ]; then
        remote_run "sudo apt-get -y install git-core"
    elif [ "$CAPTURE" == "CentOS" ]; then 
        remote_run "sudo yum install git"
    else
        echo "Not sure about the remote OS, please manually install git."
        exit -1
    fi
fi

# Clone or update the repo
if remote_test "[ -d cf-php-buildpack-binary-build-scripts ]"; then 
    remote_run "cd cf-php-buildpack-binary-build-scripts; git pull"
else
    remote_run "git clone https://github.com/dmikusa-pivotal/cf-php-buildpack-binary-build-scripts.git"
fi

# Update / install dependencies
remote_run "cd cf-php-buildpack-binary-build-scripts; ./build/install-deps.sh"

# Run the build-all.sh script
remote_run "cd cf-php-buildpack-binary-build-scripts; ./build/build-all.sh"

# Copy the binaries to the 
scp -r "$REMOTE_HOST:./cf-php-buildpack-binary-build-scripts/output/*" "$ROOT/output/"
{'fraction_non_alphanumeric': 0.1420873511060692, 'fraction_numerical': 0.00737379466817924, 'mean_word_length': 3.403245942571785, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 12, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3905108', 'n_tokens_mistral': 1265, 'n_tokens_neox': 1183, 'n_words': 368}