helper.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. elif [[ $1 == "golang.org/x/crypto" ]]
  58. then
  59. echo $1 $2 $3
  60. get_git "github.com/golang/crypto" $2
  61. else
  62. echo $1 $2 $3
  63. fi
  64. }
  65. # Read the .gopmfile file and clone the branch/commits of the depends
  66. # $1 = .gopmfile file path
  67. # $2 = target directory path
  68. function get_gopm {
  69. local startStr=""
  70. local revStr=""
  71. while read line
  72. do
  73. if [[ $startStr == 'X' ]] && [[ $line == '' ]]
  74. then
  75. break
  76. elif [[ $startStr == 'X' ]]
  77. then
  78. IFS="=" read -a array <<< "$line"
  79. if [[ ${array[1]} != "" ]]
  80. then
  81. local revStr=${array[1]//\`}
  82. go_get ${array[0]} "$2/${array[0]}" $revStr
  83. else
  84. go_get ${array[0]} "$2/${array[0]}" master
  85. fi
  86. elif [[ $line == '[deps]' ]]
  87. then
  88. local startStr="X"
  89. fi
  90. done <$1
  91. }