deb/apache-register-hg.bash
author Oleksandr Gavenko <gavenkoa@gmail.com>
Sat, 23 Dec 2023 21:19:31 +0200
changeset 32 921746b84574
parent 31 461eed8e7463
permissions -rw-r--r--
Update hgweb to Python 3.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
6a6933bfce58 Added test Apache 2 virtual host.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     1
#!/bin/bash
6a6933bfce58 Added test Apache 2 virtual host.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     2
11
a6a75053c129 Fixed names, enabled debugging.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 10
diff changeset
     3
set -x
a6a75053c129 Fixed names, enabled debugging.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 10
diff changeset
     4
16
667a0417c36a Corrections to hosting HG in Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 15
diff changeset
     5
a2enmod cgi
667a0417c36a Corrections to hosting HG in Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 15
diff changeset
     6
service apache2 restart
667a0417c36a Corrections to hosting HG in Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 15
diff changeset
     7
15
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
     8
mkdir -p /srv/hg
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
     9
chown user:user /srv/hg
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
    10
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
    11
cat <<EOF >/srv/hg/hgweb.cgi
32
921746b84574 Update hgweb to Python 3.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 31
diff changeset
    12
#!/usr/bin/env python3
15
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
    13
# See also https://mercurial-scm.org/wiki/PublishingRepositories
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
    14
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
    15
# Path to repo or hgweb config to serve (see 'hg help hgweb')
32
921746b84574 Update hgweb to Python 3.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 31
diff changeset
    16
config = b"/srv/hg/hgweb.config"
921746b84574 Update hgweb to Python 3.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 31
diff changeset
    17
921746b84574 Update hgweb to Python 3.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 31
diff changeset
    18
# Uncomment to send python tracebacks to the browser if an error occurs:
921746b84574 Update hgweb to Python 3.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 31
diff changeset
    19
# import cgitb; cgitb.enable()
10
6a6933bfce58 Added test Apache 2 virtual host.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    20
32
921746b84574 Update hgweb to Python 3.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 31
diff changeset
    21
from mercurial import demandimport
921746b84574 Update hgweb to Python 3.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 31
diff changeset
    22
demandimport.enable()
921746b84574 Update hgweb to Python 3.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 31
diff changeset
    23
15
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
    24
from mercurial.hgweb import hgweb, wsgicgi
32
921746b84574 Update hgweb to Python 3.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 31
diff changeset
    25
15
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
    26
application = hgweb(config)
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
    27
wsgicgi.launch(application)
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
    28
EOF
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
    29
chmod a+xr /srv/hg/hgweb.cgi
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
    30
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
    31
cat <<EOF >/srv/hg/hgweb.config
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
    32
[paths]
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
    33
/ = /srv/hg/*
10
6a6933bfce58 Added test Apache 2 virtual host.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    34
15
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
    35
[web]
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
    36
style = gitweb
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
    37
encoding = "UTF-8"
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
    38
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
    39
baseurl = /
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
    40
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
    41
deny_push = *
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
    42
allow_archive = bz2, gz, zip
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
    43
EOF
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
    44
chmod a+r /srv/hg/hgweb.config
13
7ed40cd96e3a Possible fix for: AH01630: client denied by server configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 12
diff changeset
    45
15
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
    46
cat <<EOF >/etc/apache2/sites-available/hg.conf
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
    47
<VirtualHost hg.defun.work:*>
16
667a0417c36a Corrections to hosting HG in Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 15
diff changeset
    48
    DocumentRoot /srv/hg
21
52f40bd9e114 Integrated Lets Encrypt into all sites.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 17
diff changeset
    49
    ServerName hg.defun.work
15
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
    50
31
461eed8e7463 Activating Let's Encrypt webroot renewal for all my sites.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
    51
    Alias "/.well-known/acme-challenge/" "/srv/www/letsencrypt/.well-known/acme-challenge/"
461eed8e7463 Activating Let's Encrypt webroot renewal for all my sites.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
    52
    <Directory "/srv/www/letsencrypt/">
461eed8e7463 Activating Let's Encrypt webroot renewal for all my sites.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
    53
        Require all granted
461eed8e7463 Activating Let's Encrypt webroot renewal for all my sites.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
    54
    </Directory>
461eed8e7463 Activating Let's Encrypt webroot renewal for all my sites.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 21
diff changeset
    55
17
141de5177ee8 Escaped dollar sign.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 16
diff changeset
    56
    ScriptAliasMatch  ^/(.*)  /srv/hg/hgweb.cgi/\$1
15
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
    57
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
    58
    <Directory "/srv/hg/">
16
667a0417c36a Corrections to hosting HG in Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 15
diff changeset
    59
        Options +ExecCGI
13
7ed40cd96e3a Possible fix for: AH01630: client denied by server configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 12
diff changeset
    60
        Require all granted
15
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
    61
        AllowOverride None
16
667a0417c36a Corrections to hosting HG in Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 15
diff changeset
    62
        AddHandler cgi-script .cgi
13
7ed40cd96e3a Possible fix for: AH01630: client denied by server configuration.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 12
diff changeset
    63
    </Directory>
11
a6a75053c129 Fixed names, enabled debugging.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 10
diff changeset
    64
</VirtualHost>
21
52f40bd9e114 Integrated Lets Encrypt into all sites.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 17
diff changeset
    65
52f40bd9e114 Integrated Lets Encrypt into all sites.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 17
diff changeset
    66
<IfModule mod_ssl.c>
52f40bd9e114 Integrated Lets Encrypt into all sites.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 17
diff changeset
    67
  <VirtualHost hg.defun.work:443>
52f40bd9e114 Integrated Lets Encrypt into all sites.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 17
diff changeset
    68
    DocumentRoot /srv/hg
52f40bd9e114 Integrated Lets Encrypt into all sites.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 17
diff changeset
    69
    ServerName hg.defun.work
52f40bd9e114 Integrated Lets Encrypt into all sites.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 17
diff changeset
    70
52f40bd9e114 Integrated Lets Encrypt into all sites.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 17
diff changeset
    71
    ScriptAliasMatch  ^/(.*)  /srv/hg/hgweb.cgi/\$1
52f40bd9e114 Integrated Lets Encrypt into all sites.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 17
diff changeset
    72
52f40bd9e114 Integrated Lets Encrypt into all sites.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 17
diff changeset
    73
    <Directory "/srv/hg/">
52f40bd9e114 Integrated Lets Encrypt into all sites.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 17
diff changeset
    74
        Options +ExecCGI
52f40bd9e114 Integrated Lets Encrypt into all sites.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 17
diff changeset
    75
        Require all granted
52f40bd9e114 Integrated Lets Encrypt into all sites.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 17
diff changeset
    76
        AllowOverride None
52f40bd9e114 Integrated Lets Encrypt into all sites.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 17
diff changeset
    77
        AddHandler cgi-script .cgi
52f40bd9e114 Integrated Lets Encrypt into all sites.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 17
diff changeset
    78
    </Directory>
52f40bd9e114 Integrated Lets Encrypt into all sites.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 17
diff changeset
    79
  </VirtualHost>
52f40bd9e114 Integrated Lets Encrypt into all sites.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 17
diff changeset
    80
</IfModule>
10
6a6933bfce58 Added test Apache 2 virtual host.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    81
EOF
6a6933bfce58 Added test Apache 2 virtual host.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    82
15
3f7b202af99e An attempt to host HG via Apache.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 13
diff changeset
    83
a2ensite hg
21
52f40bd9e114 Integrated Lets Encrypt into all sites.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 17
diff changeset
    84
service apache2 reload