mkbitbucketrepo.sh - mkbitbucketrepo - Shell script to create Mercurial and Git repository on Bitbucket
 (HTM) hg clone https://bitbucket.org/iamleot/mkbitbucketrepo
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
       mkbitbucketrepo.sh
       ---
            1 #!/bin/sh
            2 
            3 
            4 #
            5 # Print usage information and exit.
            6 #
            7 usage()
            8 {
            9 
           10         echo "usage: $0 [-ipw] [-d description] [-s hg|git] -u user -o owner repository"
           11         echo 
           12         echo "options:"
           13         echo "-i                Enable issues"
           14         echo "-p                Make the repository private"
           15         echo "-w                Enable wiki"
           16         echo "-d description    Description of the repository"
           17         echo "-s hg|git         SCM used (by default 'hg')"
           18         echo "-o owner          Owner of the repository"
           19         echo "-u user           Username used to create the repository"
           20 
           21         exit 1
           22 }
           23 
           24 # Default values
           25 bitbucket_user=""
           26 owner=""
           27 has_wiki="false"
           28 has_issues="false"
           29 repo_slug=""
           30 scm="hg"
           31 is_private="false"
           32 description=""
           33 
           34 while getopts d:io:ps:u:w f; do
           35         case $f in
           36                 d) description=$OPTARG;;
           37                 i) has_issues="true";;
           38                 p) is_private="true";;
           39                 o) owner=$OPTARG;;
           40                 u) bitbucket_user=$OPTARG;;
           41                 s)
           42                 scm=$OPTARG;
           43                 if [ "$scm" != "hg" ] && [ "$scm" != "git" ]; then
           44                         echo "$0: invalid scm"
           45                         exit 1
           46                 fi
           47                 ;;
           48                 w) has_wiki="true";;
           49                 ?) usage;;
           50         esac
           51 done
           52 shift $((OPTIND - 1))
           53 
           54 repo_slug="$*"
           55 
           56 if [ -z "${bitbucket_user}" ]; then
           57         echo "$0: user needed"
           58         exit 1
           59 fi
           60 if [ -z "${owner}" ]; then
           61         echo "$0: owner needed"
           62         exit 1
           63 fi
           64 if [ -z "${repo_slug}" ]; then
           65         echo "$0: repository_name needed"
           66         exit 1
           67 fi
           68 
           69 curl -X POST -u ${bitbucket_user} -H "Content-Type: application/json"  \
           70     "https://api.bitbucket.org/2.0/repositories/${owner}/${repo_slug}" \
           71     -d @/dev/stdin << EOF
           72 {
           73         "scm": "${scm}",
           74         "has_issue": "${has_issues}",
           75         "has_wiki": "${has_wiki}",
           76         "is_private": "${is_private}",
           77         "description": "${description}"
           78 }
           79 EOF