1 | #!/usr/bin/perl |
---|
2 | use strict; |
---|
3 | use FindBin qw($Bin); |
---|
4 | use lib $Bin; |
---|
5 | use onserver; |
---|
6 | |
---|
7 | setup(); |
---|
8 | |
---|
9 | my $gitbase = "$scriptsdir/git"; |
---|
10 | my $htpasswd = "$gitbase/$addrend.git/.htpasswd"; |
---|
11 | |
---|
12 | open HTACCESS, ">.htaccess"; |
---|
13 | print HTACCESS <<EOF; |
---|
14 | RewriteEngine On |
---|
15 | |
---|
16 | RewriteCond %{QUERY_STRING} =service=git-receive-pack [OR] |
---|
17 | RewriteCond %{REQUEST_URI} /git-receive-pack\$ |
---|
18 | RewriteRule ^($addrend\\.git/.*)\$ /~$USER/$addrend/_git-auth.cgi/\$1 |
---|
19 | <Files _git-auth.cgi> |
---|
20 | AuthName "Git Access" |
---|
21 | AuthType basic |
---|
22 | AuthUserFile $htpasswd |
---|
23 | Require user $admin_username |
---|
24 | |
---|
25 | # Alternatively, replace "require user" with: |
---|
26 | #Require group somegroup |
---|
27 | #AuthGroupFile $gitbase/$addrend/.htgroup |
---|
28 | # and set up .htgroup appropriately |
---|
29 | </Files> |
---|
30 | |
---|
31 | RewriteRule ^($addrend\\.git/.*)\$ /~$USER/$addrend/_git.cgi/\$1 |
---|
32 | EOF |
---|
33 | close HTACCESS; |
---|
34 | chmod 0777, ".htaccess"; |
---|
35 | |
---|
36 | open GIT_CGI, ">_git.cgi"; |
---|
37 | print GIT_CGI <<EOF; |
---|
38 | #!/bin/sh |
---|
39 | case "\$PATH_INFO" in |
---|
40 | .. | ../* | */.. | */../*) |
---|
41 | echo "Content-type: text/plain" |
---|
42 | echo "Status: 403 Forbidden" |
---|
43 | echo "" |
---|
44 | echo "Error: Illegally found '..' in PATH_INFO='\$PATH_INFO'" |
---|
45 | echo "gitautoinstaller: \$HOME: found '..' in PATH_INFO='\$PATH_INFO'" >&2 |
---|
46 | exit 1;; |
---|
47 | /$addrend.git/*) |
---|
48 | # pass |
---|
49 | ;; |
---|
50 | *) |
---|
51 | echo "Content-type: text/plain" |
---|
52 | echo "Status: 403 Forbidden" |
---|
53 | echo "" |
---|
54 | echo "Error: PATH_INFO='\$PATH_INFO' must start with /$addrend.git/" |
---|
55 | echo "gitautoinstaller: \$HOME: found bad start in PATH_INFO='\$PATH_INFO'" >&2 |
---|
56 | exit 1;; |
---|
57 | esac |
---|
58 | export GIT_PROJECT_ROOT="$gitbase" |
---|
59 | export PATH_TRANSLATED="\$GIT_PROJECT_ROOT\$PATH_INFO" |
---|
60 | export GIT_HTTP_EXPORT_ALL=1 |
---|
61 | exec git http-backend |
---|
62 | EOF |
---|
63 | close GIT_CGI; |
---|
64 | chmod 0755, "_git.cgi"; |
---|
65 | symlink "_git.cgi","_git-auth.cgi"; |
---|
66 | |
---|
67 | chdir $gitbase; |
---|
68 | system qw{git init --bare}, "$addrend.git"; |
---|
69 | chdir "$addrend.git"; |
---|
70 | |
---|
71 | system qw{htpasswd -c}, $htpasswd, $admin_username; |
---|
72 | |
---|
73 | print "Your git repository is located in:\n"; |
---|
74 | print " $gitbase/$addrend.git/\n"; |
---|
75 | print "To clone, run\n git clone https://$USER.scripts.mit.edu/$addrend/$addrend.git\n\n"; |
---|
76 | print "Note: Push over HTTP is a relatively new feature in Git, so if git push fails\n"; |
---|
77 | print "try a newer version of Git, e.g. if you're on Athena, 'add -f git' and try again.\n\n"; |
---|
78 | press_enter; |
---|
79 | |
---|
80 | exit 0; |
---|