#!/bin/bash
if [[ -s //etc/profile ]]; then
  source //etc/profile
fi

if [[ -s $HOME/.bash_profile ]] ; then
  source $HOME/.bash_profile
fi

ANSI_RED="\033[31;1m"
ANSI_GREEN="\033[32;1m"
ANSI_RESET="\033[0m"
ANSI_CLEAR="\033[0K"

if [ $TERM = dumb ]; then
  unset TERM
fi
: "${SHELL:=/bin/bash}"
: "${TERM:=xterm}"
: "${USER:=travis}"
export SHELL
export TERM
export USER

TRAVIS_TEST_RESULT=
TRAVIS_CMD=

travis_cmd() {
  local assert output display retry timing cmd result

  cmd=$1
  TRAVIS_CMD=$cmd
  shift

  while true; do
    case "$1" in
      --assert)  assert=true; shift ;;
      --echo)    output=true; shift ;;
      --display) display=$2;  shift 2;;
      --retry)   retry=true;  shift ;;
      --timing)  timing=true; shift ;;
      *) break ;;
    esac
  done

  if [[ -n "$timing" ]]; then
    travis_time_start
  fi

  if [[ -n "$output" ]]; then
    echo "\$ ${display:-$cmd}"
  fi

  if [[ -n "$retry" ]]; then
    travis_retry eval "$cmd"
  else
    eval "$cmd"
  fi
  result=$?

  if [[ -n "$timing" ]]; then
    travis_time_finish
  fi

  if [[ -n "$assert" ]]; then
    travis_assert $result
  fi

  return $result
}

travis_time_start() {
  travis_timer_id=$(printf %08x $(( RANDOM * RANDOM )))
  travis_start_time=$(travis_nanoseconds)
  echo -en "travis_time:start:$travis_timer_id\r${ANSI_CLEAR}"
}

travis_time_finish() {
  local result=$?
  travis_end_time=$(travis_nanoseconds)
  local duration=$(($travis_end_time-$travis_start_time))
  echo -en "\ntravis_time:end:$travis_timer_id:start=$travis_start_time,finish=$travis_end_time,duration=$duration\r${ANSI_CLEAR}"
  return $result
}

travis_nanoseconds() {
  local cmd="date"
  local format="+%s%N"
  local os=$(uname)

  if hash gdate > /dev/null 2>&1; then
    
    cmd="gdate"
  elif [[ "$os" = Darwin ]]; then
    
    format="+%s000000000"
  fi

  $cmd -u $format
}

travis_internal_ruby() {
  if ! type rvm &>/dev/null; then
    source $HOME/.rvm/scripts/rvm &>/dev/null
  fi
  local i selected_ruby rubies_array rubies_array_sorted rubies_array_len
  rubies_array=( $(
    rvm list strings \
      | while read -r v; do
          if [[ ! "${v}" =~ ^ruby-(2\.[0-2]\.[0-9]|1\.9\.3) ]]; then
            continue
          fi
          v="${v//ruby-/}"
          v="${v%%-*}"
          echo "$(vers2int "${v}")_${v}"
        done
  ) )
  bash_qsort_numeric "${rubies_array[@]}"
  rubies_array_sorted=( ${bash_qsort_numeric_ret[@]} )
  rubies_array_len="${#rubies_array_sorted[@]}"
  i=$(( rubies_array_len - 1 ))
  selected_ruby="${rubies_array_sorted[${i}]}"
  selected_ruby="${selected_ruby##*_}"
  echo "${selected_ruby:-default}"
}

travis_assert() {
  local result=${1:-$?}
  if [ $result -ne 0 ]; then
    echo -e "\n${ANSI_RED}The command \"$TRAVIS_CMD\" failed and exited with $result during $TRAVIS_STAGE.${ANSI_RESET}\n\nYour build has been stopped."
    travis_terminate 2
  fi
}

travis_result() {
  local result=$1
  export TRAVIS_TEST_RESULT=$(( ${TRAVIS_TEST_RESULT:-0} | $(($result != 0)) ))

  if [ $result -eq 0 ]; then
    echo -e "\n${ANSI_GREEN}The command \"$TRAVIS_CMD\" exited with $result.${ANSI_RESET}"
  else
    echo -e "\n${ANSI_RED}The command \"$TRAVIS_CMD\" exited with $result.${ANSI_RESET}"
  fi
}

