eliminate race (loaded systems only?) that makes gl-conf look empty
[gitolite.git] / t / mirror-test-setup.sh
blobb35364cbc8bcde6c7e46c319b1d37c2510426768
1 #!/bin/bash
3 set -e
4 hosts="frodo sam gollum"
5 mainhost=frodo
7 # setup software
8 bd=`gitolite query-rc -n GL_BINDIR`
9 mkdir -p /tmp/g3
10 rm -rf /tmp/g3/src
11 cp -a $bd /tmp/g3/src
12 chmod -R go+rX /tmp/g3
14 # setup symlinks in frodo, sam, and gollum's accounts
15 for h in $hosts
17 sudo -u $h -i bash -c "rm -rf *.pub bin .ssh projects.list repositories .gitolite .gitolite.rc"
18 done
20 [ "$1" = "clear" ] && exit
22 cd /tmp/g3
23 [ -d keys ] || {
24 mkdir keys
25 cd keys
26 for h in $hosts
28 ssh-keygen -N '' -q -f server-$h -C $h
29 chmod go+r /tmp/g3/keys/server-$h
30 done
31 cp $bd/../t/mirror-test-ssh-config ssh-config
33 chmod -R go+rX /tmp/g3
35 for h in $hosts
37 sudo -u $h -i bash -c "mkdir -p bin; ln -sf /tmp/g3/src/gitolite bin; mkdir -p .ssh; chmod 0700 .ssh"
39 sudo -u $h -i cp /tmp/g3/keys/ssh-config .ssh/config
40 sudo -u $h -i cp /tmp/g3/keys/server-$h .ssh/id_rsa
41 sudo -u $h -i cp /tmp/g3/keys/server-$h.pub .ssh/id_rsa.pub
42 sudo -u $h -i chmod go-rwx .ssh/id_rsa .ssh/config
44 done
46 # add all pubkeys to all servers
47 for h in $hosts
49 sudo -u $h -i gitolite setup -a admin
50 for j in $hosts
52 sudo -u $h -i gitolite setup -pk /tmp/g3/keys/server-$j.pub
53 echo sudo _u $j _i ssh $h@localhost info
54 sudo -u $j -i ssh -o StrictHostKeyChecking=no $h@localhost info
55 done
56 echo ----
57 done
59 # now copy our admin key to the main host
60 cd;cd .ssh
61 cp admin id_rsa; cp admin.pub id_rsa.pub
62 cp admin.pub /tmp/g3/keys; chmod go+r /tmp/g3/keys/admin.pub
63 sudo -u $mainhost -i gitolite setup -pk /tmp/g3/keys/admin.pub
64 ssh $mainhost@localhost info
66 lines="
67 repo gitolite-admin
68 option mirror.master = frodo
69 option mirror.slaves-1 = sam gollum
70 option mirror.redirectOK = sam
72 repo r1
73 RW+ = u1
74 RW = u2
75 R = u3
76 option mirror.master = sam
77 option mirror.slaves-1 = frodo
79 repo r2
80 RW+ = u2
81 RW = u3
82 R = u4
83 option mirror.master = sam
84 option mirror.slaves-1 = frodo gollum
85 option mirror.redirectOK = all
87 include \"%HOSTNAME.conf\"
90 lines2="
91 repo l-%HOSTNAME
92 RW = u1
95 # for each server, set the HOSTNAME to the rc, add the mirror options to the
96 # conf file, and compile
97 for h in $hosts
99 cat $bd/../t/mirror-test-rc | perl -pe "s/%HOSTNAME/$h/" > /tmp/g3/temp
100 chmod go+rX /tmp/g3/temp
101 sudo -u $h -i cp /tmp/g3/temp .gitolite.rc
102 echo "$lines" | sudo -u $h -i sh -c 'cat >> .gitolite/conf/gitolite.conf'
103 echo "$lines2" | sudo -u $h -i sh -c "cat >> .gitolite/conf/$h.conf"
104 sudo -u $h -i gitolite setup
105 done
107 # goes on frodo
108 lines="
109 # local to frodo but sam thinks frodo is a slave
110 repo lfrodo
111 RW = u1
113 # both think they're master
114 repo mboth
115 RW = u1
116 option mirror.master = frodo
117 option mirror.slaves = sam
119 # frodo thinks someone else is the master but sam thinks he is
120 repo mnotsam
121 RW = u1
122 option mirror.master = merry
123 option mirror.slaves = frodo
125 # local to frodo but sam thinks frodo is a master and redirect is OK
126 repo lfrodo2
127 RW = u1
129 # non-native to frodo but sam thinks frodo is master
130 repo nnfrodo
131 RW = u1
132 option mirror.master = gollum
133 option mirror.slaves = frodo
134 option mirror.redirectOK = all
136 # sam is not a valid slave to send stuff to frodo
137 repo nvsfrodo
138 RW = u1
139 option mirror.master = frodo
140 option mirror.slaves = gollum
141 option mirror.redirectOK = all
144 echo "$lines" | sudo -u frodo -i sh -c "cat >> .gitolite/conf/frodo.conf"
146 # goes on sam
147 lines="
148 # local to frodo but sam thinks frodo is a slave
149 repo lfrodo
150 RW = u1
151 option mirror.master = sam
152 option mirror.slaves = frodo
154 # both think they're master
155 repo mboth
156 RW = u1
157 option mirror.master = sam
158 option mirror.slaves = frodo
160 # frodo thinks someone else is the master but sam thinks he is
161 repo mnotsam
162 RW = u1
163 option mirror.master = sam
164 option mirror.slaves = frodo
166 # local to frodo but sam thinks frodo is a master and redirect is OK
167 repo lfrodo2
168 RW = u1
169 option mirror.master = frodo
170 option mirror.slaves = sam
171 option mirror.redirectOK = all
173 # non-native to frodo but sam thinks frodo is master
174 repo nnfrodo
175 RW = u1
176 option mirror.master = frodo
177 option mirror.slaves = sam
178 option mirror.redirectOK = all
180 # sam is not a valid slave to send stuff to frodo
181 repo nvsfrodo
182 RW = u1
183 option mirror.master = frodo
184 option mirror.slaves = sam
185 option mirror.redirectOK = all
188 echo "$lines" | sudo -u sam -i sh -c "cat >> .gitolite/conf/sam.conf"
190 for h in $hosts
192 sudo -u $h -i gitolite setup
193 done
195 # that ends the setup phase
196 echo ======================================================================