(no commit message)
[ikiwiki.git] / ikiwiki-makerepo
blob6951ca0de98f79d9d782ceaf0a772d0900ac6132
1 #!/bin/sh
2 set -e
4 rcs="$1"
5 srcdir="$2"
6 repository="$3"
8 usage () {
9 echo "usage: ikiwiki-makerepo svn|git|svn|monotone|darcs|cvs srcdir repository" >&2
10 echo " ikiwiki-makerepo bzr|mercurial srcdir" >&2
11 exit 1
14 if [ -z "$rcs" ] || [ -z "$srcdir" ]; then
15 usage
18 if [ ! -d "$srcdir" ]; then
19 echo "srcdir $srcdir not found" >&2
20 exit 1
23 if [ "$rcs" != mercurial ] && [ "$rcs" != bzr ]; then
24 if [ -z "$repository" ]; then
25 echo "you need to specify both a srcdir and a repository for $rcs" >&2
26 usage
28 if [ -e "$repository" ]; then
29 echo "repository $repository already exists, aborting" >&2
30 exit 1
32 repository="$(perl -e 'use Cwd; $r=shift; $r=getcwd.q{/}.$r if $r!~m!^/!; print $r' "$repository")"
33 if [ -z "$repository" ]; then
34 echo "internal error finding repository abs_path" >&2
35 exit 1
39 echo "Importing $srcdir into $rcs"
41 case "$rcs" in
42 cvs)
43 if [ -e "$srcdir/CVS" ]; then
44 echo "$srcdir already seems to be a cvs working copy" >&2
45 exit 1
47 cvs -Q -d "$repository" init
48 cd "$srcdir"/..
49 cvs -Q -d "$repository" get -P CVSROOT
50 cd CVSROOT
51 echo .ikiwiki >> cvsignore
52 cvs -Q add cvsignore
53 echo "^ikiwiki $repository/CVSROOT/post-commit %{sVv} &" >> loginfo
54 cvs -Q commit -m "ikiwiki-makerepo setup" cvsignore loginfo
55 cd ..
56 rm -rf CVSROOT
57 cd "$srcdir"
58 cvs -Q -d "$repository" import -m "initial import" ikiwiki IKIWIKI PRE_CVS
59 cd ..
60 mv "$srcdir" "$srcdir.orig"
61 cvs -Q -d "$repository" get -P -d "$(basename "$srcdir")" ikiwiki
62 [ -d "$srcdir.orig/.ikiwiki" ] && mv "$srcdir.orig/.ikiwiki" "$srcdir"
63 rm -rf "$srcdir.orig"
64 echo "Directory $srcdir is now a checkout of $rcs repository $repository"
66 svn)
67 if [ -e "$srcdir/.svn" ]; then
68 echo "$srcdir already seems to be a svn working copy" >&2
69 exit 1
71 svnadmin create "$repository"
72 svn mkdir "file://$repository/trunk" -m "create trunk directory"
73 cd "$srcdir"
74 svn co "file://$repository/trunk" .
75 svn propset svn:ignore ".ikiwiki" .
76 svn add *
77 svn commit -m "initial import"
78 echo "Directory $srcdir is now a checkout of $rcs repository $repository"
80 git)
81 # There are better ways to do this, but this works with older
82 # versions of git.)
83 mkdir -p "$repository"
84 (cd "$repository" && git --bare init --shared)
86 cd "$srcdir"
87 git init
88 echo /.ikiwiki > .gitignore
89 echo /recentchanges >> .gitignore
90 git add .
91 git commit -m "initial commit"
92 git remote add origin "$repository"
93 git config branch.master.merge refs/heads/master
94 git config branch.master.remote origin
95 git push --all
96 echo "Directory $srcdir is now a clone of $rcs repository $repository"
98 mercurial)
99 hg init "$srcdir"
100 cd "$srcdir"
101 echo .ikiwiki > .hgignore
102 hg add
103 hg commit -m "initial import"
104 echo "Directory $srcdir is now set up as a mercurial repository"
106 bzr)
107 bzr init "$srcdir"
108 cd "$srcdir"
109 echo .ikiwiki > .bzrignore
110 bzr add
111 bzr commit -m "initial import"
112 echo "Directory $srcdir is now set up as a bzr repository"
114 monotone)
115 if [ -e "$srcdir/_MTN" ]; then
116 echo "$srcdir already seems to be a monotone working copy" >&2
117 exit 1
120 mkdir -p "$(dirname "$repository")"
121 mtn db init -d "$repository"
123 cleaned_srcdir=$(basename "$srcdir" | tr -s "[:space:]" "_" | sed 's/_$//g')
124 reverse_hostname=$( (hostname -f 2>/dev/null || hostname) |\
125 tr "." "\n" | ( tac 2>/dev/null || tail -r ) | tr "\n" "." )
126 branch_name="$reverse_hostname$cleaned_srcdir"
127 mtn setup -d "$repository" -b "$branch_name" "$srcdir"
129 cd "$srcdir"
130 echo \.ikiwiki$ > .mtn-ignore
131 mtn add -R .
132 # this expects that you already have a working mtn environment
133 # with a default key floating around...
134 mtn ci -m "initial import"
135 echo "Directory $srcdir is now set up as a monotone repository"
136 echo ""
137 echo "Note: If your monotone key has a passphrase, you need to configure"
138 echo "monotone to automatically use it. Otherwise, web commits to ikiwiki"
139 echo "will fail."
140 echo ""
141 echo "You can create a $srcdir/_MTN/monotonerc"
142 echo "containing the passphrase:"
143 echo ""
144 echo "function get_passphrase (branchname)"
145 echo ' return "passphrasehere"'
146 echo "end"
148 darcs)
149 if [ -e "$srcdir/_darcs" ]; then
150 echo "$srcdir already seems to be a darcs repository" >&2
151 exit 1
154 mkdir -p "$repository"
155 (cd "$repository" && darcs initialize)
157 mkdir -p "$srcdir"
158 cd "$srcdir"
159 darcs initialize
160 echo .ikiwiki >> _darcs/prefs/boring
161 darcs record -a -l -q -m "initial import"
162 darcs pull -a -q "$repository"
163 darcs push -a -q "$repository"
164 echo "Directory $srcdir is now a branch of darcs repo $repository"
166 # set up master repo's apply hook and tell user to adjust it if desired
167 darcsdefaults="$repository/_darcs/prefs/defaults"
168 echo "Preconfiguring apply hook in $darcsdefaults - adjust as desired!"
169 echo "apply posthook $repository/_darcs/ikiwiki-wrapper" >> "$darcsdefaults"
170 echo "apply run-posthook" >> "$darcsdefaults"
173 echo "Unsupported revision control system $rcs" >&2
174 usage
176 esac