Last active
August 29, 2015 14:19
-
-
Save utamas/07d0c27f92e4f0888b44 to your computer and use it in GitHub Desktop.
Add private key to your git account.
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/bash -e | |
################################################################################ | |
# To use this script copy and paste the following line without the "#" character | |
# into a "git bash" - installed by msysgit (http://msysgit.github.io/) | |
################################################################################ | |
# curl -sLo add-key.sh http://epa.ms/gitkey && chmod u+x add-key.sh && ./add-key.sh | |
################################################################################ | |
url="https://git.epam.com" | |
if [ ! -z "$1" ] ; then | |
url="$1" | |
fi | |
read -p "What is your git TOKEN (copy paste from $url/profile/account)?" TOKEN | |
if [ ${#TOKEN} -ne 20 ] ; then | |
echo | |
echo "[ERROR] your private token should be 20 characters long" | |
echo "run this script again, and make sure that you use the token from:" | |
echo " $url/profile/account" | |
exit -1 | |
fi | |
if [ -f ~/.ssh/id_rsa.pub ] ; then | |
echo "your existing public key will be used: ~/.ssh/id_rsa.pub" | |
echo " fingerprint of public key:" | |
ssh-keygen -lf ~/.ssh/id_rsa.pub | |
else | |
echo "public/private ssh keypair will be generated ..." | |
ssh-keygen -q -t rsa -f ~/.ssh/id_rsa -N "" | |
fi | |
echo '{' \"title\":\"private-key\", \"key\":\"$(cat ~/.ssh/id_rsa.pub)\" '}' | curl -H "Accept: application/json" -H "Content-type: application/json" --data @- "$url/api/v3/user/keys?private_token=$TOKEN" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment