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