GIT repository on Ubuntu
Contents
Software
We assume that apache is already installed.
apt install apache2-suexec-pristine gitweb git libcgi-session-perl
Git user creation
Create the group git
groupadd git
Enable git shell, if not listed on /etc/shells
cat /etc/shells # /etc/shells: valid login shells /bin/sh /bin/bash /bin/rbash /bin/dash /usr/bin/tmux /usr/bin/screen echo "/usr/bin/git-shell" >> /etc/shells
Home directory creation
mkdir /opt/repositories/git
User creation
useradd -s /usr/bin/git-shell -g git -d /opt/repositories/git git id git uid=1001(git) gid=1001(git) groups=1001(git)
Change owner of home directory
chown git:git /opt/repositories/git/
Apache configuration
Sites configuration
cd /etc/apache2/sites-available
We create the site 21_git.luniel.com
cat 21_git.luniel.com.conf <VirtualHost *:80> ServerName git.luniel.com RewriteEngine On RewriteRule (.*) https://git.luniel.com%{REQUEST_URI} </VirtualHost>
<VirtualHost *:443> ServerName git.luniel.com Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains;" DocumentRoot "/var/www/git.luniel.com" SSLEngine on SSLCertificateFile /etc/apache2/ssl/rigel.oamis.net.cer SSLCertificateKeyFile /etc/apache2/ssl/rigel.oamis.net.key SSLCACertificateFile /etc/apache2/ssl/ca.cer
<Directory /opt/repositories/git/> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory>
<Location / > Options +FollowSymLinks +ExecCGI AddHandler cgi-script .cgi AuthType Basic AuthName "GIT Repository" AuthUserFile /etc/subversion/passwd Require valid-user </Location>
SuexecUserGroup git git ScriptAlias /git /var/www/sbin/git-http-backend-wrapper ScriptAlias /gitweb.cgi /var/www/sbin/gitweb.cgi
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined CustomLog /var/log/apache2/access_git.luniel.com_ssl.log combined ErrorLog /var/log/apache2/error_git.luniel.com_ssl.log
</VirtualHost>
Create document root
mkdir -p /var/www/git.luniel.com
Enable site
a2ensite 21_git.luniel.com
Enable module
a2enmod suexec cgi
Disable gitweb config
a2disconf gitweb
CGI
git-http-backend-wrapper file creation
cd /var/www/ mkdir sbin vi sbin/git-http-backend-wrapper #!/bin/bash PATH_INFO=$SCRIPT_URL GIT_PROJECT_ROOT=/opt/repositories/git REMOTE_USER=$REDIRECT_REMOTE_USER export GIT_HTTP_EXPORT_ALL=true /usr/lib/git-core/git-http-backend
Copy gitweb cgi
cp /usr/share/gitweb/gitweb.cgi sbin/
Correct rights on sbin folder
chmod 755 ./sbin/git-http-backend-wrapper chown -R git:git sbin/
Static files
Copy static files for gitweb
cd /opt/repositories/git/ cp -r /usr/share/gitweb/static/ ./
Create index.html
cat index.html <html> <head> <title>GIT Luniel Systems</title> </head> <body bgcolor=white> <table border="0" cellpadding="10"> <tr> <td> <img src="images/Luniel_Systems.png" width="200px"> </td> <td> <h1>GIT Luniel Systems</h1> </td> </tr> </table> <p>This server is for internal use only. </p> <ul> <li><a href="https://git.luniel.com/gitweb.cgi">GIT Web</a>.</li> </ul> </body> </html>
Copy Logo
mkdir images cp /home/dany/Luniel_Systems.png images/
Configure gitweb.conf
Change line in file /etc/gitweb.conf
$projectroot = "/opt/repositories/git";
Start apache
systemctl start apache2
Create repository
cd /opt/repositories/git git init --bare --shared=group log2mysql.git Initialized empty shared Git repository in /opt/git/log2mysql.git/ chown -R git:git log2mysql.git/ cd log2mysql.git/ git config --file config http.receivepack true cat config [core] repositoryformatversion = 0 filemode = true bare = true sharedrepository = 1 [receive] denyNonFastforwards = true [http] receivepack = true
References
Daniel Simao (talk) 15:43, 21 September 2018 (EDT)