Created
August 4, 2015 10:17
-
-
Save vimishor/3e16e0ddbe1248d9e2aa 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 | |
# | |
# Register a new deploy-key on Bitbucket | |
# | |
# Usage: ./bitbucket-deploy-key.sh <username> <password> key-test ~/.ssh/id_rsa.pub vimishor my-super-repo | |
# | |
USERNAME=$1 | |
PASSWORD=$2 | |
LABEL=$3 | |
KEY_FILE=$4 | |
ACCOUNT=$5 | |
REPOSITORY=$6 | |
if [[ ! -f "${KEY_FILE}" ]]; then | |
echo "Specified key file does not exists." | |
exit 1 | |
fi | |
# API server expects the "key" value to be urlencoded: | |
KEY=$(cat "${KEY_FILE}" | awk '{key=$1" "$2; print key}' | python -c "import sys, urllib as ul; print ul.quote_plus('\n'.join(sys.stdin.readlines()))") | |
curl -u "${USERNAME}:${PASSWORD}" --basic \ | |
-X POST \ | |
-H "Cache-Control: no-cache" \ | |
-H "Content-Type: application/x-www-form-urlencoded" \ | |
-d "label=${LABEL}&key=${KEY}" "https://bitbucket.org/api/1.0/repositories/${ACCOUNT}/${REPOSITORY}/deploy-keys" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment