Skip to content

Instantly share code, notes, and snippets.

@rwprodev
Forked from blvz/gh-deploy-clone.sh
Created February 2, 2020 00:16
Show Gist options
  • Save rwprodev/51d7e81035f79dd7fae2b7c4414666e6 to your computer and use it in GitHub Desktop.
Save rwprodev/51d7e81035f79dd7fae2b7c4414666e6 to your computer and use it in GitHub Desktop.

Revisions

  1. @blvz blvz revised this gist Aug 26, 2017. No changes.
  2. @blvz blvz created this gist Aug 26, 2017.
    41 changes: 41 additions & 0 deletions gh-deploy-clone.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    #!/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"