I’ve made a few updates to the original AutoTracOnDreamHost. They are:
- Bumped up to Trac 0.11.2, just released last weekend.
- The python version you use is now a config option in configure.inc – though Trac 0.11.2 proper requires python2.4, this is expected to be fixed in Trac 0.11.2.1.
- If DH has installed setuptools on your machine, now AutoTracOnDreamHost doesn’t use it, as it may be too far out of date to install the latest and greatest mysqldb, genshi, or pygments.
- Minor edits to the README.
Questions? Bugs? Please use the comments. Enjoy!
README:
AutoTracOnDreamHost: README
#################### LICENSE #####################
AutoTracOnDreamHost is free software: you can redistribute
it and/or modify it under the terms of the GNU General Public
License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
http://www.gnu.org/licenses/gpl-3.0.html
#################### HowTo #######################
Preliminaries:
1. Assuming you're going to use this with SVN, you need to already
have an SVN repository setup and running. The webserver needs
to have at least read permissions to the repository.
2. You need to have a complete domain/subdomain set up to use
with trac or a subdirectory of an existing domain.
3. A MySQL database ready to use with trac. This doesn't have to
be it's own database, but AFAIK, there is no good reason not
to give each trac site it's own database.
4. Trac 0.11.2.0 requires python 2.4, not 2.3. Trac 0.11.2.1 (not
out as of this writing) should fix this
(http://trac.edgewall.org/ticket/7801).
5. To avoid permission failings by apache, it's best to install this
using the same user as you have apache doing it's cgi stuff under (If
you didn't change anything from the dreamhost default - then you have
only one user and you can ignore this step.)
Do once:
1. Edit the configure.inc:
- you probably want the latest and greatest of Trac, Genshi,
MySQLDB, and Pygments. Minor version releases of these
shouldn't break this script.
- alter the trac directory structure to your liking, or just
run with my setup.
2. Run the backend.sh. This will set up all the parts of trac that
are shared between all your trac sites (even if you have only one).
Do once per trac site:
1. Run the site.sh. This script will query you for details about
the configuration of your database, your directory structure,
svn repository, an admin trac user etc.
2. Test it! Go to your new trac url and log in, browse the svn
repository, create a dummy ticket etc.
#################### Help Me! ####################
I'll post about any major updates or known bugs on my blog.
http://blog.fogel.ca In event of enough interest in these
scripts, I'll set up a public repository for it so we can
all contribute.
If you find any major bugs or want to submit a patch, you can
email me which is my first name (mike) at my domain (fogel.ca).
Requests for personalized help will be answered in the limit
of infinite free time, which I don't have, so no promises.
Elsewise, the best conglomeration of information about Trac
on DreamHost AFAIK is currently at on the DreamHost wiki.
http://wiki.dreamhost.com/Trac
##################################################
configure.inc:
# AutoTracOnDreamHost: configure.inc
# Released under GLPv3. http://www.gnu.org/licenses/gpl-3.0.html
# Copyright 2008 Michael Fogel. http://fogel.ca
# Abort on any errors
set -e
PYTHON_VERS=2.4
TRAC_VERS=0.11.2
GENSHI_VERS=0.5.1
MYSQLDB_VERS=1.2.2
PYGMENTS_VERS=0.11.1
# trac dir structure
TRAC_ROOT="${HOME}/trac"
PKG=${TRAC_ROOT}/packages
EGG=${TRAC_ROOT}/egg_cache
INSTALL=${TRAC_ROOT}/install
SITES=${TRAC_ROOT}/sites
SVN=${HOME}/svn
TRAC_SITE_PACKAGES=${PKG}/lib/python${PYTHON_VERS}/site-packages
TRAC_HTDOCS=${TRAC_SITE_PACKAGES}/Trac-${TRAC_VERS}-py${PYTHON_VERS}.egg/trac/htdocs
EXP_CMD1="export PYTHONPATH=$TRAC_SITE_PACKAGES"
EXP_CMD2="export PYTHON_EGG_CACHE=$EGG"
EXP_CMD3="export LD_LIBRARY_PATH=$PKG/lib"
EXP_CMD4="export PATH=$PKG/bin:\$PATH"
cat <<OutputDreamTracInstallReminder
==== Put the following in your ~/.bash_profile ====
Where trac/packages=PKG
$EXP_CMD1
$EXP_CMD2
$EXP_CMD3
$EXP_CMD4
===================================================
OutputDreamTracInstallReminder
# modify those env vars for the duration of this script too.
$EXP_CMD1
$EXP_CMD2
$EXP_CMD3
if [[ "$PATH" != *"$PKG/bin"* ]]; then export PATH=$PKG/bin:$PATH; fi
# Update version information here and DIRs below.
TRAC=http://ftp.edgewall.com/pub/trac/Trac-${TRAC_VERS}.tar.gz
GENSHI=http://ftp.edgewall.com/pub/genshi/Genshi-${GENSHI_VERS}.tar.gz
SETUPTOOLS=http://peak.telecommunity.com/dist/ez_setup.py
MYSQLDB=http://switch.dl.sourceforge.net/sourceforge/mysql-python/MySQL-python-${MYSQLDB_VERS}.tar.gz
PYGMENTS=http://pypi.python.org/packages/source/P/Pygments/Pygments-${PYGMENTS_VERS}.tar.gz
TRACDIR=Trac-${TRAC_VERS}
GENSHIDIR=Genshi-${GENSHI_VERS}
MYSQLDBDIR=MySQL-python-${MYSQLDB_VERS}
PYGMENTSDIR=Pygments-${PYGMENTS_VERS}
#### function getInupt - used primarily in site.sh #####
# arg 1: message
# arg 2: initial value
function getInput {
MES="$1"
eval "VAL=\$$2"
echo ""
echo "Press enter to accept the current value, or input a new value."
TMP="$VAL"
while [[ -n "$TMP" ]]; do
VAL="$TMP"
echo "$MES: $VAL"
read TMP
done
echo "Using $MES: $VAL"
eval "$2=\"$VAL\""
}
backend.sh:
# AutoTracOnDreamHost: backend.sh
# Released under GLPv3. http://www.gnu.org/licenses/gpl-3.0.html
# Copyright 2008 Michael Fogel. http://fogel.ca
source ./configure.inc
echo -e "\n==== Creating need dir structure ===="
[ ! -d ${PKG} ] && mkdir -p ${PKG}
# the egg_cache dir must be writable by your apache cgi/python user
[ ! -d ${EGG} ] && mkdir -p ${EGG} && chmod 770 ${EGG}
[ ! -d ${INSTALL} ] && mkdir -p ${INSTALL}
[ ! -d ${SITES} ] && mkdir -p ${SITES}
echo -e "\n==== Retrieving installation files ===="
cd ${INSTALL}
[ ! -f ${TRACDIR}.tar.gz ] && wget ${TRAC}
[ ! -f ${GENSHIDIR}.tar.gz ] && wget ${GENSHI}
[ ! -f ${MYSQLDBDIR}.tar.gz ] && wget ${MYSQLDB}
[ ! -f ${PYGMENTSDIR}.tar.gz ] && wget ${PYGMENTS}
[ ! -f ez_setup.py ] && wget ${SETUPTOOLS}
echo -e "\n==== Installing Setup Tools ===="
#Create site-packages directory. Script will fail without it.
mkdir -p ${TRAC_SITE_PACKAGES}
cd ${INSTALL} && python ez_setup.py --prefix=${PKG}
echo -e "\n==== Installing Pygments ===="
cd ${INSTALL} && tar xzf ${PYGMENTSDIR}.tar.gz
cd ${PYGMENTSDIR} && python setup.py install --prefix=${PKG}
echo -e "\n==== Installing MYSQLdb ===="
cd ${INSTALL} && tar xzf ${MYSQLDBDIR}.tar.gz
cd ${MYSQLDBDIR} && python setup.py install --prefix=${PKG}
echo -e "\n==== Installing Genshi ===="
cd ${INSTALL} && tar xzf ${GENSHIDIR}.tar.gz
cd ${GENSHIDIR} && python setup.py install --prefix=${PKG}
echo -e "\n==== Installing Trac ===="
cd ${INSTALL} && tar xzf ${TRACDIR}.tar.gz
cd ${TRACDIR} && python setup.py install --prefix=${PKG}
mkdir -p ${PKG}/share/trac
cp -fr ${INSTALL}/${TRACDIR}/cgi-bin ${PKG}/share/trac
echo -e "\n==== Setting permissions for Trac htdocs ===="
DIR=${TRAC_HTDOCS}
while [ "$DIR" != "$HOME" ]; do
chmod o+x $DIR
DIR=`dirname $DIR`
done
find ${TRAC_HTDOCS} -type d -exec chmod 751 {} \;
find ${TRAC_HTDOCS} -type f -exec chmod 644 {} \;
echo -e "\n==== Backend install complete ===="
site.sh:
# AutoTracOnDreamHost: site.sh
# Released under GLPv3. http://www.gnu.org/licenses/gpl-3.0.html
# Copyright 2008 Michael Fogel. http://fogel.ca
source ./configure.inc
# Prompt for project parameters, with defaults
PROJECT=somesvnproject; getInput "Subversion Project ID" PROJECT
DOMAIN=trac.somedomain.com; getInput "Domain for Trac" DOMAIN
DOMAINDIR=${HOME}/http/$DOMAIN; getInput "Path for domain root" DOMAINDIR
TRACPATH=/trac; getInput "Relative Path for Trac" TRACPATH
MYSQLHOST=mysql.$DOMAIN; getInput "MySQL hostname" MYSQLHOST
MYSQLUSER=trac_username; getInput "MySQL username" MYSQLUSER
MYSQLPASSWD=trac_password; getInput "MySQL password" MYSQLPASSWD
MYSQLDBNAME=trac_$PROJECT; getInput "MySQL DB name" MYSQLDBNAME
TRAC_USER=admin; getInput "Trac Admin username" TRAC_USER
TRAC_PASSWORD=password; getInput "Trac Admin password" TRAC_PASSWORD
# confirm those values
echo "Please confirm the values you entered:"
echo "PROJECT:${PROJECT}"
echo "DOMAIN:${DOMAIN}"
echo "DOMAINDIR:${DOMAINDIR}"
echo "TRACPATH:${TRACPATH}"
echo "MYSQLHOST:${MYSQLHOST}"
echo "MYSQLUSER:${MYSQLUSER}"
echo "MYSQLPASSWD:${MYSQLPASSWD}"
echo "MYSQLDBNAME:${MYSQLDBNAME}"
echo "TRAC_USER:${TRAC_USER}"
echo "TRAC_PASSWORD:${TRAC_PASSWORD}"
echo "Look good?"
lookingGood=Yes;
getInput "Looking good? 'Yes' to continue, all else to quit." lookingGood
[ "$lookingGood" != "Yes" ] && exit 1;
# Vars for this site
WEBDIR=${DOMAINDIR}/${TRACPATH}
INDEX_CGI=${WEBDIR}/index.cgi
TRACINI=${SITES}/${PROJECT}/conf/trac.ini
HTACCESS=${WEBDIR}/.htaccess
HTPASSWD=${WEBDIR}/.htpasswd
NAME="Trac: ${DOMAIN}${TRACPATH}/"
echo "Setup site"
if [ ! -d ${SITES}/${PROJECT} ]; then
#Setup Trac Environment for MySQL
${PKG}/bin/trac-admin ${SITES}/${PROJECT} \
initenv ${PROJECT} \
"mysql://${MYSQLUSER}:${MYSQLPASSWD}@${MYSQLHOST}/${MYSQLDBNAME}" \
svn \
${SVN}/${PROJECT};
# set admin user to premissions
${PKG}/bin/trac-admin ${SITES}/${PROJECT} \
permission add $TRAC_USER TRAC_ADMIN
fi
echo "Make Trac Web Accessible"
# Make Trac Web Accessible
mkdir -p ${WEBDIR}
chmod 751 ${WEBDIR}
if [ -f "${INDEX_CGI}" ]; then
rm ${INDEX_CGI}
fi
echo "#!/bin/bash" >> ${INDEX_CGI}
echo "export HOME=\"/home/${USER}\"" >> ${INDEX_CGI}
echo "export TRAC_ENV=\"$SITES/${PROJECT}\"" >> ${INDEX_CGI}
echo "$EXP_CMD1" >> ${INDEX_CGI}
echo "$EXP_CMD2" >> ${INDEX_CGI}
echo "$EXP_CMD3" >> ${INDEX_CGI}
echo "$EXP_CMD4" >> ${INDEX_CGI}
echo "exec $PKG/share/trac/cgi-bin/trac.cgi" >> ${INDEX_CGI}
chmod 755 ${INDEX_CGI}
# logo in trac.ini
sed -i "s/^alt = .*$/alt = trac_banner.png/" ${TRACINI}
# some fancy sed to escape forward slashes... simplier patches are welcome.
TRACPATH_S=`echo ${TRACPATH} | sed -e "s/\/$//" -e "s/\//\\\\\\ \//g" -e "s/ \//\//g"`
sed -i "s/^src = .*$/src = ${TRACPATH_S}\/chrome\/common\/trac_banner.png/"${TRACINI}
#Pretty URLs
mkdir -p ${WEBDIR}/chrome
chmod 751 ${WEBDIR}/chrome
ln -sf ${TRAC_HTDOCS} ${WEBDIR}/chrome/common
# .htaccess fun
if [ -f ${HTACCESS} ]; then
rm ${HTACCESS}
fi
touch ${HTACCESS}
chmod 644 ${HTACCESS}
echo "AuthType Basic" >> ${HTACCESS}
echo "AuthUserFile ${HTPASSWD}" >> ${HTACCESS}
echo "AuthName '${NAME}'" >> ${HTACCESS}
echo "require valid-user" >> ${HTACCESS}
echo "" >> ${HTACCESS}
echo "DirectoryIndex index.cgi" >> ${HTACCESS}
echo "Options ExecCGI FollowSymLinks" >> ${HTACCESS}
echo "" >> ${HTACCESS}
echo "" >> ${HTACCESS}
echo "RewriteEngine On" >> ${HTACCESS}
echo "RewriteCond %{REQUEST_FILENAME} !-f" >> ${HTACCESS}
echo "RewriteCond %{REQUEST_FILENAME} !-d" >> ${HTACCESS}
echo "RewriteRule ^(.*)\$ ${TRACPATH}/index.cgi/\$1 [L]" >> ${HTACCESS}
echo "" >> ${HTACCESS}
#Create .htpasswd file for trac admin with password
htpasswd -bc ${HTPASSWD} $TRAC_USER "$TRAC_PASSWORD"
# Note: on DreamHost you avoid a world-readable htpasswd file by
# setting one up via panel.dreamhost.com->Goodies->Htaccess/WebDAV.
# This will make htpasswd and htaccess files (overwriting anything
# that's there) that has group dhapache, is group readable, and
# the apache user is in the dhapache group. Baring this, you need
# to make your htpasswd file word-readable (or email support for
# some chgrp action as root)
chmod 644 ${HTPASSWD}
echo ---------- SITE INSTALL COMPLETE! ----------
[...] Update: I’ve released an updated version of AutoTracOnDreamHost. [...]
Thanks for such a nice script. After about 3 hours using netmaster’s instructions step by step and failing, I ended up on you holy-grail-script. It worked, or kinda… I’m wondering what I’m missing, if it’s in the configure.inc or in the site.sh configuration. You can visit on http://dev.protonian.com and see for yourself – it looks awkard. I know the tutorial says minimalistic, but to the point where there are no other pages or logos? Hmmm…
It look like the trac-admin tool is also giving some issues…
Traceback (most recent call last):
File “./trac-admin”, line 5, in ?
from pkg_resources import load_entry_point
File “/usr/lib/python2.4/site-packages/pkg_resources.py”, line 2479, in ?
working_set.require(__requires__)
File “/usr/lib/python2.4/site-packages/pkg_resources.py”, line 585, in require
needed = self.resolve(parse_requirements(requirements))
File “/usr/lib/python2.4/site-packages/pkg_resources.py”, line 483, in resolve
raise DistributionNotFound(req) # XXX put more info here
pkg_resources.DistributionNotFound: Trac==0.11.2
UPDATE:
Well fogel, I’m glad to announce that after 10 straight hours into installing I finally made it !
I wen’t back and tried Dreamhost’s other script, and after it didn’t work I had two options, or doing it a la netmaster again, or just doing my own script, which had more sense. In the process of looking at each one of the scripts I saw yours was pretty complete and much more clean than dreamhost’s. Reading line by line I noticed the line that bash was choking on (around 81). It was the sed command’s fault apparently, when I commented sed out, the script finished completely and all the world suddently looked beautifull.
Thanks for introducing us to Trac. Now I shall be on my way into some Genshi hacking :P
@ Alexander:
Is that line 81 in site.sh…
sed -i “s/^src = .*$/src = ${TRACPATH_S}\/chrome\/common\/trac_banner.png/” ${TRACINI}
that’s crapping out for you? That is just to set up the little trac icon in the top left… pretty unnecessary. Do you have a version of that line that works on your setup? If so I’ll test it on mine and if it works also then I’ll throw it in there.
Glad the script was helpful. It sounds like you went through pretty much the same process I did when trying to set up trac… lots of learning and re-writing the existing ‘auto’ installs out there.
Hi,
I was having troubles installing Trac on Dreamhost until I found your scripts. Thank you so much for the help. However, when I go to my trac page I get prompted for Authentication. Is there a setting somewhere I need to change to allow anonymous access to view the main page and wiki’s?
This is what I get when I execute the following.
trac-admin /path permission list
User Action
——————————
admin TRAC_ADMIN
anonymous BROWSER_VIEW
anonymous CHANGESET_VIEW
anonymous FILE_VIEW
anonymous LOG_VIEW
anonymous MILESTONE_VIEW
anonymous REPORT_SQL_VIEW
anonymous REPORT_VIEW
anonymous ROADMAP_VIEW
anonymous SEARCH_VIEW
anonymous TICKET_VIEW
anonymous TIMELINE_VIEW
anonymous WIKI_VIEW
authenticated TICKET_CREATE
authenticated TICKET_MODIFY
authenticated WIKI_CREATE
authenticated WIKI_MODIFY
@ Phantamith:
At the end of site.sh you’ll see the lines
#Create .htpasswd file for trac admin with password htpasswd -bc ${HTPASSWD} $TRAC_USER “$TRAC_PASSWORD”
Those should have created an .htpasswd file for whatever you set TRAC_USER and TRAC_PASSWORD to in the interactive part. That’s what trac is using for authentication. If you didn’t change them, the defaults are
TRAC_USER=admin;
TRAC_PASSWORD=password;
You want to make sure your .htpasswd and .htaccess files are readable by the dreamhost apache user. Beyond that, it should work.
‘man htpasswd’ for more details.
@Michael
Yes I did happen to see that, I am having no problems authenticating. However was wondering if I could open my trac site up so that users wouldn’t have to logon to simply view the Trac Site, though I would still require users to logon if they needed to create/modify tickets, wiki’s, etc…
Thanks
Phantamith
@Phantamith
Ah, sorry understood now. I think you’ve got to install some more advanced user management plugin to get that behavior. Under the current setup you could have a user ‘anonymous’ with password ‘password’ that has no permission to make tickets etc – but users would still have to login as ‘anonymous’ to just browse around. I believe this will be the case as long as you’re doing the basic .htaccess/.htpasswd authentication.
Cheers
Mike
Many many thanks for this. I had to comment out line 81 for the sed error too, but it went past it.
BTW, is there a way to make this use fcgi instead of cgi? Is it a question of renaming index.cgi to index.fcgi and updating the .htaccess file?