travis_terminate() {
  pkill -9 -P $$ &> /dev/null || true
  exit $1
}

travis_wait() {
  local timeout=$1

  if [[ $timeout =~ ^[0-9]+$ ]]; then
    
    shift
  else
    
    timeout=20
  fi

  local cmd="$@"
  local log_file=travis_wait_$$.log

  $cmd &>$log_file &
  local cmd_pid=$!

  travis_jigger $! $timeout $cmd &
  local jigger_pid=$!
  local result

  {
    wait $cmd_pid 2>/dev/null
    result=$?
    ps -p$jigger_pid &>/dev/null && kill $jigger_pid
  }

  if [ $result -eq 0 ]; then
    echo -e "\n${ANSI_GREEN}The command $cmd exited with $result.${ANSI_RESET}"
  else
    echo -e "\n${ANSI_RED}The command $cmd exited with $result.${ANSI_RESET}"
  fi

  echo -e "\n${ANSI_GREEN}Log:${ANSI_RESET}\n"
  cat $log_file

  return $result
}

travis_jigger() {
  
  local cmd_pid=$1
  shift
  local timeout=$1 
  shift
  local count=0

  
  echo -e "\n"

  while [ $count -lt $timeout ]; do
    count=$(($count + 1))
    echo -ne "Still running ($count of $timeout): $@\r"
    sleep 60
  done

  echo -e "\n${ANSI_RED}Timeout (${timeout} minutes) reached. Terminating \"$@\"${ANSI_RESET}\n"
  kill -9 $cmd_pid
}

travis_retry() {
  local result=0
  local count=1
  while [ $count -le 3 ]; do
    [ $result -ne 0 ] && {
      echo -e "\n${ANSI_RED}The command \"$@\" failed. Retrying, $count of 3.${ANSI_RESET}\n" >&2
    }
    "$@"
    result=$?
    [ $result -eq 0 ] && break
    count=$(($count + 1))
    sleep 1
  done

  [ $count -gt 3 ] && {
    echo -e "\n${ANSI_RED}The command \"$@\" failed 3 times.${ANSI_RESET}\n" >&2
  }

  return $result
}

travis_fold() {
  local action=$1
  local name=$2
  echo -en "travis_fold:${action}:${name}\r${ANSI_CLEAR}"
}

decrypt() {
  echo $1 | base64 -d | openssl rsautl -decrypt -inkey $HOME/.ssh/id_rsa.repo
}

vers2int() {
  printf '1%03d%03d%03d%03d' $(echo "$1" | tr '.' ' ')
}

