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 7.5KB

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