Перейти к содержанию

Git with Nginx and fcgiwrap: различия между версиями

Материал из Solipse Wiki
Новая страница: «useradd -s /sbin/nologin -d /dev/null git»
 
Нет описания правки
 
(не показано 10 промежуточных версий этого же участника)
Строка 1: Строка 1:
useradd -s /sbin/nologin -d /dev/null git
Add git user
 
useradd -s /sbin/nologin -d /dev/null git
usermod -G git -a nginx
 
Install daemontools
 
mkdir -p /service/gitweb
 
vi /service/gitweb/run
 
#!/bin/bash
PATH=/bin:/sbin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
if [ ! -d /var/run/git ]; then
    mkdir /var/run/git
    chown git:git /var/run/git
elif [ -f /var/run/git/gitweb.sock ]; then
    rm /var/run/git/gitweb.sock
fi
setuidgid git /usr/sbin/fcgiwrap -s unix:/var/run/git/gitweb.sock
 
Set
 
chmod +x /service/gitweb/run
 
Make repository
 
mkdir -P /home/git/repository && cd /home/git/repository
 
git --bare init
 
Config for nginx (Push not work without auth!)
 
server {
  listen 80;
  server_name localhost _default;
  access_log /var/log/nginx/git.access_log main;
  error_log /var/log/nginx/git.error_log info;
  root /var/git;
  location ^~ /static/ { alias /usr/share/gitweb/static/; }
  location / {
    auth_basic            "Restricted";
    auth_basic_user_file  /etc/nginx/htpasswd;
    alias /usr/libexec/git-core/git-http-backend;
    include /etc/nginx/fastcgi_params;
    fastcgi_param GIT_PROJECT_ROOT /var/git;
    fastcgi_param SCRIPT_FILENAME    /usr/libexec/git-core/git-http-backend;
    fastcgi_param GIT_HTTP_EXPORT_ALL "";
    fastcgi_param PATH_INFO  $uri;
    fastcgi_pass unix:/var/run/git/gitweb.sock;
  }
  location /gitweb {
    alias /usr/share/gitweb/gitweb.cgi;
    include /etc/nginx/fastcgi_params;
    fastcgi_pass unix:/var/run/git/gitweb.sock;
  }
}
 
Htpasswd on python
 
htpasswd.py
 
#!/usr/bin/python
# -*- coding: utf-8 -*-
from sys import argv
from random import choice
from string import ascii_letters, digits
from getpass import getpass
from crypt import crypt
if __name__=="__main__":
        name = argv[1:2]
        if not name:
                print ('Login:')
                name = raw_input()
                if not name:
                        print ("Error: no login.")
                        exit(1)
        else:
                name = name[0]
        salt = ''.join(choice(ascii_letters.join(digits)) for char in range(2))
        passwd = getpass("Password: ")
        if not passwd == getpass("Password2: "):
                print ("Error: passwords not same")
                exit(2)
        passwdHash = crypt(passwd, salt)
        print (name + ':' + passwdHash)
        exit(0)

Текущая версия от 10:56, 8 августа 2013

Add git user

useradd -s /sbin/nologin -d /dev/null git
usermod -G git -a nginx

Install daemontools

mkdir -p /service/gitweb
vi /service/gitweb/run
#!/bin/bash

PATH=/bin:/sbin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin 

if [ ! -d /var/run/git ]; then
   mkdir /var/run/git
   chown git:git /var/run/git
elif [ -f /var/run/git/gitweb.sock ]; then
   rm /var/run/git/gitweb.sock
fi

setuidgid git /usr/sbin/fcgiwrap -s unix:/var/run/git/gitweb.sock

Set

chmod +x /service/gitweb/run

Make repository

mkdir -P /home/git/repository && cd /home/git/repository
git --bare init

Config for nginx (Push not work without auth!)

server {
  listen 80;
  server_name localhost _default;

  access_log /var/log/nginx/git.access_log main;
  error_log /var/log/nginx/git.error_log info;

  root /var/git;

  location ^~ /static/ { alias /usr/share/gitweb/static/; }

  location / {
    auth_basic            "Restricted";
    auth_basic_user_file  /etc/nginx/htpasswd;

    alias /usr/libexec/git-core/git-http-backend;
    include /etc/nginx/fastcgi_params;
    fastcgi_param GIT_PROJECT_ROOT /var/git;
    fastcgi_param SCRIPT_FILENAME     /usr/libexec/git-core/git-http-backend;
    fastcgi_param GIT_HTTP_EXPORT_ALL "";
    fastcgi_param PATH_INFO   $uri;
    fastcgi_pass unix:/var/run/git/gitweb.sock;
  }

  location /gitweb {
    alias /usr/share/gitweb/gitweb.cgi;
    include /etc/nginx/fastcgi_params;
    fastcgi_pass unix:/var/run/git/gitweb.sock;
  }
}

Htpasswd on python

htpasswd.py
#!/usr/bin/python
# -*- coding: utf-8 -*-

from sys import argv
from random import choice
from string import ascii_letters, digits
from getpass import getpass
from crypt import crypt

if __name__=="__main__":
        name = argv[1:2]
        if not name:
                print ('Login:')
                name = raw_input()
                if not name:
                        print ("Error: no login.")
                        exit(1)
        else:
                name = name[0]

        salt = .join(choice(ascii_letters.join(digits)) for char in range(2)) 

        passwd = getpass("Password: ")
        if not passwd == getpass("Password2: "):
                print ("Error: passwords not same")
                exit(2)

        passwdHash = crypt(passwd, salt)

        print (name + ':' + passwdHash)

        exit(0)