subversionリポジトリと tracディレクトリを同時に作成するスクリプト(2)

アドバイスを受けて書き直し。シェルスクリプトの書き方は以下のサイトを参考に。
rhythm-cafe.com

#!/bin/sh

if [ $# = 0 ]; then
    echo "$0 <project>"
    exit
fi

svnrepos="/var/www/svn/$1"
tracdir="/var/www/trac/$1"

if [ -d $svnrepos ]; then
    echo "subversion repository $1 already exists."
    exit
fi

if [ -d $tracdir ]; then
    echo "Trac directory $1 already exists."
    exit
fi

### subversion
# create the repo; use the filesystem backend
svnadmin create $svnrepos --fs-type fsfs

# give Apache user ownership
chown -R apache $svnrepos

# tell everyone to go away
chmod -R go-rwx $svnrepos

# tell SELinux this is valid web content
chcon -R -u system_u -t httpd_sys_content_t $svnrepos

### trac
# create the instance
trac-admin $tracdir initenv $1 sqlite:db/trac.db svn $svnrepos /usr/share/trac/templates

# assign group ownership to Apache
chgrp -R apache $tracdir

# give Apache total ownership of a few important directories
chown -R apache $tracdir/attachments
chown -R apache $tracdir/db
chown -R apache $tracdir/log

# tell everyone else to go away
chmod -R o-rwx $tracdir

# tell SELinux this is valid web content
chcon -R -u system_u -t httpd_sys_content_t $tracdir

あとどうしても trac-adminをexpectでやりたいときはこんな風に書くといいかも

expect -c "

set timeout 5

spawn trac-admin $tracdir initenv

expect \"Project Name\"
send \"$1\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
"