2
0

bintray.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/bash
  2. # bintray_createPackage [REPO] [PACKAGE] [USER] [PASSWORD] [GIT REPO] [LICENSE]
  3. function bintray_createPackage {
  4. repo="$1"
  5. package="$2"
  6. user="$3"
  7. password="$4"
  8. srcrepo="$5"
  9. license="$6"
  10. repoUrl="https://api.bintray.com/packages/$repo"
  11. if [ "`curl -u$user:$password -H Content-Type:application/json -H Accept:application/json \
  12. --write-out %{http_code} --silent --output /dev/null -X GET \"$repoUrl/$package\"`" != "200" ];
  13. then
  14. if [ "$srcrepo" != "" -a "$license" != "" ];
  15. then
  16. echo "Package does not exist... create."
  17. data="{
  18. \"name\": \"${package}\",
  19. \"labels\": [],
  20. \"licenses\": [\"${license}\"],
  21. \"vcs_url\": \"${srcrepo}\"
  22. }"
  23. curl -u$user:$password -H "Content-Type:application/json" -H "Accept:application/json" -X POST \
  24. -d "${data}" "$repoUrl"
  25. else
  26. echo "Package does not exist... you need to specify a repo and license for it to be created."
  27. fi
  28. else
  29. echo "The package already exists. Skip."
  30. fi
  31. }
  32. # uploadFile file destination [REPO] "content" [PACKAGE] [USER] [PASSWORD] [SRCREPO] [LICENSE]
  33. function bintray_uploadFile {
  34. file="$1"
  35. dest="$2"
  36. echo "Upload $file to $dest"
  37. repo="$3"
  38. type="$4"
  39. package="$5"
  40. user="$6"
  41. password="$7"
  42. srcrepo="$8"
  43. license="$9"
  44. publish="${10}"
  45. bintray_createPackage $repo $package $user $password $srcrepo $license
  46. url="https://api.bintray.com/$type/$repo/$package/$dest"
  47. if [ "$publish" = "true" ]; then url="$url;publish=1"; fi
  48. curl -T "$file" -u$user:$password "$url"
  49. }
  50. function bintray_uploadAll {
  51. path="$1"
  52. destpath="$2"
  53. repo="$3"
  54. type="$4"
  55. package="$5"
  56. user="$6"
  57. password="$7"
  58. srcrepo="$8"
  59. license="$9"
  60. publish="${10}"
  61. cdir="$PWD"
  62. cd "$path"
  63. files="`find . -type f -print`"
  64. IFS="
  65. "
  66. set -f
  67. for f in $files; do
  68. destfile="$destpath/${f:2}"
  69. bintray_uploadFile $f $destfile $repo $type $package $user $password $srcrepo $license $publish
  70. done
  71. set +f
  72. unset IFS
  73. cd "$cdir"
  74. }