Skip to content

Instantly share code, notes, and snippets.

@alexyorke
Created January 29, 2020 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexyorke/67fcc1b58722ed379f9e3e221ffad9c2 to your computer and use it in GitHub Desktop.
Save alexyorke/67fcc1b58722ed379f9e3e221ffad9c2 to your computer and use it in GitHub Desktop.
#!/bin/sh
MINGW=true
REPO_NAME="Orbital"
ORG_NAME="focisolutions"
if [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
if ! [ -x "$(command -v xclip)" ]; then
echo 'Please install xclip via apt install xclip' >&2
exit 1
fi
MINGW=false
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ] || [ "$(expr substr $(uname -s) 1 10)" == "MINGW64_NT" ]; then
MINGW=true
fi
mkdir -p ~/.ssh
cd ~ || return
yes | ssh-keygen -b 2048 -t rsa -f ~/.ssh/id_rsa -q -N "" >/dev/null
if [ $MINGW ]; then
cat ~/.ssh/id_rsa.pub > /dev/clipboard
else
xclip -se c < ~/.ssh/id_rsa.pub
fi
read -p "The public key has been copied to your clipboard. Please go to https://dev.azure.com/$ORG_NAME/_usersSettings/keys , press Add, and paste it in there. Then click save. When you are done, press enter"
echo "Verifying that the key was added successfully..."
sleep 2
yes | git clone -q git@ssh.dev.azure.com:v3/$ORG_NAME/$REPO_NAME/$REPO_NAME
if [ $? -eq 0 ]; then
echo "Key added successfully! You can now clone the repo on this machine via: git clone git@ssh.dev.azure.com:v3/$ORG_NAME/$REPO_NAME/$REPO_NAME"
else
echo FAIL
return
fi
if [ $MINGW ]; then
cat ~/.ssh/id_rsa.pub > /dev/clipboard
else
xclip -se c < ~/.ssh/id_rsa.pub
fi
read -p "Now lets get the CI set up. I've copied the public key to the clipboard again. Go to Azure Keyvault and paste in that key into a safe place so that bash can get the contents of that variable again. Press enter to continue."
if [ $MINGW ]; then
cat ~/.ssh/id_rsa > /dev/clipboard
else
xclip -se c < ~/.ssh/id_rsa
fi
read -p "Almost done. I've copied the *private* key to the clipboard. Go to Azure Keyvault, call it private key, and press enter to continue."
echo "Now, just make a bash script to read from the public key variable that you set in Azure, and send it to this path: ~/.ssh/id_rsa.pub"
echo "Now, just make a bash script to read from the *private* key variable that you set in Azure, and send it to this path: ~/.ssh/id_rsa"
echo "Next line in that script should be: yes | git clone git@ssh.dev.azure.com:v3/$ORG_NAME/$REPO_NAME/$REPO_NAME"
echo "And you're all set!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment