「Cgit」の版間の差分
Kusanaginoturugi (トーク | 投稿記録) →Caddy: add h2o. |
|||
| (3人の利用者による、間の9版が非表示) | |||
| 1行目: | 1行目: | ||
{{Lowercase title}} |
|||
[[Category:バージョン管理システム]] |
|||
[[Category:Git ウェブインターフェイス]] |
|||
[[en:Cgit]] |
[[en:Cgit]] |
||
[http://git.zx2c4.com/cgit/ Cgit] は [[git]] バージョン管理システムの高速なウェブインターフェイスです。キャッシュを使うことで git サーバーの負担を減らしています。 |
[http://git.zx2c4.com/cgit/ Cgit] は [[git]] バージョン管理システムの高速なウェブインターフェイスです。キャッシュを使うことで git サーバーの負担を減らしています。 |
||
==インストール== |
==インストール== |
||
{{Pkg|cgit}} パッケージをインストールしてください。 |
|||
cgit を利用するには、システムに [[Apache]] などの[[:カテゴリ:ウェブサーバー|ウェブサーバー]]をインストールする必要があります。 |
cgit を利用するには、システムに [[Apache]] などの[[:カテゴリ:ウェブサーバー|ウェブサーバー]]をインストールする必要があります。 |
||
| 11行目: | 12行目: | ||
===Apache=== |
===Apache=== |
||
以下を {{ic|/etc/httpd/conf/httpd.conf}} ファイルの末尾に追加するか {{ic|/etc/httpd/conf/extra/}} ディレクトリのファイルに記述します: |
以下を {{ic|/etc/httpd/conf/httpd.conf}} ファイルの末尾に追加するか {{ic|/etc/httpd/conf/extra/}} ディレクトリのファイルに記述します: |
||
ScriptAlias /cgit |
ScriptAlias /cgit "/usr/lib/cgit/cgit.cgi/" |
||
Alias /cgit-css "/usr/share/webapps/cgit/" |
Alias /cgit-css "/usr/share/webapps/cgit/" |
||
<Directory "/usr/share/webapps/cgit/"> |
<Directory "/usr/share/webapps/cgit/"> |
||
| 28行目: | 29行目: | ||
===Lighttpd=== |
===Lighttpd=== |
||
以下の設定で http://your.server.com/git または http://your.server.com/cgit から cgit にアクセスできるようになります。完璧ではありませんが動作はします (全てのリポジトリの url で "cgit.cgi" が見えてしまいます)。 |
|||
The following configuration will let you access cgit through http://your.server.com/cgit with http://your.server.com/git redirecting to it. It is not perfect (for example you will see "cgit.cgi" in all repos' url) but works. |
|||
{{ic|/etc/lighttpd/conf.d/cgit.conf}} ファイルを作成: |
|||
server.modules += ("mod_redirect", |
|||
server.modules += ( "mod_cgi", "mod_alias" ) |
|||
"mod_cgi", |
|||
"mod_fastcgi", |
|||
"mod_rewrite" ) |
|||
var.webapps = "/usr/share/webapps/" |
|||
$HTTP["url"] =~ "^/cgit" { |
$HTTP["url"] =~ "^/cgit" { |
||
server.document-root = webapps |
server.document-root = "/usr/share/webapps/" |
||
server.indexfiles = ("cgit.cgi") |
server.indexfiles = ("cgit.cgi") |
||
cgi.assign = ("cgit.cgi" => "") |
cgi.assign = ("cgit.cgi" => "") |
||
mimetype.assign = ( ".css" => "text/css" ) |
mimetype.assign = ( ".css" => "text/css" ) |
||
} |
} |
||
url.redirect = ( |
|||
alias.url += ( |
|||
"^/git/(.*)$" => "/cgit/cgit.cgi/$1", |
|||
"/git" => "/usr/share/webapps/cgit/cgit.cgi", |
|||
) |
) |
||
$HTTP["url"] =~ "^/git" { |
|||
And include this file in {{ic|/etc/lighttpd/lighttpd.conf}}: |
|||
cgi.assign = ( "" => "" ) |
|||
} |
|||
{{ic|/etc/lighttpd/lighttpd.conf}} からファイルを include: |
|||
include "conf.d/cgit.conf" |
include "conf.d/cgit.conf" |
||
そして lighttpd を再起動してください。 |
|||
and restart lighttpd. |
|||
====Lighttpd サブドメイン==== |
====Lighttpd サブドメイン==== |
||
SSL を有効にして git.example.com のようなサブドメインで Cgit をアクセスできるようにして、パーマリンクを作成する lighttpd 設定: |
|||
This alternative lighttpd configuration will serve Cgit on a sub-domain like git.example.com with optional SSL support, and rewrites creating nice permalinks: |
|||
{{bc|1= |
|||
# GIT repository browser |
|||
server.modules += ( "mod_cgi", "mod_rewrite" ) |
|||
#$SERVER["socket"] == "127.0.0.1:443" { |
|||
$SERVER["socket"] == "127.0.0.1:80" { |
|||
#$SERVER["socket"] == ":443" { |
|||
#ssl.engine = "enable" |
|||
$SERVER["socket"] == ":80" { |
|||
#ssl.pemfile = "/etc/lighttpd/ssl/git.example.com.pem" |
|||
#ssl.engine = "enable" |
|||
#ssl.pemfile = "/etc/lighttpd/ssl/git.example.com.pem" |
|||
server.document-root = "/usr/share/webapps/cgit" |
|||
server.name = "git.example.com" |
|||
server.document-root = "/usr/share/webapps/cgit/" |
|||
index-file.names = ( "cgit.cgi" ) |
|||
cgi.assign = ( "cgit.cgi" => "/usr/share/webapps/cgit/cgit.cgi" ) |
|||
index-file.names = ( "cgit.cgi" ) |
|||
cgi.assign = ( "cgit.cgi" => "" ) |
|||
url.rewrite-once = ( |
|||
"^/([^?/]+/[^?]*)?(?:\?(.*))?$" => "/cgit.cgi?url=$1&$2", |
"^/([^?/]+/[^?]*)?(?:\?(.*))?$" => "/cgit.cgi?url=$1&$2", |
||
) |
|||
} |
|||
} |
|||
}} |
|||
===Nginx=== |
===Nginx=== |
||
====fcgiwrap を使う==== |
====fcgiwrap を使う==== |
||
以下を設定することによって {{Pkg|fcgiwrap}} を使って {{ic|git.example.com}} のようなサブドメインで Cgit を表示できます。 |
|||
{{ic|fcgiwrap.socket}} を[[起動]]・[[有効化]]してから、Nginx を設定: |
|||
Configure Nginx: |
|||
{{hc|/etc/nginx/nginx.conf|2= |
{{hc|/etc/nginx/nginx.conf|2= |
||
| 110行目: | 115行目: | ||
====uwsgi を使う==== |
====uwsgi を使う==== |
||
以下の例では uwsgi によってネイティブの cgi プラグインを使って cgit をセットアップします。 |
|||
The following example will setup cgit using the native cgi plugin for uwsgi. |
|||
まず、{{Pkg|uwsgi}} と {{Pkg|uwsgi-plugin-cgi}} をインストールしてください。 |
|||
以下の server ブロックを設定に追加: |
|||
Add below server block to your configuration: |
|||
{{hc|/etc/nginx/nginx.conf|<nowiki> |
|||
server { |
|||
listen 80; |
|||
server_name git.example.com; |
|||
root /usr/share/webapps/cgit; |
|||
server { |
|||
listen 80; |
|||
server_name git.example.com; |
|||
root /usr/share/webapps/cgit; |
|||
# Serve static files with nginx |
# Serve static files with nginx |
||
location ~* ^.+(cgit.(css|png)|favicon.ico|robots.txt) { |
location ~* ^.+(cgit.(css|png)|favicon.ico|robots.txt) { |
||
root /usr/share/webapps/cgit; |
|||
expires 30d; |
|||
} |
|||
location / { |
|||
try_files $uri @cgit; |
|||
} |
|||
location @cgit { |
|||
gzip off; |
|||
include uwsgi_params; |
|||
uwsgi_modifier1 9; |
|||
uwsgi_pass unix:/run/uwsgi/cgit.sock; |
|||
} |
|||
} |
|||
</nowiki>}} |
|||
cgit の uwsgi 設定を追加: |
|||
{{hc|/etc/uwsgi/cgit.ini|2= |
{{hc|/etc/uwsgi/cgit.ini|2= |
||
| 152行目: | 159行目: | ||
}} |
}} |
||
適切なソケットを起動・有効化 (手動でサービスを起動・有効化することもできます): |
|||
Enable and start the corresponding socket (you could also enable and start the service manually). |
|||
# systemctl enable uwsgi@cgit.socket |
# systemctl enable uwsgi@cgit.socket |
||
# systemctl start uwsgi@cgit.socket |
# systemctl start uwsgi@cgit.socket |
||
== |
=== h2o === |
||
Package {{aur|h2o-git}} has its own CGI wrapper fastcgi-cgi, which supports cgit with the following configuration. |
|||
{{hc|/etc/h2o/h2o.conf| |
|||
"git.domain.tld:443": |
|||
listen: |
|||
port: 443 |
|||
ssl: |
|||
... |
|||
paths: |
|||
/cgit.css: |
|||
file.file: /usr/share/webapps/cgit/cgit.css |
|||
file.send-compressed: ON |
|||
/favicon.ico: |
|||
file.file: /usr/share/webapps/cgit/favicon.ico |
|||
file.send-compressed: ON |
|||
/robots.txt: |
|||
file.file: /usr/share/webapps/cgit/robots.txt |
|||
/cgit.png: |
|||
file.file: /usr/share/webapps/cgit/cgit.png |
|||
/: |
|||
fastcgi.spawn: /usr/share/h2o/fastcgi-cgi |
|||
setenv: |
|||
SCRIPT_FILENAME: /usr/lib/cgit/cgit.cgi |
|||
compress: ON |
|||
}} |
|||
===Caddy=== |
|||
[[Caddy]] と [https://jung-kurt.github.io/cgi/ caddy-cgi] プラグインをインストールしてください (例: {{aur|caddy-with-cgi}})。以下の設定は最新の caddy-cgi プラグインの {{ic|except}} サブディレクティブを使用します: |
|||
{{hc|/etc/caddy/caddy.conf.d/cgit.conf| |
|||
git.example.com { |
|||
# other settings such as TLS, headers, ... |
|||
root /usr/share/webapps/cgit |
|||
cgi { |
|||
match / |
|||
exec /usr/share/webapps/cgit/cgit.cgi |
|||
except /cgit.png /favicon.ico /cgit.css /robots.txt |
|||
} |
|||
} |
|||
}} |
|||
==cgit の設定== |
|||
設定オプションの一覧は {{man|5|cgitrc}} を見てください。 |
|||
===基本設定=== |
===基本設定=== |
||
リポジトリを追加する前に、先に {{ic|/etc/cgitrc}} に cgit の基本設定ファイルを作成してください。 |
|||
Before you can start adding repositories you will first have to create the basic cgit configuration file at {{ic|/etc/cgitrc}}. |
|||
# |
# |
||
| 174行目: | 228行目: | ||
#css=/cgit/cgit.css |
#css=/cgit/cgit.css |
||
#logo=/cgit/cgit.png |
#logo=/cgit/cgit.png |
||
# Allow http transport git clone |
|||
#enable-http-clone=0 |
|||
# if you do not want that webcrawler (like google) index your site |
# if you do not want that webcrawler (like google) index your site |
||
robots=noindex, nofollow |
robots=noindex, nofollow |
||
# if cgit messes up links, use a virtual-root. For example |
# if cgit messes up links, use a virtual-root. For example, cgit.example.org/ has this value: |
||
virtual-root=/ |
virtual-root=/ |
||
===リポジトリの追加=== |
===リポジトリの追加=== |
||
リポジトリを追加: |
|||
Now you can add your repos: |
|||
# |
# |
||
| 195行目: | 252行目: | ||
repo.desc=This is my git repository |
repo.desc=This is my git repository |
||
# For a non-bare repository |
|||
repo.url=MyOtherRepo |
repo.url=MyOtherRepo |
||
repo.path=/srv/git/MyOtherRepo.git |
repo.path=/srv/git/MyOtherRepo.git |
||
repo.desc=That's my other git repository |
repo.desc=That's my other git repository |
||
リポジトリを手動で指定したくない場合、cgit に自動的に検索させるように設定することもできます: |
|||
If you prefer not having to manually specify each repository, it is also possible to configure cgit to search for them: |
|||
scan-path=/srv/git/ |
scan-path=/srv/git/ |
||
上記の方法を使用する場合、{{ic|.git/description}} ファイルに説明を追加して、作者を表示するための以下の行を追加してください: |
|||
If you are coming from gitweb and want to keep the descriptions and owner information, then use: |
|||
{{hc|.git/config|2= |
|||
[gitweb] |
|||
owner = John Cena <john@riseup.net> |
|||
}} |
|||
gitweb から移行して説明とオーナー情報を変更したくない場合: |
|||
enable-git-config=1 |
enable-git-config=1 |
||
設定ファイルで利用できる設定に関する詳細は man ページ ({{man|5|cgitrc}}) を見て下さい。 |
|||
For detailed documentation about the available settings in this configuration file, please see the manpage (`man cgitrc`). |
|||
===シンタックスハイライト=== |
===シンタックスハイライト=== |
||
Cgit はソースコードを表示したときのシンタックスハイライトをサポートしています。シンタックスハイライトを有効にする方法は複数存在します。 |
|||
Cgit supports syntax highlighting when viewing blobs. To enable syntax highlighting, you have to install the {{Pkg|highlight}} package. |
|||
====python-pygments を使う==== |
|||
# pacman -S highlight |
|||
{{Pkg|python-pygments}} をインストールして {{ic|/etc/cgitrc}} にフィルターを追加: |
|||
Edit {{ic|/usr/lib/cgit/filters/syntax-highlighting.sh}}. Comment out version 2 and comment in version 3. |
|||
You may want to add {{ic|--inline-css}} to the options of highlight for a more colorfull output without editing cgit's css file. |
|||
source-filter=/usr/lib/cgit/filters/syntax-highlighting.py |
|||
カラーのスタイルを変更したい場合、{{ic|syntax-highlighting.py}} ファイル内で {{ic|HtmlFormatter}} に渡されている {{ic|style}} 引数を修正してください。例えば、カラースタイルを 'tango' に変更するには: |
|||
formatter = HtmlFormatter(encoding='utf-8', style='tango') |
|||
利用可能なカラースタイルは以下のコマンドで確認できます: |
|||
$ python |
|||
>>> from pygments.styles import get_all_styles |
|||
>>> list(get_all_styles()) |
|||
['manni', 'igor', 'xcode', 'vim', 'autumn', 'vs', 'rrt', 'native', 'perldoc', 'borland', 'tango', 'emacs', 'friendly', 'monokai', 'paraiso-dark', 'colorful', 'murphy', 'bw', 'pastie', 'paraiso-light', 'trac', 'default', 'fruity'] |
|||
markdown ファイル (README.md など) をカラー化したい場合は、{{AUR|python-pygments-markdown-lexer}} をインストールしてください。 |
|||
====highlight を使う==== |
|||
{{Pkg|highlight}} パッケージをインストールしてください。 |
|||
{{ic|/usr/lib/cgit/filters/syntax-highlighting.sh}} を {{ic|/usr/lib/cgit/filters/syntax-highlighting-edited.sh}} にコピーします。そして、コピーしたファイルを編集して、バージョン2をコメントアウトしてバージョン3をアンコメントしてください。また、highlight のオプションに {{ic|--inline-css}} を追加することで、cgit の css ファイルを弄らなくてもよりカラフルな出力ができます: |
|||
{{bc| |
{{bc| |
||
# This is for version 2 |
# This is for version 2 |
||
| 223行目: | 308行目: | ||
exec highlight --force --inline-css -f -I -O xhtml -S "$EXTENSION" 2>/dev/null |
exec highlight --force --inline-css -f -I -O xhtml -S "$EXTENSION" 2>/dev/null |
||
}} |
}} |
||
{{ic|/etc/cgitrc}} でフィルターを有効化: |
|||
source-filter=/usr/lib/cgit/filters/syntax-highlighting.sh |
|||
Note: If you edit the {{ic|/usr/lib/cgit/filters/syntax-highlighting.sh}}, the changes will be lost the next time cgit is updated. To avoid this, copy {{ic|/usr/lib/cgit/filters/syntax-highlighting.sh}} to {{ic|/usr/lib/cgit/filters/syntax-highlighting-edited.sh}}, and change {{ic|/etc/cgitrc}} to use the copied file instead |
|||
source-filter=/usr/lib/cgit/filters/syntax-highlighting-edited.sh |
source-filter=/usr/lib/cgit/filters/syntax-highlighting-edited.sh |
||
{{Note|{{ic|/usr/lib/cgit/filters/syntax-highlighting.sh}} を直接編集してしまうと {{Pkg|cgit}} がアップデートされたときに変更した部分が戻ってしまいます。}} |
|||
Alternately you can prevent pacman from extracting the file by adding the following to {{ic|/etc/pacman.conf}}: |
|||
NoExtract = usr/lib/cgit/filters/syntax-highlighting.sh |
|||
==統合== |
==統合== |
||
===Gitosis=== |
===Gitosis=== |
||
[[ |
[[gitosis]] と統合したい場合、以下の2つのコマンドを実行して apache にフォルダを閲覧する権限を与える必要があります: |
||
# chgrp http /srv/gitosis |
# chgrp http /srv/gitosis |
||
| 251行目: | 330行目: | ||
* ''gitolite'' ホームディレクトリと既存のリポジトリのパーミッションを変更。以下のコマンドを実行してください: |
* ''gitolite'' ホームディレクトリと既存のリポジトリのパーミッションを変更。以下のコマンドを実行してください: |
||
**{{ic|# chmod g+rX /var/lib/gitolite}} |
**{{ic|# chmod g+rX /var/lib/gitolite}} |
||
**{{ic|# chmod -R g+rX /var/lib/gitolite/ |
**{{ic|# chmod -R g+rX /var/lib/gitolite/repositories}} |
||
==トラブルシューティング== |
==トラブルシューティング== |
||
===''snapshots'' が正しく表示されない=== |
===''snapshots'' が正しく表示されない=== |
||
''scan-path'' と ''snapshots'' の両方を有効にした場合、cgitrc での順番が大事です。[http://comments.gmane.org/gmane.comp.version-control.cgit/917 cgit のメーリングリスト] によれば、''snapshots'' は ''scan-path'' よりも前に指定する必要があります: |
|||
snapshots=tar.gz tar.bz2 zip |
snapshots=tar.gz tar.bz2 zip |
||
| 261行目: | 340行目: | ||
===''source-filter'' が正しく機能しない=== |
===''source-filter'' が正しく機能しない=== |
||
上記と同じように ''source-filter'' は ''scan-path'' より前に記述しないと適用されません。 |
|||
If you have enabled ''scan-path'', again, the order in cgitrc matters. ''source-filter'' should be specified before ''scan-path'', otherwise it will have no effect. |
|||
==参照== |
==参照== |
||
* |
* https://git.zx2c4.com/cgit/ |
||
* |
* https://git.zx2c4.com/cgit/about/ |
||
* |
* https://git.zx2c4.com/cgit/tree/README |
||
* |
* https://git.zx2c4.com/cgit/tree/cgitrc.5.txt |
||
2022年3月15日 (火) 11:48時点における最新版
Cgit は git バージョン管理システムの高速なウェブインターフェイスです。キャッシュを使うことで git サーバーの負担を減らしています。
インストール
cgit パッケージをインストールしてください。
cgit を利用するには、システムに Apache などのウェブサーバーをインストールする必要があります。
ウェブサーバーの設定
Apache
以下を /etc/httpd/conf/httpd.conf ファイルの末尾に追加するか /etc/httpd/conf/extra/ ディレクトリのファイルに記述します:
ScriptAlias /cgit "/usr/lib/cgit/cgit.cgi/" Alias /cgit-css "/usr/share/webapps/cgit/" <Directory "/usr/share/webapps/cgit/"> AllowOverride None Options None Require all granted </Directory> <Directory "/usr/lib/cgit/"> AllowOverride None Options ExecCGI FollowSymlinks Require all granted </Directory>
次の行をアンコメントして httpd.conf で cgi モジュールをロードするようにしてください:
LoadModule cgi_module modules/mod_cgi.so
httpd.service を再起動することで変更が適用されます。
Lighttpd
以下の設定で http://your.server.com/git または http://your.server.com/cgit から cgit にアクセスできるようになります。完璧ではありませんが動作はします (全てのリポジトリの url で "cgit.cgi" が見えてしまいます)。
/etc/lighttpd/conf.d/cgit.conf ファイルを作成:
server.modules += ( "mod_cgi", "mod_alias" )
$HTTP["url"] =~ "^/cgit" {
server.document-root = "/usr/share/webapps/"
server.indexfiles = ("cgit.cgi")
cgi.assign = ("cgit.cgi" => "")
mimetype.assign = ( ".css" => "text/css" )
}
alias.url += (
"/git" => "/usr/share/webapps/cgit/cgit.cgi",
)
$HTTP["url"] =~ "^/git" {
cgi.assign = ( "" => "" )
}
/etc/lighttpd/lighttpd.conf からファイルを include:
include "conf.d/cgit.conf"
そして lighttpd を再起動してください。
Lighttpd サブドメイン
SSL を有効にして git.example.com のようなサブドメインで Cgit をアクセスできるようにして、パーマリンクを作成する lighttpd 設定:
server.modules += ( "mod_cgi", "mod_rewrite" )
#$SERVER["socket"] == ":443" {
$SERVER["socket"] == ":80" {
#ssl.engine = "enable"
#ssl.pemfile = "/etc/lighttpd/ssl/git.example.com.pem"
server.name = "git.example.com"
server.document-root = "/usr/share/webapps/cgit/"
index-file.names = ( "cgit.cgi" )
cgi.assign = ( "cgit.cgi" => "" )
url.rewrite-once = (
"^/([^?/]+/[^?]*)?(?:\?(.*))?$" => "/cgit.cgi?url=$1&$2",
)
}
Nginx
fcgiwrap を使う
以下を設定することによって fcgiwrap を使って git.example.com のようなサブドメインで Cgit を表示できます。
fcgiwrap.socket を起動・有効化してから、Nginx を設定:
/etc/nginx/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
# Cgit
server {
listen 80;
server_name git.example.com;
root /usr/share/webapps/cgit;
try_files $uri @cgit;
location @cgit {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/cgit.cgi;
fastcgi_param PATH_INFO $uri;
fastcgi_param QUERY_STRING $args;
fastcgi_param HTTP_HOST $server_name;
fastcgi_pass unix:/run/fcgiwrap.sock;
}
}
}
uwsgi を使う
以下の例では uwsgi によってネイティブの cgi プラグインを使って cgit をセットアップします。
まず、uwsgi と uwsgi-plugin-cgi をインストールしてください。
以下の server ブロックを設定に追加:
/etc/nginx/nginx.conf
server {
listen 80;
server_name git.example.com;
root /usr/share/webapps/cgit;
# Serve static files with nginx
location ~* ^.+(cgit.(css|png)|favicon.ico|robots.txt) {
root /usr/share/webapps/cgit;
expires 30d;
}
location / {
try_files $uri @cgit;
}
location @cgit {
gzip off;
include uwsgi_params;
uwsgi_modifier1 9;
uwsgi_pass unix:/run/uwsgi/cgit.sock;
}
}
cgit の uwsgi 設定を追加:
/etc/uwsgi/cgit.ini
[uwsgi] master = true plugins = cgi socket = /run/uwsgi/%n.sock uid = http gid = http procname-master = uwsgi cgit processes = 1 threads = 2 cgi = /usr/lib/cgit/cgit.cgi
適切なソケットを起動・有効化 (手動でサービスを起動・有効化することもできます):
# systemctl enable uwsgi@cgit.socket # systemctl start uwsgi@cgit.socket
h2o
Package h2o-gitAUR has its own CGI wrapper fastcgi-cgi, which supports cgit with the following configuration.
/etc/h2o/h2o.conf
"git.domain.tld:443":
listen:
port: 443
ssl:
...
paths:
/cgit.css:
file.file: /usr/share/webapps/cgit/cgit.css
file.send-compressed: ON
/favicon.ico:
file.file: /usr/share/webapps/cgit/favicon.ico
file.send-compressed: ON
/robots.txt:
file.file: /usr/share/webapps/cgit/robots.txt
/cgit.png:
file.file: /usr/share/webapps/cgit/cgit.png
/:
fastcgi.spawn: /usr/share/h2o/fastcgi-cgi
setenv:
SCRIPT_FILENAME: /usr/lib/cgit/cgit.cgi
compress: ON
Caddy
Caddy と caddy-cgi プラグインをインストールしてください (例: caddy-with-cgiAUR)。以下の設定は最新の caddy-cgi プラグインの except サブディレクティブを使用します:
/etc/caddy/caddy.conf.d/cgit.conf
git.example.com {
# other settings such as TLS, headers, ...
root /usr/share/webapps/cgit
cgi {
match /
exec /usr/share/webapps/cgit/cgit.cgi
except /cgit.png /favicon.ico /cgit.css /robots.txt
}
}
cgit の設定
設定オプションの一覧は cgitrc(5) を見てください。
基本設定
リポジトリを追加する前に、先に /etc/cgitrc に cgit の基本設定ファイルを作成してください。
# # cgit config # css=/cgit.css logo=/cgit.png # Following lines work with the above Apache config #css=/cgit-css/cgit.css #logo=/cgit-css/cgit.png # Following lines work with the above Lighttpd config #css=/cgit/cgit.css #logo=/cgit/cgit.png # Allow http transport git clone #enable-http-clone=0 # if you do not want that webcrawler (like google) index your site robots=noindex, nofollow # if cgit messes up links, use a virtual-root. For example, cgit.example.org/ has this value: virtual-root=/
リポジトリの追加
リポジトリを追加:
# # List of repositories. # This list could be kept in a different file (e.g. '/etc/cgitrepos') # and included like this: # include=/etc/cgitrepos # repo.url=MyRepo repo.path=/srv/git/MyRepo.git repo.desc=This is my git repository # For a non-bare repository repo.url=MyOtherRepo repo.path=/srv/git/MyOtherRepo.git repo.desc=That's my other git repository
リポジトリを手動で指定したくない場合、cgit に自動的に検索させるように設定することもできます:
scan-path=/srv/git/
上記の方法を使用する場合、.git/description ファイルに説明を追加して、作者を表示するための以下の行を追加してください:
.git/config
[gitweb]
owner = John Cena <john@riseup.net>
gitweb から移行して説明とオーナー情報を変更したくない場合:
enable-git-config=1
設定ファイルで利用できる設定に関する詳細は man ページ (cgitrc(5)) を見て下さい。
シンタックスハイライト
Cgit はソースコードを表示したときのシンタックスハイライトをサポートしています。シンタックスハイライトを有効にする方法は複数存在します。
python-pygments を使う
python-pygments をインストールして /etc/cgitrc にフィルターを追加:
source-filter=/usr/lib/cgit/filters/syntax-highlighting.py
カラーのスタイルを変更したい場合、syntax-highlighting.py ファイル内で HtmlFormatter に渡されている style 引数を修正してください。例えば、カラースタイルを 'tango' に変更するには:
formatter = HtmlFormatter(encoding='utf-8', style='tango')
利用可能なカラースタイルは以下のコマンドで確認できます:
$ python >>> from pygments.styles import get_all_styles >>> list(get_all_styles()) ['manni', 'igor', 'xcode', 'vim', 'autumn', 'vs', 'rrt', 'native', 'perldoc', 'borland', 'tango', 'emacs', 'friendly', 'monokai', 'paraiso-dark', 'colorful', 'murphy', 'bw', 'pastie', 'paraiso-light', 'trac', 'default', 'fruity']
markdown ファイル (README.md など) をカラー化したい場合は、python-pygments-markdown-lexerAUR をインストールしてください。
highlight を使う
highlight パッケージをインストールしてください。
/usr/lib/cgit/filters/syntax-highlighting.sh を /usr/lib/cgit/filters/syntax-highlighting-edited.sh にコピーします。そして、コピーしたファイルを編集して、バージョン2をコメントアウトしてバージョン3をアンコメントしてください。また、highlight のオプションに --inline-css を追加することで、cgit の css ファイルを弄らなくてもよりカラフルな出力ができます:
# This is for version 2 #exec highlight --force -f -I -X -S "$EXTENSION" 2>/dev/null # This is for version 3 exec highlight --force --inline-css -f -I -O xhtml -S "$EXTENSION" 2>/dev/null
/etc/cgitrc でフィルターを有効化:
source-filter=/usr/lib/cgit/filters/syntax-highlighting-edited.sh
/usr/lib/cgit/filters/syntax-highlighting.sh を直接編集してしまうと cgit がアップデートされたときに変更した部分が戻ってしまいます。統合
Gitosis
gitosis と統合したい場合、以下の2つのコマンドを実行して apache にフォルダを閲覧する権限を与える必要があります:
# chgrp http /srv/gitosis # chmod a+rx /srv/gitosis
Gitolite
gitolite によって管理されているリポジトリを追加する場合、ウェブサーバーがファイルにアクセスできるようにパーミッションを変更する必要があります。
- http ユーザーを gitolite グループに追加:
# usermod -aG gitolite http
- 今後のリポジトリのパーミッションを変更:
/var/lib/gitolite/.gitolite.rcを編集してUMASKを0027に変更。- 参照: http://gitolite.com/gitolite/gitolite.html#umask
- gitolite ホームディレクトリと既存のリポジトリのパーミッションを変更。以下のコマンドを実行してください:
# chmod g+rX /var/lib/gitolite# chmod -R g+rX /var/lib/gitolite/repositories
トラブルシューティング
snapshots が正しく表示されない
scan-path と snapshots の両方を有効にした場合、cgitrc での順番が大事です。cgit のメーリングリスト によれば、snapshots は scan-path よりも前に指定する必要があります:
snapshots=tar.gz tar.bz2 zip scan-path=/path/to/your/repositories
source-filter が正しく機能しない
上記と同じように source-filter は scan-path より前に記述しないと適用されません。