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.

283 lines
9.0KB

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