changeset 0:edd512324c03

Add:Mercurial Files
author Pluto <meokcin@gmail.com>
date Tue, 03 Sep 2024 16:30:52 +0800
parents
children 44d6d3cb28a0
files Mercurial/CreathgRepos.sh Mercurial/apache.hg.conf.exmaple Mercurial/doc/Install-Mercurial-on-Ubuntu.md Mercurial/hgweb.config.exmaple Mercurial/hgweb.wsgi.exmaple
diffstat 5 files changed, 204 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mercurial/CreathgRepos.sh	Tue Sep 03 16:30:52 2024 +0800
@@ -0,0 +1,42 @@
+#!/bin/bash
+
+# 提示用户输入仓库名称
+echo "请输入仓库名称(不要中文):"
+read repo_name
+
+# 创建仓库目录
+repo_path="/var/hg/$repo_name"
+mkdir -p "$repo_path"
+
+# 检查目录是否创建成功
+if [ ! -d "$repo_path" ]; then
+    echo "目录创建失败,请检查权限或磁盘空间。"
+    exit 1
+fi
+
+# 初始化Mercurial仓库
+hg init "$repo_path"
+
+# 更改仓库所有者为www-data
+sudo chown -R www-data:www-data "$repo_path"
+
+# 更改仓库权限为755
+sudo chmod -R 755 "$repo_path"
+
+# 提示用户输入description和contact的内容
+echo "请输入description的内容:"
+read description
+echo "请输入contact的内容:"
+read contact
+
+# 构建hgrc文件内容
+hgrc_content="[web]
+description = $description
+contact = $contact"
+
+# 写入.hg/hgrc文件
+hgrc_path="$repo_path/.hg/hgrc"
+echo "$hgrc_content" | sudo tee "$hgrc_path" > /dev/null
+
+echo "仓库已成功创建并配置在 $repo_path"
+echo "hgrc文件已更新。"
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mercurial/apache.hg.conf.exmaple	Tue Sep 03 16:30:52 2024 +0800
@@ -0,0 +1,30 @@
+<VirtualHost *:80>
+ServerName hg.nnsui.com
+RewriteEngine On
+RewriteCond %{HTTPS} !=on
+RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
+</VirtualHost>
+<VirtualHost *:443>
+ServerName hg.nnsui.com
+SSLEngine On
+SSLCertificateFile /etc/apache2/cert/nnsui.com.pem
+SSLCertificateKeyFile /etc/apache2/cert/nnsui.com.key
+WSGIScriptAlias / /var/hg/hgweb.wsgi
+WSGIDaemonProcess hgweb user=www-data group=www-data processes=2 threads=15
+WSGIProcessGroup hgweb
+<Directory /var/hg>
+Require all granted
+</Directory>
+<Location "/">
+AuthType Basic
+AuthName "Restricted Access"
+AuthUserFile /etc/apache2/hgweb.htpasswd
+Require valid-user
+<Limit GET>
+Require all granted
+</Limit>
+<LimitExcept GET>
+Require valid-user
+</LimitExcept>
+</Location>
+</VirtualHost>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mercurial/doc/Install-Mercurial-on-Ubuntu.md	Tue Sep 03 16:30:52 2024 +0800
@@ -0,0 +1,111 @@
+# Ubuntu下 apache2 和 hgweb 的安装
+## 安装
+1. 安装 apache2、 hgweb
+```shell 
+sudo apt install apache2 mercurial libapache2-mod-wsgi-py3 apache2-utils
+```
+2. 验证环境
+```shell
+# 启用apache2
+sudo systemctl start apache2
+sudo systemctl enable apache2   
+
+# 查看HG
+hg --version
+```
+3. 创建文件夹和默认仓库
+```shell
+sudo mkdir /var/hg
+sudo hg init /var/hg/myrepo
+
+#设置文件夹权限
+sudo chown -R www-data:www-data /var/hg
+sudo chmod -R 755 /var/hg
+```
+4. 创建 ```/var/hg/hgweb.config``` 文件
+```shell
+[web]
+allow_push = *
+push_ssl = true
+allow_archive = gz, zip, bz2
+
+[paths]
+/ = /var/hg/*
+```
+
+5. 创建 ``` /var/hg/hgweb.wsgi``` 文件
+```shell
+import sys
+import os
+from mercurial import demandimport
+demandimport.enable()
+
+# 设置编码为UTF-8
+if not isinstance(os.environ.get('PYTHONIOENCODING'), str):
+    os.environ['PYTHONIOENCODING'] = 'utf-8'
+
+from mercurial.hgweb.hgwebdir_mod import hgwebdir
+
+application = hgwebdir(b'/var/hg/hgweb.config')
+```
+6. 创建 ```/etc/apache2/sites-available/hgweb.conf```
+```shell
+<VirtualHost *:80>
+    ServerName repo.nnsui.com
+
+    RewriteEngine On
+    RewriteCond %{HTTPS} !=on
+    RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
+</VirtualHost>
+
+<VirtualHost *:443>
+    ServerName repo.nnsui.com
+
+    SSLEngine On
+    SSLCertificateFile /etc/apache2/cert/nnsui.com.pem
+    SSLCertificateKeyFile /etc/apache2/cert/nnsui.com.key
+
+    WSGIScriptAlias / /var/hg/hgweb.wsgi
+    WSGIDaemonProcess hgweb user=www-data group=www-data processes=2 threads=15
+    WSGIProcessGroup hgweb
+
+    <Directory /var/hg>
+        Require all granted
+    </Directory>
+
+    <Location "/">
+        AuthType Basic
+        AuthName "Restricted Access"
+        AuthUserFile /etc/apache2/hgweb.htpasswd
+        Require valid-user
+        <Limit GET>
+            Require all granted
+        </Limit>
+        <LimitExcept GET>
+            Require valid-user
+        </LimitExcept>
+    </Location>
+</VirtualHost>
+```
+
+7. 启用apache2模块
+```shell
+sudo a2enmod wsgi
+sudo a2enmod ssl
+sudo a2enmod rewrite
+```
+8. 启动!
+```shell
+# 检查配置
+sudo apachectl configtest
+# 重启
+sudo a2ensite hgweb
+
+sudo systemctl restart apache2
+```
+9. 创建 ```htpasswd``` 文件并添加用户
+```shell
+sudo htpasswd -c /etc/apache2/hgweb.htpasswd pluto
+```
+
+10. 
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mercurial/hgweb.config.exmaple	Tue Sep 03 16:30:52 2024 +0800
@@ -0,0 +1,6 @@
+[web]
+allow_push = *
+push_ssl = true
+allow_archive = gz, zip, bz2
+[paths]
+/ = /var/hg/*
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mercurial/hgweb.wsgi.exmaple	Tue Sep 03 16:30:52 2024 +0800
@@ -0,0 +1,15 @@
+import sys
+import os
+from mercurial import demandimport
+demandimport.enable()
+# 设置编码为UTF-8
+if not isinstance(os.environ.get('PYTHONIOENCODING'), str):
+os.environ['PYTHONIOENCODING'] = 'utf-8'
+from mercurial.hgweb.hgwebdir_mod import hgwebdir
+# 确保配置文件路径正确
+config_path = '/var/hg/hgweb.config'
+if not os.path.isabs(config_path):
+config_path = os.path.join(os.getcwd(), config_path)
+# 确保路径是字节串,以防 Mercurial 需要字节串路径
+config_path_bytes = config_path.encode('utf-8')
+application = hgwebdir(config_path_bytes)
\ No newline at end of file
备案号:苏ICP备2024087954号-2 | 渝公网安备50010402001513