bash_qsort_numeric() {
   local pivot i smaller=() larger=()
   bash_qsort_numeric_ret=()
   (($#==0)) && return 0
   pivot=${1}
   shift
   for i; do
      if [[ ${i%%_*} -lt ${pivot%%_*} ]]; then
         smaller+=( "$i" )
      else
         larger+=( "$i" )
      fi
   done
   bash_qsort_numeric "${smaller[@]}"
   smaller=( "${bash_qsort_numeric_ret[@]}" )
   bash_qsort_numeric "${larger[@]}"
   larger=( "${bash_qsort_numeric_ret[@]}" )
   bash_qsort_numeric_ret=( "${smaller[@]}" "$pivot" "${larger[@]}" )
}


if [[ -f /etc/apt/sources.list.d/rabbitmq-source.list ]] ; then
  sudo rm -f /etc/apt/sources.list.d/rabbitmq-source.list
fi

mkdir -p $HOME/build
cd       $HOME/build


travis_fold start system_info
  echo -e "\033[33;1mBuild system information\033[0m"
  echo -e "Build language: cpp"
  echo -e "Build id: ''"
  echo -e "Job id: ''"
  if [[ -f /usr/share/travis/system_info ]]; then
    cat /usr/share/travis/system_info
  fi
travis_fold end system_info

echo
export PATH=$(echo $PATH | sed -e 's/::/:/g')
export PATH=$(echo -n $PATH | perl -e 'print join(":", grep { not $seen{$_}++ } split(/:/, scalar <>))')
echo "options rotate
options timeout:1

nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 208.67.222.222
nameserver 208.67.220.220
" | sudo tee /etc/resolv.conf &> /dev/null
sudo sed -e 's/^\(127\.0\.0\.1.*\)$/\1 '`hostname`'/' -i'.bak' /etc/hosts
sudo sed -e 's/^\([0-9a-f:]\+\) localhost/\1/' -i'.bak' /etc/hosts
test -f /etc/mavenrc && sudo sed -e 's/M2_HOME=\(.\+\)$/M2_HOME=${M2_HOME:-\1}/' -i'.bak' /etc/mavenrc
if [ $(command -v sw_vers) ]; then
  echo "Fix WWDRCA Certificate"
  sudo security delete-certificate -Z 0950B6CD3D2F37EA246A1AAA20DFAADBD6FE1F75 /Library/Keychains/System.keychain
  wget -q https://developer.apple.com/certificationauthority/AppleWWDRCA.cer
  sudo security add-certificates -k /Library/Keychains/System.keychain AppleWWDRCA.cer
fi

grep '^127\.0\.0\.1' /etc/hosts | sed -e 's/^127\.0\.0\.1 \(.*\)/\1/g' | sed -e 's/localhost \(.*\)/\1/g' | tr "\n" " " > /tmp/hosts_127_0_0_1
sed '/^127\.0\.0\.1/d' /etc/hosts > /tmp/hosts_sans_127_0_0_1
cat /tmp/hosts_sans_127_0_0_1 | sudo tee /etc/hosts > /dev/null
echo -n "127.0.0.1 localhost " | sudo tee -a /etc/hosts > /dev/null
cat /tmp/hosts_127_0_0_1 | sudo tee -a /etc/hosts > /dev/null
# apply :home_paths
for path_entry in $HOME/.local/bin $HOME/bin ; do
  if [[ ${PATH%%:*} != $path_entry ]] ; then
    export PATH="$path_entry:$PATH"
  fi
done

if [ ! $(uname|grep Darwin) ]; then echo update_initramfs=no | sudo tee -a /etc/initramfs-tools/update-initramfs.conf > /dev/null; fi

if [[ "$(sw_vers -productVersion 2>/dev/null | cut -d . -f 2)" -lt 12 ]]; then
  mkdir -p $HOME/.ssh
  chmod 0700 $HOME/.ssh
  touch $HOME/.ssh/config
  echo -e "Host *
    UseRoaming no
  " | cat - $HOME/.ssh/config > $HOME/.ssh/config.tmp && mv $HOME/.ssh/config.tmp $HOME/.ssh/config
fi

function travis_debug() {
echo -e "\033[31;1mThe debug environment is not available. Please contact support.\033[0m"
false
}

if [[ $(command -v sw_vers) ]]; then
  travis_cmd rvm\ use --echo
fi

if [[ -L /usr/lib/jvm/java-8-oracle-amd64 ]]; then
  echo -e "Removing symlink /usr/lib/jvm/java-8-oracle-amd64"
  travis_cmd sudo\ rm\ -f\ /usr/lib/jvm/java-8-oracle-amd64 --echo
  if [[ -f $HOME/.jdk_switcher_rc ]]; then
    echo -e "Reload jdk_switcher"
    travis_cmd source\ \$HOME/.jdk_switcher_rc --echo
  fi
  if [[ -f /opt/jdk_switcher/jdk_switcher.sh ]]; then
    echo -e "Reload jdk_switcher"
    travis_cmd source\ /opt/jdk_switcher/jdk_switcher.sh --echo
  fi
fi

export GIT_ASKPASS=echo

travis_fold start git.checkout
  if [[ ! -d todbot/Blink1Control2/.git ]]; then
    travis_cmd git\ clone\ --depth\=50\ --branch\=\'\'\ git@github.com:todbot/Blink1Control2.git\ todbot/Blink1Control2 --assert --echo --retry --timing
  else
    travis_cmd git\ -C\ todbot/Blink1Control2\ fetch\ origin --assert --echo --retry --timing
    travis_cmd git\ -C\ todbot/Blink1Control2\ reset\ --hard --assert --echo
  fi
  travis_cmd cd\ todbot/Blink1Control2 --echo
  travis_cmd git\ checkout\ -qf\  --assert --echo
travis_fold end git.checkout

if [[ -f .gitmodules ]]; then
  travis_fold start git.submodule
    echo Host\ github.com'
    '\	StrictHostKeyChecking\ no'
    ' >> ~/.ssh/config
    travis_cmd git\ submodule\ update\ --init\ --recursive --assert --echo --retry --timing
  travis_fold end git.submodule
fi

rm -f ~/.ssh/source_rsa
export PS4=+
export TRAVIS=true
export CI=true
export CONTINUOUS_INTEGRATION=true
export PAGER=cat
export HAS_JOSH_K_SEAL_OF_APPROVAL=true
export TRAVIS_EVENT_TYPE=''
export TRAVIS_PULL_REQUEST=false
export TRAVIS_SECURE_ENV_VARS=false
export TRAVIS_BUILD_ID=''
export TRAVIS_BUILD_NUMBER=''
export TRAVIS_BUILD_DIR=$HOME/build/todbot/Blink1Control2
export TRAVIS_JOB_ID=''
export TRAVIS_JOB_NUMBER=''
export TRAVIS_BRANCH=''
export TRAVIS_COMMIT=''
export TRAVIS_COMMIT_RANGE=''
export TRAVIS_REPO_SLUG=todbot/Blink1Control2
export TRAVIS_OS_NAME=linux
export TRAVIS_LANGUAGE=cpp
export TRAVIS_TAG=''
export TRAVIS_SUDO=true
export TRAVIS_PULL_REQUEST_BRANCH=''
export TRAVIS_PULL_REQUEST_SHA=''
export TRAVIS_PULL_REQUEST_SLUG=''
travis_cmd export\ CXX\=g\+\+ --echo
travis_cmd export\ CC\=gcc --echo

travis_fold start cache.1
  echo -e "Setting up build cache"
  rvm use $(rvm current >&/dev/null) >&/dev/null
  travis_cmd export\ CASHER_DIR\=\$HOME/.casher --echo
  mkdir -p $CASHER_DIR/bin
  travis_cmd curl\ https://raw.githubusercontent.com/travis-ci/casher/production/bin/casher\ \ -L\ -o\ \$CASHER_DIR/bin/casher\ -s\ --fail --assert --echo --display Installing\ caching\ utilities --retry --timing
  [ $? -ne 0 ] && echo 'Failed to fetch casher from GitHub, disabling cache.' && echo > $CASHER_DIR/bin/casher
  if [[ -f $CASHER_DIR/bin/casher ]]; then
    chmod +x $CASHER_DIR/bin/casher
  fi
  if [[ $- = *e* ]]; then
    ERREXIT_SET=true
  fi
  set +e
  if [[ -f $CASHER_DIR/bin/casher ]]; then
    travis_cmd type\ rvm\ \&\>/dev/null\ \|\|\ source\ \~/.rvm/scripts/rvm --timing
    travis_cmd rvm\ \$\(travis_internal_ruby\)\ --fuzzy\ do\ \$CASHER_DIR/bin/casher\ fetch\ https://s3.amazonaws.com/cache_bucket/1234567890//cache-linux-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855--compiler-gpp.tgz\\\?X-Amz-Algorithm\\\=AWS4-HMAC-SHA256\\\&X-Amz-Credential\\\=abcdef0123456789\\\%2F20170119\\\%2Fus-east-1\\\%2Fs3\\\%2Faws4_request\\\&X-Amz-Date\\\=20170119T201021Z\\\&X-Amz-Expires\\\=60\\\&X-Amz-Signature\\\=2f93882a55d6d460e75afce404c0f291bbd40b0448e0bc7b4da09a8db6eda864\\\&X-Amz-SignedHeaders\\\=host\ https://s3.amazonaws.com/cache_bucket/1234567890//cache--compiler-gpp.tgz\\\?X-Amz-Algorithm\\\=AWS4-HMAC-SHA256\\\&X-Amz-Credential\\\=abcdef0123456789\\\%2F20170119\\\%2Fus-east-1\\\%2Fs3\\\%2Faws4_request\\\&X-Amz-Date\\\=20170119T201021Z\\\&X-Amz-Expires\\\=60\\\&X-Amz-Signature\\\=ca8e369f79bbc2b19a27f53950bf382e038adb3bd0b52c95b6624762f366d1d5\\\&X-Amz-SignedHeaders\\\=host\ https://s3.amazonaws.com/cache_bucket/1234567890/cache-linux-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855--compiler-gpp.tgz\\\?X-Amz-Algorithm\\\=AWS4-HMAC-SHA256\\\&X-Amz-Credential\\\=abcdef0123456789\\\%2F20170119\\\%2Fus-east-1\\\%2Fs3\\\%2Faws4_request\\\&X-Amz-Date\\\=20170119T201021Z\\\&X-Amz-Expires\\\=60\\\&X-Amz-Signature\\\=caabd88d28a8c41ca211ff827f645573e4d88e0f78fcc24a7709d0074f5fa316\\\&X-Amz-SignedHeaders\\\=host\ https://s3.amazonaws.com/cache_bucket/1234567890/cache--compiler-gpp.tgz\\\?X-Amz-Algorithm\\\=AWS4-HMAC-SHA256\\\&X-Amz-Credential\\\=abcdef0123456789\\\%2F20170119\\\%2Fus-east-1\\\%2Fs3\\\%2Faws4_request\\\&X-Amz-Date\\\=20170119T201021Z\\\&X-Amz-Expires\\\=60\\\&X-Amz-Signature\\\=9fe12e34980c22a9b780401183f994825e44c4deff6415cd95d3c7e40c91fcbe\\\&X-Amz-SignedHeaders\\\=host --timing
  fi
  if [[ -n $ERREXIT_SET ]]; then
    set -e
  fi
  if [[ $- = *e* ]]; then
    ERREXIT_SET=true
  fi
  set +e
  if [[ -f $CASHER_DIR/bin/casher ]]; then
    travis_cmd type\ rvm\ \&\>/dev/null\ \|\|\ source\ \~/.rvm/scripts/rvm --timing
    travis_cmd rvm\ \$\(travis_internal_ruby\)\ --fuzzy\ do\ \$CASHER_DIR/bin/casher\ add\ node_modules\ app/node_modules\ \$HOME/.electron\ \$HOME/.cache --timing
  fi
  if [[ -n $ERREXIT_SET ]]; then
    set -e
  fi
travis_fold end cache.1

travis_cmd g\+\+\ --version --echo

travis_fold start before_install.1
  travis_cmd rvm\ get\ head --assert --echo --timing
travis_fold end before_install.1

travis_fold start before_install.2
  travis_cmd rm\ -rf\ \~/.nvm\ \&\&\ git\ clone\ https://github.com/creationix/nvm.git\ \~/.nvm\ \&\&\ \(cd\ \~/.nvm\ \&\&\ git\ checkout\ \`git\ describe\ --abbrev\=0\ --tags\`\)\ \&\&\ source\ \~/.nvm/nvm.sh --assert --echo --timing
travis_fold end before_install.2

travis_fold start before_install.3
  travis_cmd nvm\ install\ \$TRAVIS_NODE_VERSION --assert --echo --timing
travis_fold end before_install.3

travis_fold start before_install.4
  travis_cmd PATH\=\$PATH:\`pwd\`/node_modules/.bin --assert --echo --timing
travis_fold end before_install.4

travis_fold start before_install.5
  travis_cmd BASE_URL\=\$\(node\ -p\ \"\'https://nodejs.org/dist/\'\ \+\ process.version\"\) --assert --echo --timing
travis_fold end before_install.5

travis_fold start before_install.6
  travis_cmd X86_FILE\=\$\(node\ -p\ \"\'node-\'\ \+\ process.version\ \+\ \'-\'\ \+\ process.platform\ \+\ \'-x86\'\"\) --assert --echo --timing
travis_fold end before_install.6

travis_fold start before_install.7
  travis_cmd if\ \[\[\ \"\$ARCH\"\ \=\=\ \"x86\"\ \]\]\;\ then\ wget\ \$BASE_URL/\$X86_FILE.tar.gz\;\ tar\ -xf\ \$X86_FILE.tar.gz\;\ export\ PATH\=\$X86_FILE/bin:\$PATH\;\ fi --assert --echo --timing
travis_fold end before_install.7

travis_fold start before_install.8
  travis_cmd uname\ -a --assert --echo --timing
travis_fold end before_install.8

travis_fold start before_install.9
  travis_cmd file\ \`which\ node\` --assert --echo --timing
travis_fold end before_install.9

travis_fold start before_install.10
  travis_cmd node\ --version --assert --echo --timing
travis_fold end before_install.10

travis_fold start before_install.11
  travis_cmd node\ -p\ \'process.platform\ \+\ \"@\"\ \+\ process.arch\' --assert --echo --timing
travis_fold end before_install.11

travis_fold start before_install.12
  travis_cmd npm\ --version --assert --echo --timing
travis_fold end before_install.12

travis_fold start before_install.13
  travis_cmd if\ \[\[\ \$TRAVIS_OS_NAME\ \=\=\ \"linux\"\ \]\]\;\ then\ export\ CXX\=g\+\+-4.8\;\ fi --assert --echo --timing
travis_fold end before_install.13

travis_fold start before_install.14
  travis_cmd \$CXX\ --version --assert --echo --timing
travis_fold end before_install.14

travis_fold start before_install.15
  travis_cmd PUBLISH_BINARY\=false --assert --echo --timing
travis_fold end before_install.15

travis_fold start before_install.16
  travis_cmd echo\ \$TRAVIS_BRANCH --assert --echo --timing
travis_fold end before_install.16

travis_fold start before_install.17
  travis_cmd echo\ \`git\ describe\ --tags\ --always\ HEAD\` --assert --echo --timing
travis_fold end before_install.17

travis_fold start before_install.18
  travis_cmd if\ \[\[\ \$TRAVIS_BRANCH\ \=\=\ \`git\ describe\ --tags\ --always\ HEAD\`\ \]\]\;\ then\ PUBLISH_BINARY\=true\;\ fi\; --assert --echo --timing
travis_fold end before_install.18

travis_fold start before_install.19
  travis_cmd echo\ \"Publishing\ native\ platform\ Binary\ Package\?\ -\>\"\ \$PUBLISH_BINARY --assert --echo --timing
travis_fold end before_install.19

travis_fold start before_install.20
  travis_cmd npm\ config\ set\ progress\ false --assert --echo --timing
travis_fold end before_install.20

travis_fold start before_install.21
  travis_cmd npm\ config\ set\ spin\ false --assert --echo --timing
travis_fold end before_install.21

travis_fold start install.1
  travis_cmd npm\ install --assert --echo --timing
travis_fold end install.1

travis_fold start install.2
  travis_cmd npm\ run\ postinstall --assert --echo --timing
travis_fold end install.2

travis_cmd npm\ run\ webpack --echo --timing
travis_result $?
travis_cmd npm\ run\ dist --echo --timing
travis_result $?
travis_cmd echo\ \"\*\*\*\ done.\ debug\ begin\ \*\*\*\" --echo --timing
travis_result $?
travis_cmd env\ \|\ sort --echo --timing
travis_result $?
travis_cmd ls\ -al\ dist/mac --echo --timing
travis_result $?
travis_cmd echo\ \"\*\*\*\ done.\ debug\ end\ \*\*\*\" --echo --timing
travis_result $?

travis_fold start cache.2
  echo -e "store build cache"
  if [[ $- = *e* ]]; then
    ERREXIT_SET=true
  fi
  set +e
  if [[ -n $ERREXIT_SET ]]; then
    set -e
  fi
  if [[ $- = *e* ]]; then
    ERREXIT_SET=true
  fi
  set +e
  if [[ -f $CASHER_DIR/bin/casher ]]; then
    travis_cmd type\ rvm\ \&\>/dev/null\ \|\|\ source\ \~/.rvm/scripts/rvm --timing
    travis_cmd rvm\ \$\(travis_internal_ruby\)\ --fuzzy\ do\ \$CASHER_DIR/bin/casher\ push\ https://s3.amazonaws.com/cache_bucket/1234567890//cache-linux-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855--compiler-gpp.tgz\\\?X-Amz-Algorithm\\\=AWS4-HMAC-SHA256\\\&X-Amz-Credential\\\=abcdef0123456789\\\%2F20170119\\\%2Fus-east-1\\\%2Fs3\\\%2Faws4_request\\\&X-Amz-Date\\\=20170119T201021Z\\\&X-Amz-Expires\\\=60\\\&X-Amz-Signature\\\=217ddbfa117684ce06c38b26ac9fbcb4c1434a3ef07d616ff033e9edee268a6a\\\&X-Amz-SignedHeaders\\\=host --timing
  fi
  if [[ -n $ERREXIT_SET ]]; then
    set -e
  fi
travis_fold end cache.2

if [[ $TRAVIS_TEST_RESULT = 0 ]]; then
  if [[ ($TRAVIS_REPO_SLUG = "todbot/Blink1Control2") && ("$TRAVIS_TAG" != "") ]]; then
    if [[ $- = *e* ]]; then
      ERREXIT_SET=true
    fi
    set +e
    travis_fold start before_deploy.1
      travis_cmd if\ \[\[\ \"\$TRAVIS_OS_NAME\"\ \=\=\ \"osx\"\ \]\]\;\ \ \ then\ export\ DFILE1\=\$\(ls\ dist/mac/Blink1Control2\*.dmg\)\;\ fi --assert --echo --timing
    travis_fold end before_deploy.1
    travis_fold start before_deploy.2
      travis_cmd if\ \[\[\ \"\$TRAVIS_OS_NAME\"\ \=\=\ \"osx\"\ \]\]\;\ \ \ then\ export\ DFILE2\=\$\(ls\ dist/mac/Blink1Control2\*.zip\)\;\ fi --assert --echo --timing
    travis_fold end before_deploy.2
    travis_fold start before_deploy.3
      travis_cmd if\ \[\[\ \"\$TRAVIS_OS_NAME\"\ \=\=\ \"linux\"\ \]\]\;\ then\ export\ DFILE1\=\$\(ls\ dist/linux/Blink1Control2\*.zip\)\;\ fi --assert --echo --timing
    travis_fold end before_deploy.3
    travis_fold start dpl.0
      type rvm &>/dev/null || source ~/.rvm/scripts/rvm
      travis_cmd rvm\ \$\(travis_internal_ruby\)\ --fuzzy\ do\ ruby\ -S\ gem\ install\ dpl --assert --timing
      rm -f dpl-*.gem
    travis_fold end dpl.0
    type rvm &>/dev/null || source ~/.rvm/scripts/rvm
    travis_cmd rvm\ \$\(travis_internal_ruby\)\ --fuzzy\ do\ ruby\ -S\ dpl\ --skip_cleanup\ --provider\=\"releases\"\ --file\=\"\$\{RELEASE_FILE1\}\"\ --file\=\"\$\{RELEASE_FILE2\}\"\ --fold\;\ if\ \[\ \$\?\ -ne\ 0\ \]\;\ then\ echo\ \"failed\ to\ deploy\"\;\ travis_terminate\ 2\;\ fi --timing
    if [[ -n $ERREXIT_SET ]]; then
      set -e
    fi
  else
    if [[  ! $TRAVIS_REPO_SLUG = "todbot/Blink1Control2" ]]; then
      echo -e "\033[33;1mSkipping a deployment with the releases provider because this repo's name does not match one specified in .travis.yml's deploy.on.repo: todbot/Blink1Control2\033[0m"
    fi
    if [[  ! "$TRAVIS_TAG" != "" ]]; then
      echo -e "\033[33;1mSkipping a deployment with the releases provider because this is not a tagged commit\033[0m"
    fi
  fi
fi

echo -e "\nDone. Your build exited with $TRAVIS_TEST_RESULT."

travis_terminate $TRAVIS_TEST_RESULT
