Installation of Mercurial (Hg) on BlueHost

This is a guide on how to install Mercurial to your BlueHost site.
The guide is mostly written as a reminder to myself on how I did it. If you use this guide and want changes or other features, you could use the forum or google
Basic Authentication is used for the repositories (normal linux password file)

commands to run directly from the prompt is in this format (of course, after changing the values that needs changing )
text to enter or edit in files is in this format
Text you need to change is in this format

Before you start:

You need ssh access to your BlueHost account and you should also know how to use nano (or any other text editor from command line)

  1. Update your .bash_profile file
  2. Update your .bashrc file

1. Update your .bash_profile file (and add/modify these 3 lines)

nano ~/.bash_profile

Enter these 3 lines, or edit them if you find them there already
export LD_LIBRARY_PATH="$HOME/packages/lib:$LD_LIBRARY_PATH"
export PYTHONPATH="$HOME/packages/lib/python2.3/site-packages:$PYTHONPATH"
export PATH="$HOME/packages/bin:$HOME/bin:$PATH"

source ~/.bash_profile

2. Update your .bashrc file

nano ~/.bashrc

Add or edit this line
PATH=$PATH:$HOME/bin:$HOME/packages/mercurial

source ~/.bashrc


Mercurial installation:

1.Get mercurial and install

This part does everything except initializing the repository, creating the password file and initialize the projects

cd
mkdir install_files
mkdir packages
mkdir ~/public_html/hg
mkdir ~/public_html/hg/repos
cd ~/packages
wget http://www.selenic.com/mercurial-stable-snapshot.tar.gz
tar zxf mercurial-stable-snapshot.tar.gz
mv mercurial-stable-snapshot.tar.gz ~/install_files/
mv mercurial* mercurial
cd mercurial
make local
./hg debuginstall
cp ~/packages/mercurial/hgwebdir.cgi ~/public_html/hg
chmod 755 ~/public_html/hg/hgwebdir.cgi
sed 's|#import sys|import sys|g' ~/public_html/hg/hgwebdir.cgi > TMPFILE && mv TMPFILE ~/public_html/hg/hgwebdir.cgi
sed 's|#sys.path.insert(0, "/path/to/python/lib")|sys.path.insert(0, "/home/'$USER'/packages/mercurial")|g' ~/public_html/hg/hgwebdir.cgi > TMPFILE && mv TMPFILE ~/public_html/hg/hgwebdir.cgi
echo [collections] > ~/public_html/hg/hgweb.config
echo /home/$USER/public_html/hg/repos = /home/$USER/public_html/hg/repos >> ~/public_html/hg/hgweb.config
echo [web] >> ~/public_html/hg/hgweb.config
echo allowpull=true >> ~/public_html/hg/hgweb.config
echo 'Options +ExecCGI' > ~/public_html/hg/.htaccess
echo 'RewriteEngine On' >> ~/public_html/hg/.htaccess
echo 'RewriteBase /'~$USER'/hg' >> ~/public_html/hg/.htaccess
echo 'RewriteRule ^$ hgwebdir.cgi [L]‘ >> ~/public_html/hg/.htaccess
echo ‘RewriteCond %{REQUEST_FILENAME} !-f’ >> ~/public_html/hg/.htaccess
echo ‘RewriteCond %{REQUEST_FILENAME} !-d’ >> ~/public_html/hg/.htaccess
echo ‘RewriteRule (.*) hgwebdir.cgi/$1 [QSA,L]‘ >> ~/public_html/hg/.htaccess
echo ‘AuthUserFile /home/’$USER’/etc/hg-basic-auth’ >> ~/public_html/hg/.htaccess
echo ‘AuthName “HG Repositories”‘ >> ~/public_html/hg/.htaccess
echo ‘AuthType Basic’ >> ~/public_html/hg/.htaccess
echo ‘Require valid-user’ >> ~/public_html/hg/.htaccess
cd ~/public_html/hg/repos

2. Initialize the mercurial repository

You need to change REPOSITORY to your repository name
If you want more than one repository, run the command for each of them

~/packages/mercurial/hg init REPOSITORY

3. Create password file

You need to change the values of HGUSERNAME and PASSWORD to your wanted user name and password

cd
htpasswd -b -c -d ~/etc/hg-basic-auth HGUSERNAME PASSWORD

For extra users (also change HGUSERNAME and PASSWORD )

htpasswd -b -d ~/etc/hg-basic-auth HGUSERNAME PASSWORD

4. Create hgrc files for each project

You need to change:
PROJECTNAME to your project name (due to limitations in this wiki, I can't get the coloring totally correct)
The line MYPROJECT="PROJECTNAME" should look like this (without the spaces) MYPROJECT=" PROJECTNAME "
ADMIN EMAIL to your project admin email
DESCRIPTION to your project description
USER1 ... USERn to your repository user(s) name(s)
If you are the only user, the line should be echo 'allow_push=USER1' >> ~/public_html/hg/repos/PROJECT/.hg/hgrc

cd
MYPROJECT="PROJECTNAME"
echo '[web]' > ~/public_html/hg/repos/$MYPROJECT/.hg/hgrc
echo 'contact=ADMIN EMAIL' >> ~/public_html/hg/repos/$MYPROJECT/.hg/hgrc
echo 'description=DESCRIPTION' >> ~/public_html/hg/repos/$MYPROJECT/.hg/hgrc
echo 'allow_push=USER1, USERn' >> ~/public_html/hg/repos/$MYPROJECT/.hg/hgrc
echo 'allow_archive=zip' >> ~/public_html/hg/repos/$MYPROJECT/.hg/hgrc


And that's how I installed Mercurial on BlueHost


Also available in: HTML TXT