summaryrefslogtreecommitdiff
path: root/ikiwiki-makerepo
blob: c3d835c308436a5a50d158420ba827c80b95e8af (plain)
  1. #!/bin/sh
  2. set -e
  3. rcs="$1"
  4. srcdir="$2"
  5. repository="$3"
  6. usage () {
  7. echo "usage: ikiwiki-makerepo svn|git|monotone srcdir repository" >&2
  8. echo " ikiwiki-makerepo bzr|mercurial srcdir" >&2
  9. exit 1
  10. }
  11. if [ -z "$rcs" ] || [ -z "$srcdir" ]; then
  12. usage
  13. fi
  14. if [ ! -d "$srcdir" ]; then
  15. echo "srcdir $srcdir not found" >&2
  16. exit 1
  17. fi
  18. if [ "$rcs" != mercurial ] && [ "$rcs" != bzr ]; then
  19. if [ -z "$repository" ]; then
  20. echo "you need to specify both a srcdir and a repository for $rcs" >&2
  21. usage
  22. fi
  23. if [ -e "$repository" ]; then
  24. echo "repository $repository already exists, aborting" >&2
  25. exit 1
  26. fi
  27. repository="$(perl -e 'use Cwd q{abs_path}; $r=shift; $r=~s/\/*$//; print abs_path($r)' "$repository")"
  28. if [ -z "$repository" ]; then
  29. echo "internal error finding repository abs_path" >&2
  30. exit 1
  31. fi
  32. fi
  33. echo "Importing $srcdir into $rcs"
  34. case "$rcs" in
  35. svn)
  36. if [ -e "$srcdir/.svn" ]; then
  37. echo "$srcdir already seems to be a svn working copy" >&2
  38. exit 1
  39. fi
  40. svnadmin create "$repository"
  41. svn mkdir "file://$repository/trunk" -m "create trunk directory"
  42. cd "$srcdir"
  43. svn co "file://$repository/trunk" .
  44. svn propset svn:ignore ".ikiwiki" .
  45. svn add *
  46. svn commit -m "initial import"
  47. echo "Directory $srcdir is now a checkout of $rcs repository $repository"
  48. ;;
  49. git)
  50. # There are better ways to do this, but this works with older
  51. # versions of git.)
  52. mkdir -p "$repository"
  53. (cd "$repository" && git --bare init --shared)
  54. cd "$srcdir"
  55. git init
  56. echo /.ikiwiki > .gitignore
  57. echo /recentchanges >> .gitignore
  58. git add .
  59. git commit -m "initial commit"
  60. git remote add origin "$repository"
  61. git config branch.master.merge refs/heads/master
  62. git config branch.master.remote origin
  63. git push --all
  64. echo "Directory $srcdir is now a clone of $rcs repository $repository"
  65. ;;
  66. mercurial)
  67. hg init "$srcdir"
  68. cd "$srcdir"
  69. echo .ikiwiki > .hgignore
  70. hg add * .hgignore
  71. hg commit -m "initial import"
  72. echo "Directory $srcdir is now set up as a mercurial repository"
  73. ;;
  74. bzr)
  75. bzr init "$srcdir"
  76. cd "$srcdir"
  77. echo .ikiwiki > .bzrignore
  78. bzr add * .bzrignore
  79. bzr commit -m "initial import"
  80. echo "Directory $srcdir is now set up as a bzr repository"
  81. ;;
  82. monotone)
  83. if [ -e "$srcdir/_MTN" ]; then
  84. echo "$srcdir already seems to be a monotone working copy" >&2
  85. exit 1
  86. fi
  87. mkdir -p "$(dirname "$repository")"
  88. mtn db init -d "$repository"
  89. cleaned_srcdir=$(basename "$srcdir" | tr -s "[:space:]" "_" | sed 's/_$//g')
  90. reverse_hostname=$( (hostname -f 2>/dev/null || hostname) |\
  91. tr "." "\n" | ( tac 2>/dev/null || tail -r ) | tr "\n" "." )
  92. branch_name="$reverse_hostname$cleaned_srcdir"
  93. mtn setup -d "$repository" -b "$branch_name" "$srcdir"
  94. cd "$srcdir"
  95. echo \.ikiwiki$ > .mtn-ignore
  96. mtn add -R .
  97. # this expects that you already have a working mtn environment
  98. # with a default key floating around...
  99. mtn ci -m "initial import"
  100. echo "Directory $srcdir is now set up as a monotone repository"
  101. echo ""
  102. echo "Note: If your monotone key has a passphrase, you need to configure"
  103. echo "monotone to automatically use it. Otherwise, web commits to ikiwiki"
  104. echo "will fail."
  105. echo ""
  106. echo "You can create a $srcdir/_MTN/monotonerc"
  107. echo "containing the passphrase:"
  108. echo ""
  109. echo "function get_passphrase (branchname)"
  110. echo ' return "passphrasehere"'
  111. echo "end"
  112. ;;
  113. *)
  114. echo "Unsupported revision control system $rcs" >&2
  115. usage
  116. ;;
  117. esac