ubuntu 在 R40e 上 還有 Debian 在 Sempron 2600 上

2010年11月29日 星期一

public git server by git-daemon

雖然 git-daemon 有 security 問題,但是在 LAN 內還算 OK .
follow 這一篇 , install git-daemon-run $sudo aptitude install git-daemon-run 這會用 sv 啟動 git-daemon,

git-daemon 的啟動 script 在 /etc/sv/git-gaemo/run
要修改一下 run 這個 script,讓他可以允許 remote push,, follow 這一篇: #!/bin/sh exec 2>&1 echo 'git-daemon starting.' exec chpst -ugitdaemon \ /usr/lib/git-core/git-daemon --export-all --verbose --enable=receive-pack --base-path=/var/cache /var/cache/git
至於要 public 的 repository,要 follow git book 的說明,先 bare clone 出來。
如果不作 bare clone的話,會不允許 remote 對 master 作 push 的動作。

option --export-all 就不用在 .git 下加一個 export_ok 的檔案。

--base-path=/var/cache 代表 git:// 的 root path.

/var/cache/git 代表放置 git repo 專案的位置。
因為 -base-path=/var/cache, 和 位置 /var/cache/git 不一樣 (少了 git),所以 remote access git:// 時,要自己加上 /git/
如果設得一樣就不用了。

假設要 public 的 repository 是 ~/testgit"
$git clone --bare ~/testgit testgit.git 然後把 clone 出來的 testgit.git 這個目錄 copy 到 剛剛啟動 git-daemon 時指定的 path : /var/cache/git 下。

另外,把testgit.git 裡,所有 file, directory 的 owner 都設為 git,這樣 git-daemon 才有write的權限。

重新啟動 git-daemon $sudo sv restart git-daemon
這樣,LAN 裡面的 機器就可以用
$ git clone git://serverip/git/testgit 取出 剛剛的 repo,用
$git push 把 code update 到 server.

實際上,安裝玩後一直有 remote push fail 的問題,到 server 打開 /var/log/git-daemon/current 來看,可以看到是 git repo folder 全縣問題。

結果是看了 run script
exec chpst -ugitdaemon 查一下 chpst 的意思, chpst -uuid 是以 uid 來 run 後面的 program。
所以要把所有 repo 的 owner 改為 gitdaemon 才行。

.... gitdaemon 只有 create user 沒有 group.



開啟 web 介面 (gitweb) #aptitude install apache2 gitweb 裝完以後,先 config gitweb: /etc/gitweb.conf
告訴 gitweb, git-daemon 的 repository 位置: $projectroot = "/home/git/git-daemon/myandroid10.2"
* 實際上,git-daemon 下有很多 folder,每個 folder 各自聚集很多 git project, 如果指定: $projectroot = "/home/git/git-daemon"
gitweb 會找所有 /home/git/git-daemon/下的git project,然後把他們攤平,列出來。
會很亂,所以只把最多人用的 project folder myandroid10.2 列出來就好,就把 root 指到 myandroid10.2 下.
其他的 folder project 就不會顯示出來了。

然後在 apache 加入 virtualhost

因為這個 server 已經 run redmine 了,加上 dns 不歸我們管,所以只有用 port number 來區分。
gitweb 使用 8080

#vi /etc/apache2/site-available/gitweb.conf: <VirtualHost *:8080> DocumentRoot /usr/share/gitweb/ SetEnv GITWEB_CONFIG /etc/gitweb.conf Options ExecCGI AddHandler cgi-script cgi DirectoryIndex gitweb.cgi RewriteEngine on RewriteRule ^/$ /usr/lib/cgi-bin/gitweb.cgi RewriteRule ^/(.*\.git/(?!/?(HEAD|info|objects|refs)).*)?$ /cgi-bin/gitweb.cgi%{REQUEST_URI} [L,PT] </VirtualHost>
然後建 link 到 site-enable 去 #ln -s /etc/apache2/site-available/gitweb.conf /etc/apache2/site-enable/001-gitweb.conf
然後把 port 8080 打開: /etc/apache2/port.conf 加上 port 8080
因為有enable RewriteEngine,所以要 load Rewrite module
建 link #ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enable/rewrite.load
之後重新啟動 apache2 #/etc/init.d/apache2 restart OK

ref
  1. http://blog.longwin.com.tw/2009/05/debian-linux-build-gitweb-2009/

備份一下 server 的 git-daemon run script: #!/bin/sh exec 2>&1 echo 'git-daemon starting.' exec chpst -ugit \ "$(git --exec-path)"/git-daemon --export-all --verbose --enable=receive-pack --base-path=/home/git/git-daemon /home/git/git-daemon server 為了方便,所以真的 create 一個 user git. 然後把 git-daemon base 放到 git 的 home 下...

沒有留言:

標籤

網誌存檔