Mercurial : a fast, lightweight Source Control Management system designed for efficient handling of very large distributed projects.
Voici brièvement les éléments mis en oeuvre pour monter un serveur Mercurial sécurisé (ssl) avec restriction d’accès (login/password).
Installation de Mercurial

Vous aurez besoin de ces packages (Debian like) :
$ apt-get install python2.3-dev gcc make
Téléchargez la dérnière version stable de Mercurial sur le site officiel de Mercurial, décompressez et installez :
$ wget http://www.selenic.com/mercurial/release/mercurial-0.9.5.tar.gz--23:15:48-- http://www.selenic.com/mercurial/release/mercurial-0.9.5.tar.gz
=> `mercurial-0.9.5.tar.gz'
Résolution de www.selenic.com... 66.93.16.53
Connexion vers www.selenic.com|66.93.16.53|:80...connecté.
requête HTTP transmise, en attente de la réponse...200 OK
Longueur: 670 808 (655K) [application/x-tar]
100%[===========================================>] 670 808 41.44K/s ETA 00:00
23:16:11 (30.13 KB/s) - « mercurial-0.9.5.tar.gz » sauvegardé [670808/670808]
$ tar xzf mercurial-0.9.5.tar.gz
$ cd mercurial-0.9.5/
$ python setup.py install
running install
running build
running build_py
creating build
(...)
Vérifiez que hg est bien installé :
$ hg --version
Préparer le repository
création
$ cd /var/development/projects/hg-repositories/
$ hg init myrepo
Vous devrez également spécifier les utilisateurs autorisés à "pusher" (dans mon cas "*") dans le fichier "/var/development/projects/hg-repositories/myrepo/.hg/hgrc" :
[web]
allow_push = *
installation du cgi
$ cd /var/development/projects/hg-tools/
$ cp /tmp/mercurial-0.9.5/hgwebdir.cgi index.cgi
Créez et éditez le fichier "/var/development/projects/hg-tools/hgweb.config" qui va contenir les lien entre les urls et les repositories :
[paths]
myrepo = /var/development/projects/hg-repositories/myrepo/
autorisations pour apache
$ chown -R www-data:www-data /var/development/projects/hg-{repositories,tools}
$ chmod g+rw /var/development/projects/hg-repositories/
$ chmod g+rx /var/development/projects/hg-tools/hgwebdir.cgi
Configuration d’Apache
Je suppose que vous avez déjà Apache2 installé.
certificat
Créez un certificat (choisissez bien le nom de domaine utilisé, il est unique par nom de domaine) :
$ apache2-ssl-certificate
port 443
echo "Listen 443" >> /etc/apache2/ports.conf
module ssl
$ echo "LoadModule ssl_module /usr/lib/apache2/modules/mod_ssl.so" >> /etc/apache2/httpd.conf
création des login/password :
$ mkdir /etc/apache2/htpasswd/
$ htpasswd2 -c /etc/apache2/htpasswd/hg.passwd bja
New password:
Re-type new password:
Virtual Host
<VirtualHost *:443>
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/apache.pem
ServerName ssl.moroblog.info
ServerAdmin webmaster@localhost
ErrorLog /var/log/apache2/ssl.moroblog.info.error.log
CustomLog /var/log/apache2/ssl.moroblog.info.access.log common
DocumentRoot /var/development/projects/www-index/
ScriptAliasMatch /hg(.*) /var/development/projects/hg-tools/index.cgi$1
<Directory /var/development/projects/hg-tools>
DirectoryIndex index.cgi
AddHandler cgi-script .cgi
Options ExecCGI
Order allow,deny
Allow from all
</Directory>
<Location /hg>
AuthType Basic
AuthName "Moro - Mercurial Repository"
AuthUserFile /etc/apache2/htpasswd/hg.passwd
Require valid-user
</Location>
</VirtualHost>
Voilou ! Donc rechargez apache :
$ /etc/init.d/apache2 reload
et accédez à l’url que vous avez choisi pour Mercurial, dans mon exemple c’est "https://ssl.moroblog.info/hg". Vous arriverez sur la page générée par le CGI qui est une interface web qui vous présentera vos repositories.
No module named mercurial.hgweb.hgwebdir_mod
Il se peut que vous ayez une erreur lorsque vous tenterez d’accéder au cgi (quand mercurial a été installé via apt-get sur sarge par exemple) :

L’erreur est : "No module named mercurial.hgweb.hgwebdir_mod". On peut vérifier que le module est bien présent en faisant :
$ updatedb
$ locate hgwebdir_mod
/usr/lib/python2.4/site-packages/mercurial/hgweb/hgwebdir_mod.py
/usr/lib/python2.4/site-packages/mercurial/hgweb/hgwebdir_mod.pyc
En faisant un petit strace on voit que python2.3 ne cherche pas dans notre répertoire /usr/lib/python2.4/site-packages/... N’étant pas un grand spécialiste de Python (loin de là !), je me suis contenté de faire un lien symbolique :
$ ln -s /usr/lib/python2.4/site-packages/mercurial/ /usr/lib/python2.3/mercurial
Rechargez la page et ça devrait marcher.
Ajouter un repo
créez le projet et donner les droits à www-data
ajouter le repo dans hgweb.config :
[paths]
myrepo = /var/development/projects/hg-repositories/myrepo/
myrepo2 = /var/development/projects/hg-repositories/myrepo2/
donner des droits de push à certains utilisateurs
[web]
allow_push = bob