Advertisement
Guest User

Untitled

a guest
Jun 16th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.93 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # This script was written for Ubuntu 14.04 and 16.04
  4. # Other operating systems may need a few changes
  5.  
  6. WORK_DIR=~/svn2git
  7. AUTHORS_FILE=$WORK_DIR/authors.txt
  8. GITDIR_DIRTY=$WORK_DIR/dirty
  9. GITDIR_FINAL=$WORK_DIR/final
  10. CONVERSIONLOG_FILE=$WORK_DIR/conversion.log
  11.  
  12. function checkPrograms {
  13. svn --version >/dev/null 2>&1 || {
  14. printf 'Please install SVN it with the following command\nsudo apt-get install -y subversion\n' >&2
  15. exit 1
  16. }
  17. git --version >/dev/null 2>&1 || {
  18. printf 'Please install GIT it with the following command\nsudo apt-get install -y git\nor with\nsudo apt-get install -y git-core\n' >&2
  19. exit 1
  20. }
  21. git svn --version >/dev/null 2>&1
  22. case $? in
  23. 0|128)
  24. ;;
  25. *)
  26. printf 'Please install GIT SVN it with the following command\nsudo apt-get install -y git-svn\n' >&2
  27. exit 1
  28. esac
  29. }
  30.  
  31. function setupDirectory {
  32. if [ -d "$WORK_DIR" ]; then
  33. printf "Working directory already exists: please remove it.\n$WORK_DIR\n" >&2
  34. exit 1
  35. fi
  36. mkdir "$WORK_DIR" || {
  37. printf "Failed to create working directory.\n$WORK_DIR\n" >&2
  38. exit 1
  39. }
  40. }
  41.  
  42. function exitErr {
  43. printf "\n$1\n"
  44. rm -rf "$WORK_DIR" >/dev/null 2>&1
  45. exit 1
  46. }
  47.  
  48. checkPrograms
  49.  
  50. setupDirectory
  51.  
  52. read -p 'SVN repository URL: ' SVN_URL
  53. if [ -z "$SVN_URL" ]; then
  54. exitErr 'Aborted'
  55. fi
  56. read -p 'SVN username: ' SVN_USERNAME
  57. if [ -z "$SVN_USERNAME" ]; then
  58. exitErr 'Aborted'
  59. fi
  60. read -p 'SVN password: ' SVN_PASSWORD
  61. if [ -z "$SVN_PASSWORD" ]; then
  62. exitErr 'Aborted'
  63. fi
  64. read -p 'Your GIT username: ' GIT_USERNAME
  65. if [ -z "$GIT_USERNAME" ]; then
  66. exitErr 'Aborted'
  67. fi
  68. read -p 'Your GIT email: ' GIT_EMAIL
  69. if [ -z "$GIT_EMAIL" ]; then
  70. exitErr 'Aborted'
  71. fi
  72.  
  73. printf 'Listing committer user names... '
  74. svn log --limit 1 \
  75. --username "$SVN_USERNAME" --password "$SVN_PASSWORD" \
  76. --non-interactive --quiet \
  77. "$SVN_URL" | awk '/^r/ {print $3}' | sort -u \
  78. > "$AUTHORS_FILE" || exitErr 'FAILED!'
  79. printf 'done.\n\n'
  80. echo 'Now you have to fix the authors file.'
  81. echo 'This file is needed to map the SVN usernames to GIT names and emails.'
  82. echo 'For instance, if the SVN username is "mlocati" and the GIT author is "Michele Locati <mlocati@gmail.com>", then the authors file must contain a line like this:'
  83. echo 'mlocati = Michele Locati <mlocati@gmail.com>'
  84. echo 'An editor will be lauched: edit the map file and save it'
  85. read -p 'Press RETURN to continue...' PROCEED
  86. while true; do
  87. editor "$AUTHORS_FILE"
  88. read -p 'Proceed [Y(es), R(edo edit), A(bort)] ' PROCEED
  89. case "$PROCEED" in
  90. Y|y)
  91. break
  92. ;;
  93. A|a)
  94. exitErr 'Aborted'
  95. ;;
  96. R|r)
  97. ;;
  98. esac
  99. done
  100.  
  101.  
  102. printf 'Creating GIT-SVN repository... '
  103. mkdir "$GITDIR_DIRTY" || exitErr "Failed to create directory $GITDIR_DIRTY"
  104. cd "$GITDIR_DIRTY" || exitErr "Failed to enter directory $GITDIR_DIRTY"
  105. git svn init \
  106. --no-metadata \
  107. --username "$SVN_USERNAME" \
  108. "$SVN_URL" >/dev/null || exitErr 'FAILED!'
  109. git config svn.authorsfile "$AUTHORS_FILE"
  110. printf 'done.\n'
  111. printf 'Fetching SVN repository (this may take long time)... '
  112. git svn fetch --quiet --log-window-size=1000 >"$CONVERSIONLOG_FILE" 2>&1 || {
  113. cat "$CONVERSIONLOG_FILE" 2>&1
  114. exitErr 'FAILED!'
  115. }
  116. printf 'done.\n'
  117. printf 'Ignoring files... '
  118. git svn show-ignore > .gitignore
  119. git add .gitignore
  120. git config user.name "$GIT_USERNAME"
  121. git config user.email "$GIT_EMAIL"
  122. git commit --quiet -m 'Convert svn:ignore properties to .gitignore.'
  123. printf 'done.\n'
  124. printf 'Creating empty GIT repository... '
  125. mkdir "$GITDIR_FINAL" || exitErr "Failed to create directory $GITDIR_FINAL"
  126. cd "$GITDIR_FINAL" || exitErr "Failed to enter directory $GITDIR_FINAL"
  127. git init --quiet
  128. printf 'done.\n'
  129. printf 'Creating final GIT repository... '
  130. git remote add dirty "$GITDIR_DIRTY" || exitErr 'Failed to set dirty remote'
  131. git pull --quiet dirty master:master || exitErr 'Failed to fetch from dirty remote'
  132. git remote remove dirty
  133. printf 'done.\n'
  134. printf 'Cleanup... '
  135. rm -rf "$GITDIR_DIRTY"
  136. unlink "$AUTHORS_FILE"
  137. printf 'done.\n'
  138. printf "\nHere's your pretty GIT repository:\n$GITDIR_FINAL\nThe conversion log is here:\n$CONVERSIONLOG_FILE\n\n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement