2016-12-01 23:06:32 +01:00
|
|
|
#!/bin/bash
|
2016-01-14 11:29:50 -08:00
|
|
|
|
2016-12-01 23:06:32 +01:00
|
|
|
set -e -o pipefail
|
|
|
|
|
|
|
|
|
|
# Workaround for Travis CI cookbook https://github.com/travis-ci/travis-ci/issues/4862,
|
|
|
|
|
# where $PATH will be extended with relative paths to the NPM binaries.
|
2017-05-30 18:27:06 +02:00
|
|
|
PATH=`echo ${PATH} | sed -e 's/:\.\/node_modules\/\.bin//'`
|
2016-12-01 23:06:32 +01:00
|
|
|
|
|
|
|
|
TUNNEL_FILE="BrowserStackLocal-linux-x64.zip"
|
2017-05-30 18:27:06 +02:00
|
|
|
TUNNEL_URL="https://www.browserstack.com/browserstack-local/${TUNNEL_FILE}"
|
2016-12-01 23:06:32 +01:00
|
|
|
TUNNEL_DIR="/tmp/browserstack-tunnel"
|
2017-05-30 18:27:06 +02:00
|
|
|
TUNNEL_LOG="${LOGS_DIR}/browserstack-tunnel.log"
|
2016-12-01 23:06:32 +01:00
|
|
|
|
2017-05-30 18:27:06 +02:00
|
|
|
BROWSER_STACK_ACCESS_KEY=`echo ${BROWSER_STACK_ACCESS_KEY} | rev`
|
2016-12-01 23:06:32 +01:00
|
|
|
|
|
|
|
|
# Cleanup and create the folder structure for the tunnel connector.
|
2017-05-30 18:27:06 +02:00
|
|
|
rm -rf ${TUNNEL_DIR} ${BROWSER_PROVIDER_READY_FILE}
|
|
|
|
|
mkdir -p ${TUNNEL_DIR}
|
|
|
|
|
touch ${TUNNEL_LOG}
|
2016-12-01 23:06:32 +01:00
|
|
|
|
2017-05-30 18:27:06 +02:00
|
|
|
cd ${TUNNEL_DIR}
|
2016-12-01 23:06:32 +01:00
|
|
|
|
|
|
|
|
# Download the browserstack local binaries.
|
2017-05-30 18:27:06 +02:00
|
|
|
curl ${TUNNEL_URL} -o ${TUNNEL_FILE} 2> /dev/null 1> /dev/null
|
2016-12-01 23:06:32 +01:00
|
|
|
|
|
|
|
|
# Extract the browserstack local binaries from the tarball.
|
|
|
|
|
mkdir -p browserstack-tunnel
|
2017-05-30 18:27:06 +02:00
|
|
|
unzip -q ${TUNNEL_FILE} -d browserstack-tunnel
|
2016-12-01 23:06:32 +01:00
|
|
|
|
|
|
|
|
# Cleanup the download directory.
|
2017-05-30 18:27:06 +02:00
|
|
|
rm ${TUNNEL_FILE}
|
2016-12-01 23:06:32 +01:00
|
|
|
|
|
|
|
|
ARGS=""
|
|
|
|
|
|
|
|
|
|
# Set tunnel-id only on Travis, to make local testing easier.
|
2017-05-30 18:27:06 +02:00
|
|
|
if [ ! -z "${TRAVIS_JOB_ID}" ]; then
|
|
|
|
|
ARGS="${ARGS} --local-identifier ${TRAVIS_JOB_ID}"
|
2016-12-01 23:06:32 +01:00
|
|
|
fi
|
|
|
|
|
|
2017-05-30 18:27:06 +02:00
|
|
|
echo "Starting Browserstack Local in the background, logging into: ${TUNNEL_LOG}"
|
2016-12-01 23:06:32 +01:00
|
|
|
|
|
|
|
|
# Extension to the BrowserStackLocal binaries, because those can't create a readyfile.
|
|
|
|
|
function create_ready_file {
|
|
|
|
|
|
|
|
|
|
# To be able to exit the tail properly we need to have a sub shell spawned, which is
|
|
|
|
|
# used to track the state of tail.
|
2017-05-30 18:27:06 +02:00
|
|
|
{ sleep 120; touch ${BROWSER_PROVIDER_ERROR_FILE}; } &
|
2016-12-01 23:06:32 +01:00
|
|
|
|
2017-05-30 18:27:06 +02:00
|
|
|
TIMER_PID=${!}
|
2016-12-01 23:06:32 +01:00
|
|
|
|
|
|
|
|
# Disown the background process, because we don't want to show any messages when killing
|
|
|
|
|
# the timer.
|
|
|
|
|
disown
|
|
|
|
|
|
|
|
|
|
# When the tail recognizes the `Ctrl-C` log message the BrowserStack Tunnel is up.
|
|
|
|
|
{
|
2017-05-30 18:27:06 +02:00
|
|
|
tail -n0 -f ${TUNNEL_LOG} --pid ${TIMER_PID} | { sed '/Ctrl/q' && kill -9 ${TIMER_PID}; };
|
2016-12-01 23:06:32 +01:00
|
|
|
} &> /dev/null
|
|
|
|
|
|
|
|
|
|
echo
|
|
|
|
|
echo "BrowserStack Tunnel ready"
|
|
|
|
|
|
2017-05-30 18:27:06 +02:00
|
|
|
touch ${BROWSER_PROVIDER_READY_FILE}
|
2016-12-01 23:06:32 +01:00
|
|
|
}
|
|
|
|
|
|
2017-05-30 18:27:06 +02:00
|
|
|
browserstack-tunnel/BrowserStackLocal -k ${BROWSER_STACK_ACCESS_KEY} ${ARGS} 2>&1 >> ${TUNNEL_LOG} &
|
2016-12-01 23:06:32 +01:00
|
|
|
|
|
|
|
|
# Wait for the tunnel to be ready and create the readyfile with the Browserstack PID
|
|
|
|
|
create_ready_file &
|