Installing Mercurial Without Admin Rights And No C Compiler

Cheap webhosters can be pretty limiting sometimes in the platforms they run and the software packages on offer, even when you do have shell access. Here's a quick guide to setting Mercurial up on a shared webhost for use when:

Prerequisites

To build Mercurial plus its documentation (e.g. build all), you need to have the Python doctools package.  To most easily install the doctools package, it helps to have the Python easy_install package.

easy_install

It's best to choose one directory where all of your Python eggs and modules will live. In my case, I chose "~/software", which means the software directory under my home directory.

wget http://pypi.python.org/packages/2.5/s/setuptools/setuptools-0.6c11-py2.5.egg
sh setuptools-0.6c11-py2.5.egg --prefix=~/software

The first time you run the setuptools install, it may complain about the installation directory not existing:

vilimpoc@funky:~/software$ sh setuptools-0.6c11-py2.5.egg --prefix=~/software

    error: can't create or remove files in install directory

The following error occurred while trying to add or remove files in the installation directory:

    [Errno 2] No such file or directory:
    '/home/vilimpoc/software/lib/python2.5/site-packages/test-easy-install-12006.pth'

The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

    /home/vilimpoc/software/lib/python2.5/site-packages

This directory does not currently exist.  Please create it and try again, or choose a different installation directory (using the -d or --install-dir option).

So create the directory:

mkdir -p /home/vilimpoc/software/lib/python2.5/site-packages
export PYTHONPATH=/home/vilimpoc/software/lib/python2.5/site-packages

Then run setuptools again:

sh setuptools-0.6c11-py2.5.egg --prefix=~/software

The second time you should see something like:

Processing setuptools-0.6c11-py2.5.egg
Removing /home/vilimpoc/software/lib/python2.5/site-packages/setuptools-0.6c11-py2.5.egg
Copying setuptools-0.6c11-py2.5.egg to /home/vilimpoc/software/lib/python2.5/site-packages
setuptools 0.6c11 is already the active version in easy-install.pth
Installing easy_install script to /home/vilimpoc/software/bin
Installing easy_install-2.5 script to /home/vilimpoc/software/bin

Installed /home/vilimpoc/software/lib/python2.5/site-packages/setuptools-0.6c11-py2.5.egg
Processing dependencies for setuptools==0.6c11
Finished processing dependencies for setuptools==0.6c11
vilimpoc@funky:~/software$

Make the easy_install command available by exporting its directory to your PATH:

export PATH=${PATH}:/home/vilimpoc/software/bin

Now you can run easy_install from everywhere, but you have to always remember to provide the install prefix you chose for where your python modules should live.

docutils

easy_install --prefix=~/software docutils

Searching for docutils
Reading http://pypi.python.org/simple/docutils/
Reading http://docutils.sourceforge.net/
Best match: docutils 0.7
Downloading http://prdownloads.sourceforge.net/docutils/docutils-0.7.tar.gz?download
Processing docutils-0.7.tar.gz
Running docutils-0.7/setup.py -q bdist_egg --dist-dir /tmp/easy_install-UeCHaD/docutils-0.7/egg-dist-tmp-LsTUG-
warning: no files found matching 'MANIFEST'
warning: no previously-included files matching '.cvsignore' found under directory '*'
warning: no previously-included files matching '*.pyc' found under directory '*'
warning: no previously-included files matching '*~' found under directory '*'
warning: no previously-included files matching '.DS_Store' found under directory '*'
zip_safe flag not set; analyzing archive contents...
docutils.parsers.rst.directives.misc: module references __file__
docutils.writers.html4css1.__init__: module references __file__
docutils.writers.latex2e.__init__: module references __file__
docutils.writers.newlatex2e.__init__: module references __file__
docutils.writers.odf_odt.__init__: module references __file__
docutils.writers.pep_html.__init__: module references __file__
docutils.writers.s5_html.__init__: module references __file__
Adding docutils 0.7 to easy-install.pth file
Installing rst2html.py script to /home/vilimpoc/software/bin
Installing rst2latex.py script to /home/vilimpoc/software/bin
Installing rst2man.py script to /home/vilimpoc/software/bin
Installing rst2newlatex.py script to /home/vilimpoc/software/bin
Installing rst2odt.py script to /home/vilimpoc/software/bin
Installing rst2odt_prepstyles.py script to /home/vilimpoc/software/bin
Installing rst2pseudoxml.py script to /home/vilimpoc/software/bin
Installing rst2s5.py script to /home/vilimpoc/software/bin
Installing rst2xml.py script to /home/vilimpoc/software/bin
Installing rstpep2html.py script to /home/vilimpoc/software/bin

Installed /home/vilimpoc/software/lib/python2.5/site-packages/docutils-0.7-py2.5.egg
Processing dependencies for docutils
Finished processing dependencies for docutils

Mercurial

Now that docutils is installed in your private Python packages, you can move on to installing Mercurial.

vilimpoc@funky:~/software/mercurial-1.6.3$ make PURE=--pure all
vilimpoc@funky:~/software/mercurial-1.6.3$ make PURE=--pure HOME=~/software install-home

Then you just have to move the Mercurial directories into the site-packages directory.

vilimpoc@funky:~/software/lib/python2.5$ ls
hgext  mercurial  mercurial-unknown.egg-info  site-packages
vilimpoc@funky:~/software/lib/python2.5$ mv hgext site-packages/
vilimpoc@funky:~/software/lib/python2.5$ mv mercurial site-packages/
vilimpoc@funky:~/software/lib/python2.5$ mv mercurial-unknown.egg-info site-packages/
vilimpoc@funky:~/software/lib/python2.5$ cd ~
vilimpoc@funky:~$ hg
Mercurial Distributed SCM

basic commands:

 add        add the specified files on the next commit
 annotate   show changeset information by line for each file
 clone      make a copy of an existing repository
 commit     commit the specified files or all outstanding changes
 diff       diff repository (or selected files)
 export     dump the header and diffs for one or more changesets
 forget     forget the specified files on the next commit
 init       create a new repository in the given directory
 log        show revision history of entire repository or files
 merge      merge working directory with another revision
 pull       pull changes from the specified source
 push       push changes to the specified destination
 remove     remove the specified files on the next commit
 serve      start stand-alone webserver
 status     show changed files in the working directory
 summary    summarize working directory state
 update     update working directory (or switch revisions)

use "hg help" for the full list of commands or "hg -v" for details

vilimpoc@funky:~$

Using Mercurial

Now you have a fully-functional Mercurial install that you can use, for instance, to locally revision control content in your webdirectories.

e.g. You have a simple website in public_html, you can do something like:

cd ~/public_html
hg init
hg add
hg commit

Now your changes will be tracked, how sweet is that?