Skip to content

Instantly share code, notes, and snippets.

@vimishor
Created August 4, 2015 10:17
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 vimishor/3e16e0ddbe1248d9e2aa to your computer and use it in GitHub Desktop.
Save vimishor/3e16e0ddbe1248d9e2aa to your computer and use it in GitHub Desktop.
#!/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