-
-
Save dacbarbos/e391b6df600008bbc41759b1a4775972 to your computer and use it in GitHub Desktop.
Create a private key-pair and encrypt it for use in .travis.yml with working code for decrypting it on both Linux and macOS builders
This file contains 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
#!/bin/env bash | |
ssh-keygen -t rsa -N "" -C travis -f ./travis_key | |
# tested on Linux only (according the author) | |
# on macOS you'll need gsplit instead of split | |
# decryption should work on both Linux and macOS travis-workers | |
# official doc/help page https://docs.travis-ci.com/user/encryption-keys | |
# see also http://stackoverflow.com/questions/18027115/committing-via-travis-ci-failing | |
echo "encrypt private" | |
base64 --wrap=0 ./travis_key > ./travis_key_base64 | |
ENCRYPTION_FILTER="echo \$(echo \" - secure: \")\$(travis encrypt \"\$FILE='\`cat $FILE\`'\" -r koter84/tg)" | |
split --bytes=100 --numeric-suffixes --suffix-length=2 --filter="$ENCRYPTION_FILTER" ./travis_key_base64 id_rsa_ | |
echo "encrypt public" | |
base64 --wrap=0 ./travis_key.pub > ./travis_key_base64.pub | |
ENCRYPTION_FILTER="echo \$(echo \" - secure: \")\$(travis encrypt \"\$FILE='\`cat $FILE\`'\" -r koter84/tg)" | |
split --bytes=100 --numeric-suffixes --suffix-length=2 --filter="$ENCRYPTION_FILTER" ./travis_key_base64.pub id_rsa_pub_ | |
## The parts below go in the .travis.yml file, and work on Linux and macOS hosts | |
- echo "decrypt private" | |
- for i in {0..30}; do eval $(printf "echo \$id_rsa_%02d\n" $i) >> ~/.ssh/id_rsa_base64; done | |
- base64 --decode ~/.ssh/id_rsa_base64 > ~/.ssh/id_rsa | |
- chmod 600 ~/.ssh/id_rsa | |
- echo "decrypt public" | |
- for i in {0..10}; do eval $(printf "echo \$id_rsa_pub_%02d\n" $i) >> ~/.ssh/id_rsa_base64.pub; done | |
- base64 --decode ~/.ssh/id_rsa_base64.pub > ~/.ssh/id_rsa.pub | |
- chmod 600 ~/.ssh/id_rsa.pub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment