この二つのWebページが大変参考になった。SElinux絡みの設定は一度テキストを読まないと、理解しないまま使うのはちょっと気持ち悪い。
http://jigen.aruko.net/2006/11/14/procedure-to-install-trac-in-from-yum-in-centos/
SubversionリポジトリとTracを作るスクリプトを作る。Setting Up Trac on CentOSの「Instantiating Trac and Subversion」を自動化するようなもの。Tracの新規作成にはいろいろ質問されることがあるので、その辺を expectで自動化している。
subversionリポジトリは /var/www/svn/以下に、Tracディレクトリは /var/www/trac以下に作られ、subversionとtracのプロジェクト名は同じとすることを前提にしている。あとエラーチェックとか入れてないので存在するプロジェクト名を引数にしたときの動作は保障できない。
#!/usr/bin/expect if { $argc == 0 } { puts "usage: $argv0 <project name>" exit } set svnrepos "/var/www/svn/[lindex $argv 0]" set tracdir "/var/www/trac/[lindex $argv 0]" set timeout 5 ### subversion # create the repo; use the filesystem backend spawn svnadmin create $svnrepos --fs-type fsfs interact # give Apache user ownership spawn chown -R apache $svnrepos interact # tell everyone to go away spawn chmod -R go-rwx $svnrepos interact # tell SELinux this is valid web content spawn chcon -R -u system_u -t httpd_sys_content_t $svnrepos interact ### trac # create the instance spawn trac-admin $tracdir initenv expect "Project Name" send "$argv\n" expect "Database connection string" send "\n" expect "Repository type" send "\n" expect "Path to repository" send "$svnrepos\n" expect "Templates directory" send "\n" interact # assign group ownership to Apache spawn chgrp -R apache $tracdir interact # give Apache total ownership of a few important directories spawn chown -R apache $tracdir/attachments interact spawn chown -R apache $tracdir/db interact spawn chown -R apache $tracdir/log interact # tell everyone else to go away spawn chmod -R o-rwx $tracdir interact # tell SELinux this is valid web content spawn chcon -R -u system_u -t httpd_sys_content_t $tracdir interact
spawnのたびにinteractを入れなきゃならないのが見苦しいが、こうしないと処理が飛ばされたりする。もっとエレガントな書き方は誰かにお願いしたい。とりあえず動いてるし。