<commit_before>#!/bin/bash -ev

function cleanup_keyfiles {
  find /tmp/ -maxdepth 1 -name keys* -type f -exec shred -f {} \;
}
trap cleanup_keyfiles EXIT

function preset_passphrase {
  echo 'Calling gpg-preset-passphrase'
  set +x
  echo $GPG_PASSPHRASE | /usr/lib/gnupg2/gpg-preset-passphrase --preset $GPG_KEYGRIP
  echo $GPG_PASSPHRASE | /usr/lib/gnupg2/gpg-preset-passphrase --preset $GPG_SIGN_KEYGRIP
  set -x
  echo 'done'
}

function import_gpg_keys () {
  from_dir=$1
  gpg --status-fd 2 --import $from_dir/key.secret.asc
  gpg --status-fd 2 --import-ownertrust < $from_dir/trust.asc
}

rm -f ~/.gnupg/options ~/.gnupg/gpg.conf

if [ "$TRAVIS_SECURE_ENV_VARS" == 'true' ]; then
  set +x
  echo "SECRETS are available, fetching reahl GPG signing key"
  gpg --keyserver $GPG_KEYSERVER --recv $GPG_KEY_ID
  pip install awscli
  aws s3 cp s3://$AWS_BUCKET/keys.tgz.enc /tmp/keys.tgz.enc
  openssl aes-256-cbc -K $encrypted_f7a01544e957_key -iv $encrypted_f7a01544e957_iv -in /tmp/keys.tgz.enc -out /tmp/keys.tgz -d
  tar -C /tmp -zxvf /tmp/keys.tgz 
  ps aux | grep gpg
  mkdir -p ~/.gnupg
#  echo "allow-loopback-pinentry" >> ~/.gnupg/gpg-agent.conf
  echo "allow-preset-passphrase" >> ~/.gnupg/gpg-agent.conf
  echo "use-agent" >> ~/.gnupg/gpg.conf
  gpgconf --reload gpg-agent
  gpg-connect-agent reloadagent /bye
  sleep 2
  ps aux | grep gpg
  preset_passphrase
  ls ~/.gnupg
  cat ~/.gnupg/*.conf
  import_gpg_keys /tmp/keys
  mkdir -p ~/.gnupg
  echo "default-key $GPG_KEY_ID" >> ~/.gnupg/gpg.conf
else
  echo "SECRETS NOT available, using fake key for signing"
fi

import_gpg_keys travis/keys  # We import these anyways for use by tests that sign stuff
<commit_msg>configure gpg and preset passphrase correctly<commit_after>#!/bin/bash -ev

function cleanup_keyfiles {
  find /tmp/ -maxdepth 1 -name keys* -type f -exec shred -f {} \;
}
trap cleanup_keyfiles EXIT

function configure_gnupg {
  mkdir -p ~/.gnupg
  echo "allow-preset-passphrase" >> ~/.gnupg/gpg-agent.conf
  echo "use-agent" >> ~/.gnupg/gpg.conf
  gpgconf --reload gpg-agent
#  gpg-connect-agent reloadagent /bye
}

function preset_passphrase {
  /usr/lib/gnupg2/gpg-preset-passphrase --preset $GPG_KEYGRIP <<< $GPG_PASSPHRASE
}

function import_gpg_keys () {
  from_dir=$1
  gpg --status-fd 2 --import $from_dir/key.secret.asc
  gpg --status-fd 2 --import-ownertrust < $from_dir/trust.asc
}

rm -f ~/.gnupg/options ~/.gnupg/gpg.conf

configure_gnupg

if [ "$TRAVIS_SECURE_ENV_VARS" == 'true' ]; then
  echo "SECRETS are available, fetching reahl GPG signing key"
  gpg --keyserver $GPG_KEYSERVER --recv $GPG_KEY_ID
  pip install awscli
  aws s3 cp s3://$AWS_BUCKET/keys.tgz.enc /tmp/keys.tgz.enc
  set +x
  openssl aes-256-cbc -K $encrypted_f7a01544e957_key -iv $encrypted_f7a01544e957_iv -in /tmp/keys.tgz.enc -out /tmp/keys.tgz -d
  set -x
  tar -C /tmp -zxvf /tmp/keys.tgz 
  preset_passphrase
  import_gpg_keys /tmp/keys
  echo "default-key $GPG_KEY_ID" >> ~/.gnupg/gpg.conf
else
  echo "SECRETS NOT available, using fake key for signing"
fi

import_gpg_keys travis/keys  # We import these anyways for use by tests that sign stuff

{'fraction_non_alphanumeric': 0.12804878048780488, 'fraction_numerical': 0.018613607188703467, 'mean_word_length': 3.3533519553072626, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7361315', 'n_tokens_mistral': 1334, 'n_tokens_neox': 1284, 'n_words': 307}