helper.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. else
  13. go get $1
  14. fi
  15. }
  16. # $1 = git package
  17. # $2 = target directory path
  18. # $3 = branch/commit/revision string, if empty then maste ist used
  19. function get_git {
  20. git clone https://$1 $2
  21. if [[ $3 != "master" ]] && [[ ${3:0} == commit* ]]
  22. then
  23. cd $2
  24. git checkout ${3:7}
  25. elif [[ $3 != "master" ]] && [[ ${3:0} == tag* ]]
  26. then
  27. cd $2
  28. git checkout tags/${3:4}
  29. else
  30. cd $2
  31. git checkout ${3:7}
  32. fi
  33. }
  34. # $1 = mercury package name
  35. # $2 = target directory path
  36. # $3 = branch/commit/revision string, if empty then maste ist used
  37. function get_hg {
  38. if [[ $3 == "master" ]] || [[ $3 == "" ]]
  39. then
  40. hg clone https://$1 $2
  41. else
  42. hg clone https://$1 -r $3 $2
  43. fi
  44. }
  45. # Read the .gopmfile file and clone the branch/commits of the depends
  46. # $1 = .gopmfile file path
  47. # $2 = target directory path
  48. function get_gopm {
  49. local startStr=""
  50. local revStr=""
  51. while read line
  52. do
  53. if [[ $startStr == 'X' ]] && [[ $line == '' ]]
  54. then
  55. break
  56. elif [[ $startStr == 'X' ]]
  57. then
  58. IFS="=" read -a array <<< "$line"
  59. if [[ ${array[1]} != "" ]]
  60. then
  61. local revStr=${array[1]//\`}
  62. go_get ${array[0]} "$2/${array[0]}" $revStr
  63. else
  64. go_get ${array[0]} "$2/${array[0]}" master
  65. fi
  66. elif [[ $line == '[deps]' ]]
  67. then
  68. local startStr="X"
  69. fi
  70. done <$1
  71. }