summaryrefslogtreecommitdiff
path: root/ikiwiki-makerepo
blob: 245043a5c9c0e217d467d30720d5a839fd02a6d5 (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. repodir=$(dirname "$repository")
  88. mkdir -p "$repodir"
  89. file_basename=$(basename "$repository" | sed -e 's/\.monotone$//' |\
  90. tr -s "[:space:]" "_" | sed 's/_$//g')
  91. reverse_hostname=$( (hostname -f 2>/dev/null || hostname) |\
  92. tr "." "\n" | tac | tr "\n" ".")
  93. branch_name="$reverse_hostname$file_basename"
  94. reponame_with_ext="$file_basename.monotone"
  95. mtn db init -d "$repodir/$reponame_with_ext"
  96. mtn setup -d "$repodir/$reponame_with_ext" -b "$branch_name" "$srcdir"
  97. cd "$srcdir"
  98. echo \.ikiwiki$ > .mtn-ignore
  99. mtn add -R .
  100. # this expects that you already have a working mtn environment
  101. # with a default key floating around...
  102. mtn ci -m "initial import"
  103. echo "Directory $srcdir is now set up as a monotone repository"
  104. echo ""
  105. echo "Note: If your monotone key has a passphrase, you need to configure"
  106. echo "monotone to automatically use it. Otherwise, web commits to ikiwiki"
  107. echo "will fail."
  108. echo ""
  109. echo "You can create a $srcdir/_MTN/monotonerc"
  110. echo "containing the passphrase:"
  111. echo ""
  112. echo "function get_passphrase (branchname)"
  113. echo ' return "passphrasehere"'
  114. echo "end"
  115. ;;
  116. *)
  117. echo "Unsupported revision control system $rcs" >&2
  118. usage
  119. ;;
  120. esac