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.

216 lines
6.9 KiB

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