ArchLinux 2017.10.01: Install Trac for project management

This article will describe installing Trac which manages user with digest authentication.

1 Install Trac

The following script will install Trac and create "test" project.

  • Login to Trac via digest authentication.
  • ADMIN_PASSWD is password of admin user for digest authentication.
  • USER_NAME is user name of not admin user for digest authentication.
  • USER_PASSWD is password name of not admin user for digest authentication.
#!/bin/sh

set -e

[ -z "${ADMIN_PASSWD}" ] && ADMIN_PASSWD="admin_passwd"
[ -z "${USER_NAME}" ] && USER_NAME="guest"
[ -z "${USER_PASSWD}" ] && USER_PASSWD="guest_passwd"

apache_install()
{
  # mod_wsgi2 supports python 2.7 which is used by trac.
  sudo pacman -Sy --noconfirm apache mod_wsgi2
  sudo systemctl enable httpd

  # ssl configuration.
  # Country Name (2 letter code) [AU]:
  # State or Province Name (full name) [Some-State]:
  # Locality Name (eg, city) []:
  # Organization Name (eg, company) [Internet Widgits Pty Ltd]:
  # Organizational Unit Name (eg, section) []:
  # Common Name (e.g. server FQDN or YOUR name) []:
  # Email Address []:
  cat <<EOF | sudo openssl req -new -x509 -nodes -newkey rsa:4096 -days 1095 \
                   -keyout /etc/httpd/conf/server.key \
                   -out /etc/httpd/conf/server.crt
AU
Some-State
city
company
section


EOF
  sudo sed -i /etc/httpd/conf/httpd.conf \
       -e 's/^#LoadModule ssl_module/LoadModule ssl_module/g' \
       -e 's/^#LoadModule socache_shmcb_module/LoadModule socache_shmcb_module/g'
  cat <<EOF | sudo tee -a /etc/httpd/conf/httpd.conf
Include conf/extra/httpd-ssl.conf
EOF

  # rewrite configuration.
  sudo sed -i /etc/httpd/conf/httpd.conf \
       -e 's/^#LoadModule rewrite_module/LoadModule rewrite_module/g'
  cat << EOF | sudo tee /etc/httpd/conf/extra/redirect-to-https.conf
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}
EOF
  cat <<EOF | sudo tee -a /etc/httpd/conf/httpd.conf
Include conf/extra/redirect-to-https.conf
EOF

  # digest configuration.
  sudo sed -i /etc/httpd/conf/httpd.conf \
       -e 's/#LoadModule auth_digest_module/LoadModule auth_digest_module/g'

  # wsgi configuration.
  cat <<EOF | sudo tee -a /etc/httpd/conf/httpd.conf
LoadModule wsgi_module modules/mod_wsgi.so
EOF

  sudo systemctl restart httpd
}

trac_install()
{
  sudo pacman -Sy --noconfirm trac
  sudo systemctl enable httpd
  sudo mkdir /var/lib/trac
  sudo mkdir /srv/http/trac
  sudo chown http:http /srv/http/trac
}

create_project()
{
  proj=$1

  sudo trac-admin /var/lib/trac/"${proj}" initenv "${proj}" sqlite:db/trac.db
  sudo trac-admin /var/lib/trac/"${proj}" deploy /srv/http/trac/"${proj}"
  sudo chown -R http:http /var/lib/trac/"${proj}"
  sudo chown -R http:http /srv/http/trac/"${proj}"

  yes "${ADMIN_PASSWD}" | \
    sudo htdigest -c /var/lib/trac/"${proj}"/.htdigest "${proj}" admin
  sudo trac-admin /var/lib/trac/"${proj}" permission add admin TRAC_ADMIN

  yes "${USER_PASSWD}" | \
    sudo htdigest /var/lib/trac/"${proj}"/.htdigest "${proj}" "${USER_NAME}"

  cat <<EOF | sudo tee /etc/httpd/conf/extra/${proj}.conf
WSGIScriptAlias /trac/${proj} /srv/http/trac/${proj}/cgi-bin/trac.wsgi
<Location /trac/${proj}>
  AuthType Digest
  AuthName "${proj}"
  AuthUserFile /var/lib/trac/${proj}/.htdigest
  Require valid-user
</Location>
EOF
  cat <<EOF | sudo tee -a /etc/httpd/conf/httpd.conf
Include conf/extra/${proj}.conf
EOF

  sudo systemctl restart httpd
}

trac_main()
{
  apache_install
  trac_install
  create_project test
  create_project OtherProject
}

trac_main

2 Access to Trac

Access the following URL with browser. Accept this page's certification to browser.

https://<server>/trac/test

The dialog of digest authentication is displayed. Input admin to Username and ADMIN_PASSWD value to Password.

0001_DigestAuth.png

Trac page is displayed.

0002_Trac.png