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.

181 lines
5.6KB

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