Last active
August 29, 2015 14:16
-
-
Save andrewfritz86/5a225c9aec3faee52d1c to your computer and use it in GitHub Desktop.
Grab SSH keys so we can use WDI submit gem
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
#!/usr/bin/env bash | |
echo "" | |
echo "If you haven't already, please sign up for a github account" | |
#read to capture user input, saved as a variable as the third argument here | |
read -p "First Name: " fname | |
read -p "Last Name: " lname | |
read -p "Github Username (CASE SENSITIVE AND DON'T CHANGE THIS LATER): " github_name | |
read -p "Github Email: " github_email | |
read -s -p "Github Password: " github_password | |
echo "please confirm that your github username and email are correct. you entered the email: $github_email and the username: $github_name. Is this right? enter 'y' or 'n' " | |
read -p "y/n" answer | |
if [ $answer == "y" ] ; then | |
echo "great!" | |
echo "Generate an SSH key. We can use this to quickly authenticate your computer with github and not have to enter your password all over the place. When you see the prompt 'Enter a file in which to save the key', just press Enter! Your passphrase can be anything that's memorable." | |
#from GH docs, pass GH email captured earlier. | |
ssh-keygen -t rsa -C $github_email | |
#start ssh-agent if it's not running (TODO maybe take this out) | |
eval "$(ssh-agent -s)" | |
#add the key | |
ssh-add ~/.ssh/id_rsa | |
#set another variable called public key | |
public_key=$(cat ~/.ssh/id_rsa.pub) | |
# Upload to github | |
# -H flag for headers, -d for data, like form data (body of a post request), -u to specify user and password for server auth | |
curl https://api.github.com/user/keys \ | |
-H "User-Agent: WDI Installfest" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
-u "$github_name:$github_password" \ | |
-d '{"title":"WDI", "key":"'"$public_key"'"}' | |
git config --global user.name "$fname $lname" | |
git config --global user.email "$github_email" | |
git config --global user.username "$github_name" | |
echo "" | |
echo "All set! Thanks!" | |
else | |
echo "got it. re-run the script, lol!" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment