Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save edipofederle/b6a6f9354d0cfdfb0eca to your computer and use it in GitHub Desktop.
Save edipofederle/b6a6f9354d0cfdfb0eca to your computer and use it in GitHub Desktop.
#!/bin/bash
ssh-keygen -t rsa -N "" -C travis -f ./travis_key
# i only tested the encrypting on Linux.
# on mac you need gsplit instead of split, but the rest should be mostly the same
#
# decryption works on both linux and mac travis-workers
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 osx 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