2009年5月31日 星期日

安裝 Fedora 9+ Trac + GIT 心得

節錄自 http://blog.yam.com/wjyaries/article/18295557

安裝 Fedora 9+ Trac + GIT 心得以文找文
wjyaries 在天空部落發表於16:33:45 | 系統運作
加入書籤: HemiDemiGoogle BookmarksYahoo! My WebDel.icio.usfurltechnorati加入此網頁到:你推我報MyShareUDN共享書籤BlogLive

前言:
  • Git: 程式碼 version control tool. (Linux 的創始人大力推崇,Linux 的核心程式就是用它來控管)
  • Trac: 程式碼瀏覽 / Bug 追蹤 / Wiki,相當實用的開發軟體專案軟體,尤其是協同開發時。
  • Fedora core 9: 前身是有名的小紅帽(Red Hat),也是很多人在用的分支。
接下來就是安裝過程的記錄。
另外,我也試著在 Ubuntu 8 上安裝,請參照<<這篇>>。

1. 安裝 Trac:
[1]經由 trac 官網的手冊,上網抓 setuptools-xxx-py2.5.egg
root $ sh setuptools-xxx.egg
==> 安裝 easy_install 到 /usr/bin
[2] 安裝 Trac 主程式:
root $ easy_install trac
自動上網找到最新版的 trac.
安裝了下列程式:
trac (v0.11.2), trac-admin, tracd
Genshi v0.5.1

[2] 檢查 sqlite 版本:
v3.4.2-2 > 3.3.4 [OK]


2. 安裝 Apache:
在 Linux OS, 幾乎都是它的天下。灌 fedora 時已安裝,不需手動安裝。
(沒安裝的人,請自行查閱網路上的教學文章)

3. 安裝 Git:
[1] 安裝 git 主程式
root $ yum install git-core

[2] 安裝 gitk
root $ yum install gitk


4. 安裝 ssh:
為免不相干的人瀏覽專案內容,除了要設登入權限(稍後介紹)之外,讓 http server 運行成 https (port 443)
灌 fedora 時已安裝,不需手動安裝。
(沒安裝的人,請自行查閱網路上的教學文章)

5. 建立 git repository:
5-1. 建立原始程式碼倉庫(Repository)
% cd /path/to/your/src
% git init
% tar xzvf your.src.tar.gz
% git add *
% git commit -a -m "First revision"

5-2. 建立 git 專案協同開發
% cd /path/to/your/git-web
% git clone --bare /path/to/your/src prj1.git
↑ prj1 是專案名稱, 而建議目錄名稱加上 ".git" 來識別是網路發行用的目錄
% touch prj1.git/git-daemon-export-ok

% ls -F git-web/prj1.git
branch/ config HEAD hooks/ info/ objects/ refs/ description
↑ 注意,這個目錄裡你將看不到任何程式碼。

5-3. 確認程式碼都有上到 git-web
% cd /path/to/new/src
% git clone ssh://your-ip-address/path/to/your/git-web/prj1.git
~ 下載程式碼到 /path/to/new/src, 並產生一個 ".git" 隱藏目錄在 /path/to/new/src/.git

確認程式碼沒問題後,把原先的 source codes 砍掉,以後在 git clone 的目錄開發程式碼
% rm -rf /path/to/your/src
% cd /path/to/new/src
% EDIT/Modify/Create your source codes

6. 設定 trac 環境:
% cd /path/to/trac; mkdir prj1
% trac-admin /path/to/trac-env/prj1 initenv
回答提問的問題,大部份都選預設值即可,即使答錯了,稍後修改 prj1/conf/trac.ini 即可:
db : 預設值 (db/trac.db)
Repository 目錄: /path/to/your/git-web/prj1.git
Version Control = git

% pwd
/path/to/trac-env

% trac-admin /path/to/trac-env/prj1 deploy shares ; ls -F
prj1/ shares/ <--- 產生 shares/ 目錄 % ls -F shares cgi-bin/ htdocs/

% chmod 775 shares/cgi-bin/trac.cgi <--- 設為可執行 修改 trac.cgi, 加入一行: try: import os ++ os.environ['TRAC_ENV_PARENT_DIR'] = '/path/to/trac-env'
import pkg-resources

6-1 設定登入密碼: (承上)
% htdigest -c shares/trac.htpasswd "your-realm" user_acc
New password:
Re-type new password:
其中:
your-realm : 這個字串要跟 httpd.conf 中的設定一致,以下的動作中會說明.
user-acc : 使用者帳號

% htdigest shares/trac.htpasswd "your-realm" user_acc
==> 加第二個以上的使用者時,不需要 "-c" 參數了

6-2 變更 trac 環境目錄的擁有者
root $ chown -R apache.apache /path/to/trac-env
() 在 ubuntu 則是 www-data:www-data

7. 安裝 gitplugin
7-1 到 trac 官網下載 gitplugin.zip, unzip it.
7-2 build python egg
% cd gitplugin/0.11; ls -F
COPYING README setup.py tracext/
% pythod setup.py bdist_egg
==> output 在 dist/TracGit-0.11.0.1-py2.5.egg
% cp dist/TracGit-0.11.0.1-py2.5.egg /path/to/trac-env/prj1/plugins
root $ chown -R apache.apache /path/to/trac-env/prj1/plugins

8. 修改 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
tracext.git.* = enabled

9. 在本機(localhost)上執行 trac + git
目前為止,你可以用下列指令來執行 trac 並從網頁來操作了.
% tracd --port 8000 /path/to/trac-env/prj1

開啟 browser, 連到 http://localhost:8000/trac-env/prj1

10. 設定 apache (HTTP server)
% cd /etc/httpd/conf
% vi httpd.conf
在檔案最末尾,加入以下內容 (假設你的 httpd.conf 是預設的內容)

ScriptAlias /trac /path/to/trac-env/shares/cgi-bin/trac.cgi


SetHandler mod_python
PythonHandler trac.web.modpython_frontend
PythonOption TracEnvParentDir /path/to/trac-env
SSLRequireSSL
AuthType Digest
AuthDigestDomain /trac
AuthName "your-realm"
AuthUserFile /path/to/trac-env/shares/trac.htpasswd
Require valid-user


() "your-realm" 即 6-1 中要輸入的 your-realm 參數

重新啟動 apache:
root $ /etc/init.d/httpd restart
或是
root $ service httpd restart

開啟 browser, 連到 https://your-trac-srv-ip/trac/,應該會看到一個列表(當你有多個專案時),
或直接 https://your-trac-srv-ip/trac/prj1


Appendix A. 如何設定操作 trac 網頁的權限
% trac-admin /path/to/trac-env/prj1
Trac> <--- 進入不同的 shell
Trac> permission list <--- 列出目前的權限設定 Trac> permission add admin TRAC_ADMIN <-- 設定 admin 這個人擁有最高的操作權限 萬用字元的使用:
Trac>
permission remove aaa '*' <--- 把 aaa 的所有權限移除 Trac> permission remove '*' BROWSER_VIEW <-- 移除所有人的瀏覽程式碼權限 ~ 詳情請看 Trac 使用者手冊 ~


Appendix B. FAQ
[1] 在 trac 上 Browse Source 時出現以下錯誤訊息:
Warning: Can't synchronize with the repository (No changeset 1cf82c825f8570d3b7f0b402109c81e5394dbb28 in the repository). Look in the Trac log for more information.

解法:
% trac-admin resync



(完)

沒有留言: