Here are some notes on installing Trac, so that I have a good reference to help me the next time I need to install it, and maybe it’ll help someone else too.
The latest version of trac is 0.10.4. This still uses ClearSilver, so we need to install that. (ClearSilver gets replaced by Genshi in Trac 0.11.)
I’ll gloss over permission and ownership issues. Python packages get installed in /Library/Python/2.5/site-packages, so you need write permission to that. Other things may end up in /usr/local, so you also need permissions there.
Python and Subversion
Mac OS X 10.5 ships with Python 2.5.1, Subversion 1.4.4, and the SWIG bindings. The SWIG bindings are required for the cool subversion repository integration.
ClearSilver
The latest version of ClearSilver is 0.10.5. Something in the Ruby module doesn’t build (complaining it can’t find i386 arches on ppc), so just disable it:
% ./configure --disable-ruby
% make
% sudo make install
This should install three libraries in /usr/local/lib: libneo_cgi.a, libneo_cs.a, libneo_utl.a.
(Somewhere something installs a stray Library directory, this might be it. I watch for it the next time I install.)
This install file says this:
The make install is relatively new, and just installs the
libraries/header files (and probably the perl and python modules, but
that’s a guess)
Uh, thanks for guessing, but it doesn’t install the python modules that Trac needs. Change into the python directory and do this to install:
% sudo python setup.py install
This should create /Library/Python/2.5/site-packages/clearsilver-0.10.5-py2.5-macosx-10.5-ppc.egg.
You can verify by running python and trying to import neo_cgi.
Postgres
I use Postgres for a database, I assume that’s already been installed.
Psycopg 2
This is a Postgres database adaptor for Python that Trac uses.
Here is latest version of psycopg 2
Installation is simple:
% python setup.py build
% sudo python setup.py install
Trac
Installing trac itself is pretty easy. It’s another case of running “python setup.py install” as root and hoping it does the right thing. In this case there’s one small hitch—it wants to put the man pages and wiki templates in /System/Library/Frameworks/Python.framework/Versions/2.5. (This is sys.prefix). setup.py uses distutils, and I couldn’t figure out if you can use a command-line argument to fix it (–prefix=/usr/local didn’t do the right thing), so here’s the least invasive solution I found:
# cd /System/Library/Frameworks/Python.framework/Versions/2.5
# ln -s /usr/local/share
# chmod -h 777 share
(Yes, symbolic links have had permissions since 10.4, and now we can change their permissions after they’ve been created.)
# python setup.py install
This should put tracd and trac-admin in /usr/local/bin, and the python packages in /Library/Python/2.5/site-packages, and the trac page templates in /usr/local/share/trac/templates.
Testing Trac
Create a trac database user, if necessary:
% sudo -u postgres psql
postgres=# create user trac password 'tracpassword';
postgres=# \du (to list the users)
postgres=# create database "trac-test1" owner trac;
postgres=# \l (to list the databases)
postgres=# \q
Create a test environment and run tracd to see if it works:
% trac-admin /tmp/test1 initenv
% tracd --port 8000 /tmp/test1
From there, configure trac the way you want it. The postgres connection string looks something like “postgres://trac:tracpassword@127.0.0.1/trac-test1″.
Starting Trac Automatically
There are a few options on running Trac. I use tracd, which is very simple and works well for a single developer.
Here’s a configuration for a trac launch agent. Save this file as ~/Library/LaunchAgents/org.edgewall.trac.plist and it will automatically start trac when you log in.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>EnvironmentVariables</key>
<dict>
<key>LC_TIME</key>
<string>en_CA</string>
</dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>org.edgewall.trac</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/tracd</string>
<string>--port</string>
<string>8000</string>
<string>--auth</string>
<string>*,/usr/local/trac/users.htdigest,example.com</string>
<string>/usr/local/trac/test1</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>UserName</key>
<string>nygard</string>
</dict>
</plist>
Trac makes it extremely difficult to change the date format. They expect you to find some other language that uses the date format you want, and then set the LC_TIME environment variable. In my case, I want dates like 2007-10-31, and I couldn’t find anything matching that. So, I set LC_TIME to en_CA, and then edit the date format in the system locale. That is, I make a copy of /usr/share/locale/en_CA/LC_TIME (it’s a symlink), and change %d/%m/%Y to %Y-%m-%d.
You can use locale LC_TIME to see the formats for your current locale.
The program arguments are the ones you use on the command line. Be sure you don’t use -d, since daemons started by launchd must not daemonize themselves. RunAtLoad makes it start when you log in, and UserName will run it as the specified user.
Since you’re already logged in, you can start it now with launchctl load org.edgewall.trac.plist. launchctl automatically searches for the file and finds it in ~/Library/LaunchAgents. Since RunAtLoad is true, we don’t need to use launchctl start org.edgewall.trac (this is the Label from the .plist) to start it—it starts as soon as it’s loaded. You can see what’s loaded with launchctl load
Backing up
I’ll update this part after I’ve set it up.
Disabling accesskeys
[Update: 2007-11-15] Here’s one last thing I forgot about. HTML has a terrible misfeature called accesskeys. You can use an accesskey attribute on anchors and input elements, and then pressing control and that key will, for example, move the focus to the input, or activate the link. Safari has no option do disable this. What this means is that the standard system-wide control-key combinations that you use for editing text can be usurped by a web page to do something totally unexpected and undesired.
The solution for a local Trac installation is simple enough. Search the python code for any reference to “accesskey” and remove it. It’s probably best to do this before you install it, so that the .pyc files get the update too. Next you have to do the same for all of the template files.
For non-local sites accesskeys are more of a problem. I’ve gone as far as replacing all “accesskey” strings in Safari and it’s supporting frameworks with a different name of the same length, but it wasn’t successful.