Skip to content

Instantly share code, notes, and snippets.

@wavejumper
Last active August 29, 2015 14:02
Show Gist options
  • Save wavejumper/95032a0d8a7565637782 to your computer and use it in GitHub Desktop.
Save wavejumper/95032a0d8a7565637782 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Modified from https://gist.github.com/douglasduteil/5525750#file-travis-secure-key-sh
#
# If you need:
# ssh-keygen -t rsa -C "travis" -f ~/.ssh/travis_rsa
#
# Example usage: ./travis-encrypt-key.sh ~/.ssh/travis-rsa
# Run in same directory as your .travis.yml file
SSH_KEY=$1
base64 --wrap=0 $SSH_KEY > travis_rsa_64
cat travis_rsa_64 | perl -pe 's/(.{100})/$1\n/g' | nl | perl -pe 's/\s*(\d+)\s*(.*)/travis encrypt id_rsa_$1="$2" --add env.global/' | while read line; do
eval $line
done
COUNT=$(cat travis_rsa_64 | perl -pe 's/(.{100})/$1\n/g' | nl | wc -l)
rm travis_rsa_64
echo -e "Add to before_script:"
echo -e "\t- echo -n \$id_rsa_{1..$COUNT} >> ~/.ssh/travis_rsa_64"
echo -e "\t- base64 --decode --ignore-garbage ~/.ssh/travis_rsa_64 > ~/.ssh/id_rsa"
echo -e "\t- chmod 600 ~/.ssh/id_rsa"
echo -e "\t- echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment