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