aboutsummaryrefslogtreecommitdiff
path: root/grok-gitolite-setup.sh
blob: 7958a9a6888def91b9b98a5b3946ed544ee32fa1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/sh -e

# performs steps to install the grokmirror trigger in gitolite

if [ $# -ne 3 ] ; then
	echo "Usage: $0 <gitolite-admin-username> <repo_root> <manifest path>"
	exit 1
fi

if test -f $HOME/.gitolite/local/triggers/post-update.grokmirror && \
   test -f $HOME/.gitolite/local/triggers/post-create.grokmirror && \
   test -f $HOME/.gitolite/local/commands/desc ; then
   # all exist exit early
   exit 0
fi

repo=$(mktemp -d)
git clone $2/gitolite-admin.git $repo

cd $repo
git config user.email "$USER@localhost"
git config user.name "$USER"
git config push.default simple

mkdir -p local/triggers
mkdir -p local/commands

if ! test -f $HOME/.gitolite/local/triggers/post-update.grokmirror ; then
	cat >local/triggers/post-update.grokmirror <<EOF
#!/bin/sh -e

repos=$2
manifest=$3

log(){
	echo "post-git trigger: \$*" 1>&2
}

cd \$repos

if [ "\$4" = "R" ] ; then
	# gitolite read operation, no updates needed
	exit 0
fi

log "updating grokmirror"
/usr/local/bin/grok-manifest -c -m \$manifest -t \$repos -n \$2.git
chmod 655 \$manifest
EOF

chmod 755 local/triggers/post-update.grokmirror
fi

if ! test -f $HOME/.gitolite/local/triggers/post-create.grokmirror ; then
	cat >local/triggers/post-create.grokmirror <<EOF
#!/bin/sh -e

repos=$2
manifest=$3

log(){
	echo "post-git trigger: \$*" 1>&2
}

cd \$repos

if [ "\$4" != "fork" ] ; then
	# no a fork, the update trigger will handle this
	exit 0
fi

log "updating grokmirror"

# NOTE: gitolite always call internal triggers *after* user-defined triggers.
# However, we need the update-git-daemon-access-list to set the
# git-daemon-export-ok flag on the new repo. We call it manually here so
# that our grokmirror code will know if its safe to export the repo
\$GL_BINDIR/triggers/post-compile/update-git-daemon-access-list \$1 \$2 \$3 \$4 \$5

/usr/local/bin/grok-manifest -c -m \$manifest -t \$repos -n \$2.git
chmod 655 \$manifest
EOF

chmod 755 local/triggers/post-create.grokmirror
fi

if ! test -f $HOME/.gitolite/local/commands/desc ; then
	cat >local/commands/desc <<EOF
#!/bin/sh -e

repos=$2
manifest=$3

\${GL_BINDIR}/commands/desc \$*

if [ \$# -ne 1 ] ; then
        if [ \$1 != "-h" ] ; then
                cd \$repos
                /usr/local/bin/grok-manifest -c -m \$manifest -t \$repos -n \$1.git
                chmod 655 \$manifest
        fi
fi
EOF

chmod 755 local/commands/desc
fi

echo "updating gitolite-admin"
git add .
git commit -a -m "add grokmirror setup"
GL_USER=$(echo $1 | cut -d@ -f1) GL_REPO=gitolite-admin GL_LIBDIR=$HOME/gitolite/src/lib git push

rm -rf $repo