Triaxx Web Log

Mercurial

Initialization

hg init
cat >> .hg/hgrc << EOF
[ui]
username = triaxx <triaxx@triaxx.io>
EOF

Usage

hg status
hg add <file>
hg forget <file>
hg commit
hg log --graph

Change the message of the last commit:

hg commit --amend

Revert to the last commit version:

hg revert
hg revert --no-backup

Extensions

Enable histedit:

cat >> .hg/hgrc << EOF
[extensions]
histedit =

Web

Add a CNAME entry for hg:

hg     CNAME   www

Configure a hgweb application:

mkdir -p /etc/mercurial
cat > /etc/mercurial/hgweb/hgrc << EOF
[paths]
/ = /srv/hg/repos/*

[web]
cacerts = /etc/ssl/certs/ca-certificates.crt
allow-push = triaxx
EOF
cat > /etc/mercurial/hgweb/hgweb.py << EOF
#!/usr/bin/env python3

from mercurial import demandimport
demandimport.enable()
from mercurial.hgweb import hgweb
config = b"/etc/mercurial/hgweb/hgrc"
app = hgweb(config)
EOF

Install gunicorn to serve hg:

emerge --ask --verbose gunicorn

Create init script for gunicorn:

cat > /etc/init.d/gunicorn-hgweb << EOF
description="Gunicorn server for Mercurial hgweb"

: ${GUNICORN_HGWEB_DIR:=/etc/mercurial/hgweb}
: ${GUNICORN_HGWEB_USER:=hg}
: ${GUNICORN_HGWEB_GROUP:=hg}
: ${GUNICORN_HGWEB_RUNDIR:=/run/hgweb}
: ${GUNICORN_HGWEB_BIND:=unix:${GUNICORN_HGWEB_RUNDIR}/gunicorn.sock}

supervisor="supervise-daemon"
command="/usr/bin/gunicorn"
command_args="--chdir ${GUNICORN_HGWEB_DIR} \
  --bind ${GUNICORN_HGWEB_BIND} \
  --user ${GUNICORN_HGWEB_USER} \
  --group ${GUNICORN_HGWEB_GROUP} \
  hgweb:app"

depend() {
  need net
  after logger
}

start_pre() {
  checkpath -d -m 0755 -o "${GUNICORN_HGWEB_USER}:${GUNICORN_HGWEB_GROUP}" ${GUNICORN_HGWEB_RUNDIR} 2>/dev/null || true
}
EOF

Configure Nginx to proxy gunicorn:

http {
  server {
    listen                             443 ssl;
    listen                             [::]:443 ssl;
    server_name                        hg.triaxx.io;
    ssl_certificate                    /etc/letsencrypt/live/triaxx.io/fullchain.pem;
    ssl_certificate_key                /etc/letsencrypt/live/triaxx.io/privkey.pem;

    location / {
      auth_basic                       "hgweb";
      auth_basic_user_file             credentials;
      proxy_pass                       http://unix:/run/hgweb/gunicorn.sock;
      proxy_set_header                 Host $host;
      proxy_set_header                 X-Real-IP $remote_addr;
      proxy_set_header                 X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header                 X-Forwarded-Proto $scheme;
    }
  }
}

Add the credential:

echo "triaxx:$(openssl passwd)" >> /etc/nginx/credentials