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.

repositories 5.8KB

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