Debian Linux 架設 Git + Trac
Trac + SVN 的搭配非常方便, 也是一直沒從 SVN 轉換到 Git 的原因之一.
既然想要取代 SVN, Trac + Git 當然也是該要有的, 下面就來將 Trac + Git 完成.
此篇文章假設已經將 Git Server 環境建置完畢, 若尚未建置, 可參考下述:
此篇文章不會詳細解說 Trac 及 額外 Trac 指令等, 有興趣可以參考:
相關資料準備
- Server: project_name.example.com
- Project name: project_name
- Git Repository Path: /var/cache/git (/var/cache/git/prject_name.git)
- Trac Path: /var/lib/trac (/var/lib/trac/prject_name)
- Apache 帳號、密碼檔: /etc/apache2/dav_git.passwd
- Trac 存取帳號: test_user
安裝步驟
- # on Debian / Ubuntu Linux
- apt-get install trac libapache2-mod-python
- apt-get install trac-git
設定 Trac、存取權限
- mkdir -p /var/lib/trac/project_name
- trac-admin /var/lib/trac/project_name initenv
Project Name => project_name
Path to repository => /var/cache/git/project_name.git - vim /var/lib/trac/project_name/conf/trac.ini
# 修改
default_charset = iso-8859-15 => default_charset = utf-8
repository_dir = /var/cache/git/project_name.git
repository_type = git
# 於檔案最後面增加
[components]
# for plugin version 0.10 (如果 trac 版本是 0.10, 下面 gitplugin 前的 # 要拿掉)
# gitplugin.* = enabled
# for plugin version 0.11.0.1+ (目前 Debian Testing 版 trac 為 0.11, 需要加這段)
tracext.git.* = enabled - chown www-data:www-data -R /var/lib/trac/project_name
- trac-admin /var/lib/trac/project_name permission list # 列出有哪些帳號可以存取
- trac-admin /var/lib/trac/project_name permission remove anonymous '*' # 不允許匿名存取
- trac-admin /var/lib/trac/project_name permission add test_user TRAC_ADMIN # 增加帳號
設定 Apache VirtualHost
- vim /etc/apache2/sites-available/trac_project_name.conf
<VirtualHost *>
ServerAdmin webmaster@localhost
DocumentRoot /var/lib/trac/project_name
ServerName project_name.example.com
ErrorLog /var/log/apache2/trac-project_name-error.log
CustomLog /var/log/apache2/trac-project_name-access.log combined
SetHandler mod_python
PythonHandler trac.web.modpython_frontend
PythonOption TracEnv "/var/lib/trac/project_name"
PythonOption TracUriRoot "/trac/project_name"
<LocationMatch "/trac/[^/]+/login">
AuthType Basic
AuthName "Trac"
AuthUserFile /etc/apache2/dav_git.passwd
Require valid-user
</LocationMatch>
</VirtualHost> - ln -s /etc/apache2/sites-available/trac_project_name.conf /etc/apache2/sites-enabled/trac_project_name.conf
- /etc/init.d/apache2 restart
- 瀏覽 http://project_name.example.com/trac/project_name/ 即完成.
問題與解法
- 若 Git 安裝完, 一直說沒有 Git 相關套件的, 可試著安裝 GitPlugin.
相關網頁
- TracOnDebian – The Trac Project
- GitPlugin - Trac Hacks - Plugins Macros etc. - Trac
- TracGitPlugin - Trac Hacks - Plugins Macros etc. - Trac
- GitwebPlugin - Trac Hacks - Plugins Macros etc. - Trac
- Trac Git Plugin - Trac
Trac+git 來管理wiki和source code
% cd /path/to/your/src
% git init
% tar xzvf your.src.tar.gz
% git add *
% git commit -a -m "First revision"
% git clone --bare /path/to/your/src prj1.git
% touch prj1.git/git-daemon-export-ok
% ls -F git-web/prj1.git
branch/ config HEAD hooks/ info/ objects/ refs/ description
% git clone ssh://your-ip-address/path/to/your/git-web/prj1.git
% trac-admin /path/to/trac-env/prj1 initenv
Repository : /path/to/your/git-web/prj1.git
Version Control = git
% pwd
/path/to/trac-env
修改 trac.cgi, 加入一行:
try:
import os
++ os.environ['TRAC_ENV_PARENT_DIR'] = '/path/to/trac-env'
import pkg-resources
New password:
Re-type new password:
其中:
your-realm : 這個字串要跟 httpd.conf 中的設定一致,以下的動作中會說明.
user-acc : 使用者帳號
% htdigest shares/trac.htpasswd "your-realm" user_acc
==> 加第二個以上的使用者時,不需要 "-c" 參數了
官方網上有tar包,可以安裝。
% pythod setup.py bdist_egg
==> output 在 dist/TracGit-0.10.0.1-py2.4.egg
% cp dist/TracGit-0.10.0.1-py2.4.egg /path/to/trac-env/prj1/plugins
root $ chown -R apache.apache /path/to/trac-env/prj1/plugins
7. 修改 trac 環境設置 trac.ini
% cd /path/to/trac-env/prj1/conf
% vi trac.ini
[logging]
log-type = none file <--- 需要 debug 時
新增以下內容:
[git]
cached_repository = true
persistent_cache = true
shortrev_len = 6
git_bin = /path/to/git <--- 可用 "which git" 找一下你的 git 程式是安裝到哪
[components]
gitplugin.* = enabled
8. 測試是否成功:
% tracd --port 8000 /path/to/trac-env/prj1
連接: http://localhost:8000/trac-env/prj1
9. 到頁面上需要登錄時需要如下:
$ tracd -p 8080 --\
auth=project1,/path/to/users.htdigest,your-realm /path/to/project1
就可以到頁面上登錄你的用戶,然後修改頁面以及wiki更新。
留言列表