helper.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/bash
  2. # $1 = package name
  3. # $2 = target directory path
  4. # $3 = branch/commit/revision string, if empty then maste ist used
  5. function go_get {
  6. if [[ $1 == github.com* ]]
  7. then
  8. get_git $1 $2 $3
  9. elif [[ $1 == code.google.com* ]]
  10. then
  11. get_hg $1 $2 $3
  12. elif [[ $1 == golang.org* ]]
  13. then
  14. get_golang $1 $2 $3
  15. else
  16. go get $1
  17. fi
  18. }
  19. # $1 = git package
  20. # $2 = target directory path
  21. # $3 = branch/commit/revision string, if empty then maste ist used
  22. function get_git {
  23. git clone https://$1 $2
  24. if [[ $3 != "master" ]] && [[ ${3:0} == commit* ]]
  25. then
  26. cd $2
  27. git checkout -q ${3:7}
  28. elif [[ $3 != "master" ]] && [[ ${3:0} == tag* ]]
  29. then
  30. cd $2
  31. git checkout -q tags/${3:4}
  32. else
  33. cd $2
  34. git checkout -q ${3:7}
  35. fi
  36. }
  37. # $1 = mercury package name
  38. # $2 = target directory path
  39. # $3 = branch/commit/revision string, if empty then maste ist used
  40. function get_hg {
  41. if [[ $3 == "master" ]] || [[ $3 == "" ]]
  42. then
  43. hg clone https://$1 $2
  44. else
  45. hg clone https://$1 -r $3 $2
  46. fi
  47. }
  48. function get_golang {
  49. if [[ $1 == "golang.org/x/net" ]]
  50. then
  51. echo $1 $2 $3
  52. get_git "github.com/golang/net" $2
  53. elif [[ $1 == "golang.org/x/text" ]]
  54. then
  55. echo $1 $2 $3
  56. get_git "github.com/golang/text" $2
  57. else
  58. echo $1 $2 $3
  59. fi
  60. }
  61. # Read the .gopmfile file and clone the branch/commits of the depends
  62. # $1 = .gopmfile file path
  63. # $2 = target directory path
  64. function get_gopm {
  65. local startStr=""
  66. local revStr=""
  67. while read line
  68. do
  69. if [[ $startStr == 'X' ]] && [[ $line == '' ]]
  70. then
  71. break
  72. elif [[ $startStr == 'X' ]]
  73. then
  74. IFS="=" read -a array <<< "$line"
  75. if [[ ${array[1]} != "" ]]
  76. then
  77. local revStr=${array[1]//\`}
  78. go_get ${array[0]} "$2/${array[0]}" $revStr
  79. else
  80. go_get ${array[0]} "$2/${array[0]}" master
  81. fi
  82. elif [[ $line == '[deps]' ]]
  83. then
  84. local startStr="X"
  85. fi
  86. done <$1
  87. }