Forked from floydpink/travis-secure-key-mac.sh
Last active
September 7, 2016 14:43
-
-
Save scribu/6241271 to your computer and use it in GitHub Desktop.
Generating secure environment variables for GitHub deployment keys to be used from a Travis-CI build.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# On OS X, use this script to generate an encrypted deployment key for Travis CI. | |
# Dependencies: | |
# gem install travis | |
# brew install coreutils | |
if [ $# -lt 1 ]; then | |
echo "usage: $0 <user>/<repo>" | |
exit 1 | |
fi | |
REPO=$1 | |
KEY_DIR=/tmp/travis-deploy-key | |
mkdir -p $KEY_DIR | |
echo "Generating key pair..." | |
ssh-keygen -q -f $KEY_DIR/id_rsa -P '' | |
echo "Encrypting private key..." | |
base64 --break=0 $KEY_DIR/id_rsa > $KEY_DIR/id_rsa_base64 | |
ENCRYPTION_FILTER="echo \$(echo \"- secure: \")\$(travis encrypt \"\$FILE='\`cat $FILE\`'\" -r $REPO)" | |
gsplit --bytes=100 --numeric-suffixes --suffix-length=2 --filter="$ENCRYPTION_FILTER" $KEY_DIR/id_rsa_base64 id_rsa_ | |
echo | |
echo "1. Add the above lines to your .travis.yml file." | |
echo "2. Call read-key.sh from your .travis.yml file." | |
echo "3. Add $KEY_DIR/id_rsa.pub as a deploy key to the destination Github repo." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To reconstitute the private SSH key from within the Travis-CI build (typically from 'before_script') | |
echo -n $id_rsa_{00..30} >> ~/.ssh/id_rsa_base64 | |
base64 --decode --ignore-garbage ~/.ssh/id_rsa_base64 > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
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
Used for http://github.com/wp-cli/wp-cli