Last active
August 29, 2015 14:02
-
-
Save kaizhu256/f3db4d203675bbd304e0 to your computer and use it in GitHub Desktop.
travis encrypt secrets using shell commands
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/sh | |
function shTravisEncrypt () { | |
## this shell function travis encrypts the secret $2 for github repo $1 | |
## tested to work on linux and osx (mountain lion) | |
local GITHUB_REPO="$1" | |
local SECRET="$2" | |
printf "fetching public rsa key from https://api.travis-ci.org/repos/$GITHUB_REPO/key ...\n" | |
curl -3Ls https://api.travis-ci.org/repos/$GITHUB_REPO/key\ | |
| perl -ne 's/[^-]*//; s/"[^"]*$//; s/\\n/\n/g; s/ RSA / /g; print'\ | |
> /tmp/id_rsa.pub | |
printf "encrypting value with fetched public rsa key ...\n" | |
printf "$SECRET"\ | |
| openssl rsautl -encrypt -pubin -inkey /tmp/id_rsa.pub\ | |
| base64\ | |
| tr -d "\n" | |
printf "\n" | |
} | |
# usage example | |
# $ source travis-encrypt.sh | |
# $ shTravisEncrypt kaizhu256/utility2 "SECRET=open-sesame" | |
# fetching public rsa key from https://api.travis-ci.org/repos/kaizhu256/utility2/key ... | |
# encrypting value with fetched public rsa key ... | |
# AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment