| [1805] | 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 | exec git http-backend | 
|---|
 | 61 | EOF | 
|---|
 | 62 | close GIT_CGI; | 
|---|
 | 63 | chmod 0755, "_git.cgi"; | 
|---|
 | 64 | symlink "_git.cgi","_git-auth.cgi"; | 
|---|
 | 65 |  | 
|---|
 | 66 | chdir $gitbase; | 
|---|
 | 67 | system qw{git init --bare}, "$addrend.git"; | 
|---|
 | 68 | chdir "$addrend.git"; | 
|---|
 | 69 |  | 
|---|
 | 70 | open ENABLE, ">git-daemon-export-ok"; | 
|---|
 | 71 | print ENABLE ""; | 
|---|
 | 72 | close ENABLE; | 
|---|
 | 73 |  | 
|---|
 | 74 | system qw{htpasswd -c}, $htpasswd, $admin_username; | 
|---|
 | 75 |  | 
|---|
 | 76 | print "Your git repository is located in:\n"; | 
|---|
 | 77 | print "  $gitbase/$addrend.git/\n"; | 
|---|
 | 78 | print "To clone, run\n  git clone https://$USER.scripts.mit.edu/$addrend/$addrend.git\n\n"; | 
|---|
 | 79 | press_enter; | 
|---|
 | 80 |  | 
|---|
 | 81 | exit 0; | 
|---|