summaryrefslogtreecommitdiffstats
path: root/t/smart-http.root-setup
blob: f22dcb5bda35b3730a6d10f042ae25a705844193 (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
#!/bin/bash

# ----------------------------------------------------------------------
# please do not even LOOK at this file without reading doc/http.mkd
# ----------------------------------------------------------------------

die() { echo "$@"; exit 1; }

# scare the sh*t out of people who run it blindly
[ -f /tmp/gitolite-smart-http-test-OK ] || {
    # scary message
    echo '+ rm -rf /'
    # lots of disk activity
    find / >/dev/null 2>/dev/null
    # and it he's still clueless, God bless!
    echo 'root file system erased successfully.  Goodbye and God bless!'
    exit 1
}

# ----------------------------------------------------------------------
# are we *BSD or Linux?
uname_s=`uname -s`  # could be Linux or FreeBSD or some other BSD
if [ "$uname_s" = "Linux" ]
then
    bsd=:
else
    lnx=:
fi

# ----------------------------------------------------------------------
# main

[ $EUID = 0 ] || die "you must run this as root"

# delete any existing apache conf for gitolite
$lnx rm /etc/httpd/conf.d/gitolite.conf
$bsd rm /usr/local/etc/apache24/Includes/gitolite.conf

# build your "home within a home"
$lnx cd ~apache
$bsd rm -rf /tmp/usr.share.httpd
$bsd mkdir -p /tmp/usr.share.httpd
$bsd chown www:www /tmp/usr.share.httpd
$bsd cd /tmp/usr.share.httpd

rm -rf gitolite-home
mkdir gitolite-home
export GITOLITE_HTTP_HOME=$PWD/gitolite-home

# get the gitolite sources
cd gitolite-home
git clone /tmp/gitolite.git gitolite-source
# NOTE: I use a bare repo in /tmp for convenience; you'd use
# 'https://github.com/sitaramc/gitolite'

# make the bin directory, and add it to PATH
cd gitolite-source
mkdir         $GITOLITE_HTTP_HOME/bin
./install -ln $GITOLITE_HTTP_HOME/bin
export PATH=$PATH:$GITOLITE_HTTP_HOME/bin

# come back to base, then run setup.  Notice that you have to point HOME to
# the right place, even if it is just for this command
cd $GITOLITE_HTTP_HOME
HOME=$GITOLITE_HTTP_HOME gitolite setup -a admin

# insert some essential lines at the beginning of the rc file
echo '$ENV{PATH} .= ":$ENV{GITOLITE_HTTP_HOME}/bin";'  >> 1
echo >> 1
cat .gitolite.rc >> 1
\mv 1 .gitolite.rc

# fix up ownership
$lnx chown -R apache:apache $GITOLITE_HTTP_HOME
$bsd chown -R www:www $GITOLITE_HTTP_HOME

# create the apache config.  Note the trailing slashes on the 2 ScriptAlias
# lines.  (The second one is optional for most sites).  NOTE: you also need to
# give the AuthUserFile a better name/location than what I have below.
cat <<EOF1 > 1
SetEnv GIT_PROJECT_ROOT $GITOLITE_HTTP_HOME/repositories
ScriptAlias /git/ $GITOLITE_HTTP_HOME/gitolite-source/src/gitolite-shell/
ScriptAlias /gitmob/ $GITOLITE_HTTP_HOME/gitolite-source/src/gitolite-shell/
SetEnv GITOLITE_HTTP_HOME $GITOLITE_HTTP_HOME
SetEnv GIT_HTTP_EXPORT_ALL

<Location /git>
    AuthType Basic
    AuthName "Private Git Access"
    Require valid-user
    AuthUserFile $GITOLITE_HTTP_HOME/gitolite-http-authuserfile
</Location>
EOF1
$lnx mv 1 /etc/httpd/conf.d/gitolite.conf
$bsd mv 1 /usr/local/etc/apache24/Includes/gitolite.conf

# NOTE: this is for testing only
htpasswd -bc $GITOLITE_HTTP_HOME/gitolite-http-authuserfile admin admin
map "htpasswd -b $GITOLITE_HTTP_HOME/gitolite-http-authuserfile % %" u{1..6}
$lnx chown apache:apache $GITOLITE_HTTP_HOME/gitolite-http-authuserfile
$bsd chown www:www $GITOLITE_HTTP_HOME/gitolite-http-authuserfile

# restart httpd to make it pick up all the new stuff
$lnx service httpd restart
$bsd /usr/local/etc/rc.d/apache24 restart