Created
March 19, 2018 06:28
-
-
Save lukedesu/8db6440b028e409106b34cb47f668c22 to your computer and use it in GitHub Desktop.
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 | |
read -r -d '' usage << EOM | |
Usage: | |
gh-deploy-clone user/repo [ENVIRONMENT] | |
EOM | |
[ -z "$1" ] && echo && echo "$usage" && echo && exit 1 | |
repo="$1" | |
repo_name="${repo#*/}" | |
env=$([ -n "$2" ] && echo "$2_" || echo) | |
key="github_$env$repo_name" | |
key_path="$HOME/.ssh/$key.rsa" | |
cat >> "$HOME/.ssh/config" << EOM | |
Host $repo_name.github.com | |
HostName github.com | |
User git | |
IdentityFile $key_path | |
IdentitiesOnly yes | |
EOM | |
ssh-keygen -f "$key_path" -N '' -t rsa -C "$key" | |
echo | |
echo | |
echo Add the deploy key below to | |
echo "https://github.com/$repo/settings/keys" | |
echo and press enter to clone the repo. | |
echo | |
echo | |
cat "$key_path.pub" | |
echo | |
echo | |
read -p "Press enter to continue..." </dev/tty | |
git clone "git@$repo_name.github.com:$repo.git" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example
curl https://gist.githubusercontent.com/senseluo/8db6440b028e409106b34cb47f668c22/raw/20598280ac557c43568c1706e49aaede6fe13d55/github-deploy-clone.sh > /usr/local/bin/github-deploy-clone