Mar 5, 2009 0
Apr 27, 2008 1
Setting up Mercurial on Dreamhost
Since this post I discovered git and github – you should too!
These instructions are really for my own benefit. I have an old Dreamhost account that I still have a few sites hosted on (including this one), although they have periods of downtime it is still good value for money, especially on non-essential sites.
One thing I use my Dreamhost space for is hosting Subversion repositories. As the recent buzz seems to have been surrounding Git, I decided it was time to dabble with Mercurial. Go figure!
If anyone else does stumble across these instructions, you may want to look at this article and this page of the Dreamhost wiki. The instructions below are essentially a re-hashing of these articles but a bit more idiot proof for those, like me, who are not overly familiar with the command line
First thing to do is to use terminal to SSH into your shell. In the home directory we will create a new (hidden)directory and download the most recent version of Mercurial.
$ mkdir -p ~/.packages/src
$ cd ~/.packages/src
$ wget http://www.selenic.com/mercurial/release/mercurial-1.0.tar.gz
$ tar xvzf mercurial-1.0.tar.gz
$ cd mercurial-1.0
$ python setup.py install --home=~/.packages/
Edit the .bash_profile and the .bash_src files and add the following lines to each:
export PYTHONPATH=${HOME}/.packages/lib/python
export PATH=${HOME}/.packages/bin:$PATH
Reload the changed files and use Mercurial’s version command to check it is installed. If successful you’ll get a copyright notice and some other stuff displayed.
$ . ~/.bash_profile
$ . ~/.bash_src
$ hg version
Now create a new folder to store our repositories in. And create our initial Test repository
$ mkdir .mercurial
$ hg init .mercurial/phoneslip
This is where i started to get confused! We need to edit a few initial proporties of the repository. This is done by means of the cat command to edit these files on the fly. Alternatively you could create the files in the relevant directory. After the first line it looks like nothing happens but continue inputting and end input with [control + D]
I put my name as the contact. allow_push sets which shell users can push to the repositories, in this instance just me.
$ cat > ~/.mercurial/hgweb.config
[web]
contact = Alan Wallace
description = Project Path Test
style = gitweb
push_ssl = false
allow_push = alshie
⌃D
Now to set-up web viewing of repositories.
$ cd domainname.com
$ mkdir hg
$ cd hg
$ cat > hgweb.config
[collections]
/home/alshie/.mercurial = /home/alshie/.mercurial
⌃D
Create a hgwebdir.cgi file in the same directory and add the below to its contents.
#!/usr/bin/env python
# send python tracebacks to the browser if an error occurs:
import cgitb
cgitb.enable()
# adjust python path if not a system-wide install:
import sys
sys.path.insert(0, "/home/alshie/.packages/lib/python")
import os
os.environ["HGENCODING"] = "UTF-8"
from mercurial.hgweb.hgwebdir_mod import hgwebdir
from mercurial.hgweb.request import wsgiapplication
import mercurial.hgweb.wsgicgi as wsgicgi
def make_web_app():
return hgwebdir("hgweb.config")
wsgicgi.launch(wsgiapplication(make_web_app))
Change the permissions of the hgwebdir.cgi file
$ chmod 755 hgwebdir.cgi
Create an .htaccess file in the hg directory with the below as its contents.
Options +ExecCGI
RewriteEngine On
RewriteBase /hg
RewriteRule ^$ hgwebdir.cgi [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) hgwebdir.cgi/$1 [QSA,L]
AuthUserFile /home/alshie/.htpasswd
AuthGroupFile /dev/null
AuthName "Mercurial Repository"
AuthType Basic
Require valid-user
Finally create the .htpasswd file in your home directory
touch ~/.htpasswd
htpasswd -sb ~/.htpasswd USERNAME PASSWORD
You should now have a working Mercurial setup with web viewing, your mileage may vary! I’m currently looking into making the web view less sucky.


