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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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. # Downloads Portage tree ready for use at production using GIT protocol
  75. # Parameters: %dest_directory% %address%
  76. #-------------------------------------------------------------------------------
  77. function originGitPortage() {
  78. local DST="${1}"
  79. local SRC="${2}"
  80. if [ -e ${DST} ]; then
  81. return 1
  82. fi
  83. run "git clone --depth 1 ${SRC} ${DST}" || return 1
  84. cd ${DST}
  85. run "git config core.compression 0" || return 1
  86. run "git gc --aggressive" || return 1
  87. return 0
  88. }
  89. #-------------------------------------------------------------------------------
  90. # Downloads Portage tree ready for use at production using RSYNC protocol
  91. # Parameters: %dest_directory% %address%
  92. #-------------------------------------------------------------------------------
  93. function originRsyncPortage() {
  94. local DST="${1}"
  95. local SRC="${2}"
  96. if [ -e ${DST} ]; then
  97. return 1
  98. fi
  99. run "rsync --compress --delete --delete-after --devices --force --links \
  100. --partial --perms --recursive --safe-links --stats --times \
  101. --timeout=${FETCHTIMEOUT} --whole-file --exclude=/distfiles \
  102. --exclude=/local --exclude=/packages ${SRC}/ ${DST}" || return 1
  103. return 0
  104. }
  105. #-------------------------------------------------------------------------------
  106. # Prepares SSH Wrappers for use with unknown hosts (requires key authentication)
  107. #-------------------------------------------------------------------------------
  108. function prepareWrappers() {
  109. run "cp ${EZROOT}/files/ssh_wrapper.sh ${BINDIR}/ssh_wrapper.sh" || return 1
  110. run "chmod +x ${BINDIR}/ssh_wrapper.sh" || return 1
  111. export CVS_PASSFILE="${TEMPDIR}/cvspass"
  112. export GIT_SSH="${BINDIR}/ssh_wrapper.sh"
  113. export SVN_SSH="${BINDIR}/ssh_wrapper.sh"
  114. return 0
  115. }
  116. #-------------------------------------------------------------------------------
  117. # Downloads or updates specified CVS repository
  118. # Parameters: %dest_directory% %address% %module%
  119. #-------------------------------------------------------------------------------
  120. function pullCvs() {
  121. local DIRECTORY="${1}"
  122. local ADDRESS="${2}"
  123. local MODULE="${3}"
  124. if [ -d ${DIRECTORY} ]; then
  125. cd ${DIRECTORY}
  126. run "cvs update" || return 1
  127. else
  128. touch ${CVS_PASSFILE}
  129. cd ${TEMPDIR}
  130. run "cvs -q -f -z3 -d:pserver:anonymous:@${ADDRESS} login" || return 1
  131. run "cvs -q -f -z3 -d:pserver:anonymous@${ADDRESS} checkout \
  132. -P ${MODULE}" || return 1
  133. run "mv ${MODULE} ${DIRECTORY}" || return 1
  134. rm -f ${CVS_PASSFILE}
  135. fi
  136. return 0
  137. }
  138. #-------------------------------------------------------------------------------
  139. # Downloads or updates specified GIT repository
  140. # Parameters: %dest_directory% %address% [%branch%]
  141. #-------------------------------------------------------------------------------
  142. function pullGit() {
  143. local DIRECTORY="${1}"
  144. local ADDRESS="${2}"
  145. local BRANCH="${3:-master}"
  146. if [ -d ${DIRECTORY} ]; then
  147. cd ${DIRECTORY}
  148. run "git reset --hard origin/${BRANCH}" || return 1
  149. run "git clean --force" || return 1
  150. run "git pull --no-stat" || return 1
  151. else
  152. run "git clone ${ADDRESS} ${DIRECTORY}" || return 1
  153. if [ ${BRANCH} != "master" ]; then
  154. cd ${DIRECTORY}
  155. run "git checkout ${BRANCH}" || return 1
  156. fi
  157. fi
  158. return 0
  159. }
  160. #-------------------------------------------------------------------------------
  161. # Downloads or updates specified HG repository
  162. # Parameters: %dest_directory% %address% [%branch%]
  163. #-------------------------------------------------------------------------------
  164. function pullMercurial() {
  165. local DIRECTORY="${1}"
  166. local ADDRESS="${2}"
  167. local BRANCH="${3:-default}"
  168. if [ -d ${DIRECTORY} ]; then
  169. cd ${DIRECTORY}
  170. run "hg recover"
  171. run "hg revert -aC" || return 1
  172. run "hg purge" || return 1
  173. run "hg pull --update -e ${BINDIR}/ssh_wrapper.sh" || return 1
  174. else
  175. run "hg clone ${ADDRESS} ${DIRECTORY} -e ${BINDIR}/ssh_wrapper.sh" \
  176. || return 1
  177. if [ ${BRANCH} != "default" ]; then
  178. run "hg branch ${BRANCH}" || return 1
  179. fi
  180. echo -e "\n[extensions]\nhgext.purge=" >> ${DIRECTORY}/.hg/hgrc
  181. fi
  182. return 0
  183. }
  184. #-------------------------------------------------------------------------------
  185. # Synchronizes specified repository regardless its protocol
  186. # Parameters: %dest_directory% %protocol% %address% [%branch%/%module%]
  187. #-------------------------------------------------------------------------------
  188. function pullRepository() {
  189. for ((i=0; $i<${FETCHTRIES}; i++)); do
  190. case "${2}" in
  191. [Cc][Vv][Ss])
  192. pullCvs "${1}" "${3}" "${4}" && return 0
  193. ;;
  194. [Gg][Ii][Tt])
  195. pullGit "${1}" "${3}" "${4}" && return 0
  196. ;;
  197. [Hh][Gg])
  198. pullMercurial "${1}" "${3}" "${4}" && return 0
  199. ;;
  200. [Rr][Ss][Yy][Nn][Cc])
  201. pullRsync "${1}" "${3}" && return 0
  202. ;;
  203. [Ss][Vv][Nn])
  204. pullSubversion "${1}" "${3}" && return 0
  205. ;;
  206. *)
  207. printWarn "Tried to pull data using unsupported protocol (${2})!"
  208. return 1
  209. ;;
  210. esac
  211. sleep ${FETCHTIMEOUT}
  212. done
  213. return 1
  214. }
  215. #-------------------------------------------------------------------------------
  216. # Downloads or updates specified RSYNC repository
  217. # Parameters: %dest_directory% %address%
  218. #-------------------------------------------------------------------------------
  219. function pullRsync() {
  220. DIRECTORY="${1}"
  221. ADDRESS="${2}"
  222. run "rsync --compress --delete --delete-after --devices --force --links \
  223. --partial --perms --recursive --safe-links --stats --times \
  224. --timeout=${FETCHTIMEOUT} --whole-file --exclude=/.git --exclude=/.hg \
  225. --exclude=/.svn --exclude=CVS --exclude=/distfiles --exclude=/local \
  226. --exclude=/metadata/cache --exclude=/metadata/md5-cache \
  227. --exclude=/packages ${ADDRESS}/ ${DIRECTORY}" || return 1
  228. return 0
  229. }
  230. #-------------------------------------------------------------------------------
  231. # Downloads or updates specified SVN repository
  232. # Parameters: %dest_directory% %address%
  233. #-------------------------------------------------------------------------------
  234. function pullSubversion() {
  235. local DIRECTORY="${1}"
  236. local ADDRESS="${2}"
  237. if [ -d ${DIRECTORY} ]; then
  238. cd ${DIRECTORY}
  239. run "svn cleanup" || return 1
  240. run "svn update" || return 1
  241. else
  242. run "svn checkout ${ADDRESS} ${DIRECTORY}" || return 1
  243. fi
  244. return 0
  245. }
  246. #-------------------------------------------------------------------------------
  247. # Sends an update to remote GIT reository
  248. # Parameters: %directory% %message%
  249. #-------------------------------------------------------------------------------
  250. function pushGit() {
  251. local DIRECTORY="${1}"
  252. local MESSAGE="${2}"
  253. local STATUS
  254. [ ! -d ${DIRECTORY} ] && return 1
  255. cd ${DIRECTORY}
  256. run "git add ." || return 1
  257. STATUS=$(git status --porcelain)
  258. if [ "${STATUS}" != "" ]; then
  259. run "git commit -a -m \"${MESSAGE}\"" || return 1
  260. run "git push" || return 1
  261. fi
  262. return 0
  263. }
  264. #-------------------------------------------------------------------------------
  265. # Sends an update to remote HG reository
  266. # Parameters: %directory% %message%
  267. #-------------------------------------------------------------------------------
  268. function pushMercurial() {
  269. local DIRECTORY="${1}"
  270. local MESSAGE="${2}"
  271. local STATUS
  272. [ ! -d ${DIRECTORY} ] && return 1
  273. cd ${DIRECTORY}
  274. run "hg add ." || return 1
  275. STATUS=$(hg status)
  276. if [ "${STATUS}" != "" ]; then
  277. run "hg commit -A -m \"${MESSAGE}\"" || return 1
  278. run "hg push -e ${BINDIR}/ssh_wrapper.sh" || return 1
  279. fi
  280. return 0
  281. }
  282. #-------------------------------------------------------------------------------
  283. # Sends an update to specified remote repository regardless its protocol
  284. # Parameters: %directory% %protocol% %message%
  285. #-------------------------------------------------------------------------------
  286. function pushRepository() {
  287. case "${2}" in
  288. [Gg][Ii][Tt])
  289. pushGit "${1}" "${3}" && return 0
  290. ;;
  291. [Hh][Gg])
  292. pushMercurial "${1}" "${3}" && return 0
  293. ;;
  294. *)
  295. printWarn "Tried to push data using unsupported protocol (${2})!"
  296. ;;
  297. esac
  298. return 1
  299. }