reGen2 Linux Release Metatool
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

162 lines
5.1KB

  1. #!/bin/bash
  2. # Copyright 2010-2012, Asio Software Technologies
  3. # Distributed under the terms of the GNU General Public License v3
  4. #-------------------------------------------------------------------------------
  5. # Creates SSH Wrapper for use with unknown hosts (requires key authentication)
  6. #-------------------------------------------------------------------------------
  7. function makeSshWrapper() {
  8. echo "#!/bin/bash" > ${BINDIR}/ssh_wrapper.sh
  9. echo "exec ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \
  10. \"\$@\"" >> ${BINDIR}/ssh_wrapper.sh
  11. chmod +x ${BINDIR}/ssh_wrapper.sh || return 1
  12. export GIT_SSH="${BINDIR}/ssh_wrapper.sh"
  13. export SVN_SSH="${BINDIR}/ssh_wrapper.sh"
  14. return 0
  15. }
  16. #-------------------------------------------------------------------------------
  17. # Downloads or updates specified GIT repository
  18. # Parameters: %dest_directory% %address% [%branch%]
  19. #-------------------------------------------------------------------------------
  20. function pullGit() {
  21. local DIRECTORY="${1}"
  22. local ADDRESS="${2}"
  23. local BRANCH="${3:-master}"
  24. if [ -d ${DIRECTORY} ]; then
  25. cd ${DIRECTORY}
  26. run "git reset --hard origin/${BRANCH}" || return 1
  27. run "git clean --force" || return 1
  28. run "git pull --no-stat" || return 1
  29. else
  30. run "git clone ${ADDRESS} ${DIRECTORY}" || return 1
  31. if [ ${BRANCH} != "master" ]; then
  32. cd ${DIRECTORY}
  33. run "git checkout ${BRANCH}" || return 1
  34. fi
  35. fi
  36. return 0
  37. }
  38. #-------------------------------------------------------------------------------
  39. # Downloads or updates specified HG repository
  40. # Parameters: %dest_directory% %address% [%branch%]
  41. #-------------------------------------------------------------------------------
  42. function pullMercurial() {
  43. local DIRECTORY="${1}"
  44. local ADDRESS="${2}"
  45. local BRANCH="${3:-default}"
  46. if [ -d ${DIRECTORY} ]; then
  47. cd ${DIRECTORY}
  48. run "hg recover"
  49. run "hg revert -aC" || return 1
  50. run "hg purge" || return 1
  51. run "hg pull" || return 1
  52. else
  53. run "hg clone ${ADDRESS} ${DIRECTORY}" || return 1
  54. if [ ${BRANCH} != "default" ]; then
  55. run "hg branch ${BRANCH}" || return 1
  56. fi
  57. echo -e "\n[extensions]\nhgext.purge=" >> ${DIRECTORY}/.hg/hgrc
  58. fi
  59. return 0
  60. }
  61. #-------------------------------------------------------------------------------
  62. # Synchronizes specified repository regardless its protocol
  63. # Parameters: %dest_directory% %protocol% %address% [%branch%]
  64. #-------------------------------------------------------------------------------
  65. function pullRepository() {
  66. for ((i=0; $i<${FETCHTRIES}; i++)); do
  67. case "${2}" in
  68. [Gg][Ii][Tt])
  69. pullGit "${1}" "${3}" "${4}" && return 0
  70. ;;
  71. [Hh][Gg])
  72. pullMercurial "${1}" "${3}" "${4}" && return 0
  73. ;;
  74. [Rr][Ss][Yy][Nn][Cc])
  75. pullRsync "${1}" "${3}" && return 0
  76. ;;
  77. [Ss][Vv][Nn])
  78. pullSubversion "${1}" "${3}" && return 0
  79. ;;
  80. *)
  81. printWarn "Tried to pull data using unsupported protocol (${2})!"
  82. return 1
  83. ;;
  84. esac
  85. sleep ${FETCHTIMEOUT}
  86. done
  87. return 1
  88. }
  89. #-------------------------------------------------------------------------------
  90. # Downloads or updates specified RSYNC repository
  91. # Parameters: %dest_directory% %address%
  92. #-------------------------------------------------------------------------------
  93. function pullRsync() {
  94. DIRECTORY="${1}"
  95. ADDRESS="${2}"
  96. run "rsync --compress --delete --delete-after --devices --force --links \
  97. --partial --perms --recursive --safe-links --stats --times \
  98. --timeout=${FETCHTIMEOUT} --whole-file --exclude=/.git --exclude=/.hg \
  99. --exclude=/.svn --exclude=CVS --exclude=/distfiles --exclude=/local \
  100. --exclude=/metadata/cache --exclude=/packages ${ADDRESS} \
  101. ${DIRECTORY}" || return 1
  102. return 0
  103. }
  104. #-------------------------------------------------------------------------------
  105. # Downloads or updates specified SVN repository
  106. # Parameters: %dest_directory% %address%
  107. #-------------------------------------------------------------------------------
  108. function pullSubversion() {
  109. local DIRECTORY="${1}"
  110. local ADDRESS="${2}"
  111. if [ -d ${DIRECTORY} ]; then
  112. cd ${DIRECTORY}
  113. run "svn cleanup" || return 1
  114. run "svn update" || return 1
  115. else
  116. run "svn checkout ${ADDRESS} ${DIRECTORY}" || return 1
  117. fi
  118. return 0
  119. }
  120. #-------------------------------------------------------------------------------
  121. # Sends an update to remote GIT reository
  122. # Parameters: %directory% %message%
  123. #-------------------------------------------------------------------------------
  124. function pushGit() {
  125. local DIRECTORY="${1}"
  126. local MESSAGE="${2}"
  127. local STATUS
  128. [ ! -d ${DIRECTORY} ] && return 1
  129. cd ${DIRECTORY}
  130. run "git add ." || return 1
  131. STATUS=$(git status --porcelain)
  132. if [ "${STATUS}" != "" ]; then
  133. run "git commit -a -m ${MESSAGE}" || return 1
  134. run "git push" || return 1
  135. fi
  136. return 0
  137. }
  138. #-------------------------------------------------------------------------------
  139. # Sends an update to specified remote repository regardless its protocol
  140. # Parameters: %directory% %protocol% %message%
  141. #-------------------------------------------------------------------------------
  142. function pushRepository() {
  143. case "${2}" in
  144. [Gg][Ii][Tt])
  145. pushGit "${1}" "${3}" && return 0
  146. ;;
  147. *)
  148. printWarn "Tried to push data using unsupported protocol (${2})!"
  149. ;;
  150. esac
  151. return 1
  152. }