eliminate race (loaded systems only?) that makes gl-conf look empty
[gitolite.git] / t / smart-http.root-setup
blob7a46dda6ecbec5383d44a7e20eab8992f11b6aff
1 #!/bin/bash
3 # ----------------------------------------------------------------------
4 # please do not even LOOK at this file without reading doc/http.mkd
5 # ----------------------------------------------------------------------
7 die() { echo "$@"; exit 1; }
9 # scare the sh*t out of people who run it blindly
10 [ -f /tmp/gitolite-smart-http-test-OK ] || {
11 # scary message
12 echo '+ rm -rf /'
13 # lots of disk activity
14 find / >/dev/null 2>/dev/null
15 # and it he's still clueless, God bless!
16 echo 'root file system erased successfully. Goodbye and God bless!'
17 exit 1
20 # ----------------------------------------------------------------------
21 # are we *BSD or Linux?
22 uname_s=`uname -s` # could be Linux or FreeBSD or some other BSD
23 if [ "$uname_s" = "Linux" ]
24 then
25 bsd=:
26 else
27 lnx=:
30 # ----------------------------------------------------------------------
31 # main
33 [ $EUID = 0 ] || die "you must run this as root"
35 # delete any existing apache conf for gitolite
36 $lnx rm /etc/httpd/conf.d/gitolite.conf
37 $bsd rm /usr/local/etc/apache24/Includes/gitolite.conf
39 # build your "home within a home"
40 $lnx cd ~apache
41 $bsd rm -rf /tmp/usr.share.httpd
42 $bsd mkdir -p /tmp/usr.share.httpd
43 $bsd chown www:www /tmp/usr.share.httpd
44 $bsd cd /tmp/usr.share.httpd
46 rm -rf gitolite-home
47 mkdir gitolite-home
48 export GITOLITE_HTTP_HOME=$PWD/gitolite-home
50 # get the gitolite sources
51 cd gitolite-home
52 git clone /tmp/gitolite.git gitolite-source
53 # NOTE: I use a bare repo in /tmp for convenience; you'd use
54 # 'git://github.com/sitaramc/gitolite'
56 # make the bin directory, and add it to PATH
57 cd gitolite-source
58 mkdir $GITOLITE_HTTP_HOME/bin
59 ./install -ln $GITOLITE_HTTP_HOME/bin
60 export PATH=$PATH:$GITOLITE_HTTP_HOME/bin
62 # come back to base, then run setup. Notice that you have to point HOME to
63 # the right place, even if it is just for this command
64 cd $GITOLITE_HTTP_HOME
65 HOME=$GITOLITE_HTTP_HOME gitolite setup -a admin
67 # insert some essential lines at the beginning of the rc file
68 echo '$ENV{PATH} .= ":$ENV{GITOLITE_HTTP_HOME}/bin";' >> 1
69 echo >> 1
70 cat .gitolite.rc >> 1
71 \mv 1 .gitolite.rc
73 # fix up ownership
74 $lnx chown -R apache:apache $GITOLITE_HTTP_HOME
75 $bsd chown -R www:www $GITOLITE_HTTP_HOME
77 # create the apache config. Note the trailing slashes on the 2 ScriptAlias
78 # lines. (The second one is optional for most sites). NOTE: you also need to
79 # give the AuthUserFile a better name/location than what I have below.
80 cat <<EOF1 > 1
81 SetEnv GIT_PROJECT_ROOT $GITOLITE_HTTP_HOME/repositories
82 ScriptAlias /git/ $GITOLITE_HTTP_HOME/gitolite-source/src/gitolite-shell/
83 ScriptAlias /gitmob/ $GITOLITE_HTTP_HOME/gitolite-source/src/gitolite-shell/
84 SetEnv GITOLITE_HTTP_HOME $GITOLITE_HTTP_HOME
85 SetEnv GIT_HTTP_EXPORT_ALL
87 <Location /git>
88 AuthType Basic
89 AuthName "Private Git Access"
90 Require valid-user
91 AuthUserFile $GITOLITE_HTTP_HOME/gitolite-http-authuserfile
92 </Location>
93 EOF1
94 $lnx mv 1 /etc/httpd/conf.d/gitolite.conf
95 $bsd mv 1 /usr/local/etc/apache24/Includes/gitolite.conf
97 # NOTE: this is for testing only
98 htpasswd -bc $GITOLITE_HTTP_HOME/gitolite-http-authuserfile admin admin
99 map "htpasswd -b $GITOLITE_HTTP_HOME/gitolite-http-authuserfile % %" u{1..6}
100 $lnx chown apache:apache $GITOLITE_HTTP_HOME/gitolite-http-authuserfile
101 $bsd chown www:www $GITOLITE_HTTP_HOME/gitolite-http-authuserfile
103 # restart httpd to make it pick up all the new stuff
104 $lnx service httpd restart
105 $bsd /usr/local/etc/rc.d/apache24 restart