#!/usr/bin/env bash
set -o errexit

INSTANCE_METADATA_URL="http://metadata.google.internal/computeMetadata/v1/instance"
INSTANCE_HOSTNAME=$(curl -s "$INSTANCE_METADATA_URL/hostname" -H "Metadata-Flavor: Google")

SSH_PASSPHRASE=$(dd if=/dev/urandom bs=1 count=32 2>/dev/null | base64)
ssh-keygen \
  -f /var/tmp/gce_rsa \
  -t rsa \
  -b 4096 \
  -C "travis-worker@$INSTANCE_HOSTNAME" \
  -N "$SSH_PASSPHRASE"

cat > /var/tmp/gce.json <<EOF

___GCE_JSON___

EOF

cat > /etc/default/travis-worker <<EOF
___ENV___

export TRAVIS_WORKER_GCE_ACCOUNT_JSON=/var/tmp/gce.json
export TRAVIS_WORKER_GCE_SSH_KEY_PASSPHRASE=$SSH_PASSPHRASE
export TRAVIS_WORKER_GCE_KEY_PATH=/var/tmp/gce_rsa
export TRAVIS_WORKER_GCE_PUB_KEY_PATH=/var/tmp/gce_rsa.pub
export TRAVIS_WORKER_LIBRATO_SOURCE=worker-___SITE___-___ENVIRONMENT___-gce-${count}

EOF

chown travis:travis /etc/default/travis-worker
chmod 0640 /etc/default/travis-worker

stop travis-worker || true
start travis-worker || true

#!/usr/bin/env bash
set -o errexit

INSTANCE_METADATA_URL="http://metadata.google.internal/computeMetadata/v1/instance"
INSTANCE_HOSTNAME=$(curl -s "$INSTANCE_METADATA_URL/hostname" -H "Metadata-Flavor: Google")

SSH_PASSPHRASE=$(dd if=/dev/urandom bs=1 count=32 2>/dev/null | base64)
ssh-keygen \
  -f /var/tmp/gce_rsa \
  -t rsa \
  -b 4096 \
  -C "travis-worker@$INSTANCE_HOSTNAME" \
  -N "$SSH_PASSPHRASE"

cat > /var/tmp/gce.json <<EOF

___GCE_JSON___

EOF

cat > /etc/default/travis-worker <<EOF
___ENV___

export TRAVIS_WORKER_GCE_ACCOUNT_JSON=/var/tmp/gce.json
export TRAVIS_WORKER_GCE_SSH_KEY_PASSPHRASE=$SSH_PASSPHRASE
export TRAVIS_WORKER_GCE_KEY_PATH=/var/tmp/gce_rsa
export TRAVIS_WORKER_GCE_PUB_KEY_PATH=/var/tmp/gce_rsa.pub
export TRAVIS_WORKER_LIBRATO_SOURCE=worker-___SITE___-___ENVIRONMENT___-gce-${number}

EOF

chown travis:travis /etc/default/travis-worker
chmod 0640 /etc/default/travis-worker

stop travis-worker || true
start travis-worker || true

Switch to correct terraform var
Switch to correct terraform var
