summaryrefslogtreecommitdiff
path: root/ikiwiki-makerepo
blob: bf33a3a803704cb870d2c85fc8a2ab63a0ccf16f (plain)
  1. #!/bin/sh
  2. set -e
  3. rcs="$1"
  4. srcdir="$2"
  5. repository="$3"
  6. usage () {
  7. echo "usage: ikiwiki-makerepo cvs|svn|git|monotone|darcs 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; $r=shift; $r=getcwd.q{/}.$r if $r!~m!^/!; print $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. cvs)
  36. if [ -e "$srcdir/CVS" ]; then
  37. echo "$srcdir already seems to be a cvs working copy" >&2
  38. exit 1
  39. fi
  40. cvs -Q -d "$repository" init
  41. cat > "$repository/CVSROOT/post-commit-wrapper" <<EOF
  42. #!/bin/sh
  43. IKIWIKI_POST_COMMIT_HOOK="$repository/CVSROOT/post-commit"
  44. exists_ikiwiki_post_commit_hook() {
  45. [ -x \$IKIWIKI_POST_COMMIT_HOOK ];
  46. }
  47. called_with_exactly_one_dir() {
  48. echo "\$@" | grep 'New directory' >/dev/null 2>&1
  49. }
  50. main() {
  51. exists_ikiwiki_post_commit_hook || exit 0
  52. called_with_exactly_one_dir "\$@" && exit 0
  53. # Return from commit and relinquish write lock. ikiwiki post-commit
  54. # wants to "cvs update", which wants to take a read lock.
  55. \$IKIWIKI_POST_COMMIT_HOOK &
  56. return 0
  57. }
  58. main "\$@"
  59. exit \$?
  60. EOF
  61. chmod +x "$repository/CVSROOT/post-commit-wrapper"
  62. cd "$srcdir"/..
  63. cvs -Q -d "$repository" get -P CVSROOT
  64. cd CVSROOT
  65. echo .ikiwiki >> cvsignore
  66. cvs -Q add cvsignore
  67. echo "^ikiwiki $repository/CVSROOT/post-commit-wrapper %{sVv}" >> loginfo
  68. cvs -Q commit -m "ikiwiki-makerepo setup" cvsignore loginfo
  69. cd ..
  70. rm -rf CVSROOT
  71. cd "$srcdir"
  72. cvs -Q -d "$repository" import -m "initial import" ikiwiki IKIWIKI PRE_CVS
  73. cd ..
  74. mv "$srcdir" "$srcdir.orig"
  75. cvs -Q -d "$repository" get -P -d "$(basename "$srcdir")" ikiwiki
  76. [ -d "$srcdir.orig/.ikiwiki" ] && mv "$srcdir.orig/.ikiwiki" "$srcdir"
  77. rm -rf "$srcdir.orig"
  78. echo "Directory $srcdir is now a checkout of $rcs repository $repository"
  79. ;;
  80. svn)
  81. if [ -e "$srcdir/.svn" ]; then
  82. echo "$srcdir already seems to be a svn working copy" >&2
  83. exit 1
  84. fi
  85. svnadmin create "$repository"
  86. svn mkdir "file://$repository/trunk" -m "create trunk directory"
  87. cd "$srcdir"
  88. svn co "file://$repository/trunk" .
  89. svn propset svn:ignore ".ikiwiki" .
  90. svn add *
  91. svn commit -m "initial import"
  92. echo "Directory $srcdir is now a checkout of $rcs repository $repository"
  93. ;;
  94. git)
  95. # There are better ways to do this, but this works with older
  96. # versions of git.)
  97. mkdir -p "$repository"
  98. (cd "$repository" && git --bare init --shared)
  99. cd "$srcdir"
  100. git init
  101. echo /.ikiwiki > .gitignore
  102. echo /recentchanges >> .gitignore
  103. git add .
  104. git commit -m "initial commit"
  105. git remote add origin "$repository"
  106. git config branch.master.merge refs/heads/master
  107. git config branch.master.remote origin
  108. git push --all
  109. echo "Directory $srcdir is now a clone of $rcs repository $repository"
  110. ;;
  111. mercurial)
  112. hg init "$srcdir"
  113. cd "$srcdir"
  114. echo .ikiwiki > .hgignore
  115. hg add
  116. hg commit -m "initial import"
  117. echo "Directory $srcdir is now set up as a mercurial repository"
  118. ;;
  119. bzr)
  120. bzr init "$srcdir"
  121. cd "$srcdir"
  122. echo .ikiwiki > .bzrignore
  123. bzr add
  124. bzr commit -m "initial import"
  125. echo "Directory $srcdir is now set up as a bzr repository"
  126. ;;
  127. monotone)
  128. if [ -e "$srcdir/_MTN" ]; then
  129. echo "$srcdir already seems to be a monotone working copy" >&2
  130. exit 1
  131. fi
  132. mkdir -p "$(dirname "$repository")"
  133. mtn db init -d "$repository"
  134. cleaned_srcdir=$(basename "$srcdir" | tr -s "[:space:]" "_" | sed 's/_$//g')
  135. reverse_hostname=$( (hostname -f 2>/dev/null || hostname) |\
  136. tr "." "\n" | ( tac 2>/dev/null || tail -r ) | tr "\n" "." )
  137. branch_name="$reverse_hostname$cleaned_srcdir"
  138. mtn setup -d "$repository" -b "$branch_name" "$srcdir"
  139. cd "$srcdir"
  140. echo \.ikiwiki$ > .mtn-ignore
  141. mtn add -R .
  142. # this expects that you already have a working mtn environment
  143. # with a default key floating around...
  144. mtn ci -m "initial import"
  145. echo "Directory $srcdir is now set up as a monotone repository"
  146. echo ""
  147. echo "Note: If your monotone key has a passphrase, you need to configure"
  148. echo "monotone to automatically use it. Otherwise, web commits to ikiwiki"
  149. echo "will fail."
  150. echo ""
  151. echo "You can create a $srcdir/_MTN/monotonerc"
  152. echo "containing the passphrase:"
  153. echo ""
  154. echo "function get_passphrase (branchname)"
  155. echo ' return "passphrasehere"'
  156. echo "end"
  157. ;;
  158. darcs)
  159. if [ -e "$srcdir/_darcs" ]; then
  160. echo "$srcdir already seems to be a darcs repository" >&2
  161. exit 1
  162. fi
  163. mkdir -p "$repository"
  164. (cd "$repository" && darcs initialize)
  165. mkdir -p "$srcdir"
  166. cd "$srcdir"
  167. darcs initialize
  168. echo .ikiwiki >> _darcs/prefs/boring
  169. darcs record -a -l -q -m "initial import"
  170. darcs pull -a -q "$repository"
  171. darcs push -a -q "$repository"
  172. echo "Directory $srcdir is now a branch of darcs repo $repository"
  173. # set up master repo's apply hook and tell user to adjust it if desired
  174. darcsdefaults="$repository/_darcs/prefs/defaults"
  175. echo "Preconfiguring apply hook in $darcsdefaults - adjust as desired!"
  176. echo "apply posthook $repository/_darcs/ikiwiki-wrapper" >> "$darcsdefaults"
  177. echo "apply run-posthook" >> "$darcsdefaults"
  178. ;;
  179. *)
  180. echo "Unsupported revision control system $rcs" >&2
  181. usage
  182. ;;
  183. esac