diff options
author | 2025-01-07 12:36:05 +0800 | |
---|---|---|
committer | 2025-01-07 12:36:05 +0800 | |
commit | 4d88ef666eee1b6f191f6e85b00acf8d5a2d1899 (patch) | |
tree | 68391846bae84f9546b0d089c012afc336a6e6bd /code/linux/gitserver.html | |
parent | 11e64c5804b696f170b9d5d881befbabc4a4e85c (diff) | |
download | myweb-4d88ef666eee1b6f191f6e85b00acf8d5a2d1899.tar.gz myweb-4d88ef666eee1b6f191f6e85b00acf8d5a2d1899.zip |
highlight don't use auto-detect but given languagenew_highlightjs
In this commit, lot's of things is changed. Hope they all runs
currectly.
Now highlight.js is supporting more and more proguam languages, but
the auto detection always go wrong, even for common languages like c,
bash, python, makefile.
Use Given Language
------------------
As you know, I always write markdown and convert to html by pandoc. In
the old, "```cpp" in markdown will be deleted first to keep the embeded
code clean and not highlighted, then I can use highlight.js. But this
causes that html document doesn't know the language.
This time, md2html.sh is changed: pandoc use "--no-highlight"
argument to keep code clean, and it will output like this:
```html
<pre class="cpp"><code>...</code></pre>
```
Although there may be other tags between `<code></code>`, it's clear
that `<pre class="xxx"><code>` is nested tightly, except some space
characters or \n.
Then, sed deal with the whole doc(not line by line), replace `<pre
class="xxx"><code>` with `<pre><code class="language-xxx">`. That's it!
Math Formula
------------
Math formular is also a problem during convertion by pandoc. In the old
it's dealed menually. Now pandoc use "--mathjax=none", then formula is
no longer showed by pandoc, but only `<span class="math xxx">\( formula \)</span>`.
And the math tool I used will deal with it.
Mermaid picture
----------------
pandoc doesn't support convert mermaid in markdown to html picture.
Let's have a warning!
Diffstat (limited to 'code/linux/gitserver.html')
-rw-r--r-- | code/linux/gitserver.html | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/code/linux/gitserver.html b/code/linux/gitserver.html index 8c97999..40c3cb8 100644 --- a/code/linux/gitserver.html +++ b/code/linux/gitserver.html | |||
@@ -7,14 +7,15 @@ | |||
7 | <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> | 7 | <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> |
8 | <title>自己的 git 托管</title> | 8 | <title>自己的 git 托管</title> |
9 | <link rel="stylesheet" href="https://www.qin-juan-ge-zhu.top/common/CSS/pandoc.css"> | 9 | <link rel="stylesheet" href="https://www.qin-juan-ge-zhu.top/common/CSS/pandoc.css"> |
10 | <script type="text/javascript" src="https://hl.qin-juan-ge-zhu.top/myset/myhighlight.js"></script> | ||
11 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/script4code.js"></script> | 10 | <script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/script4code.js"></script> |
12 | </head> | 11 | </head> |
13 | 12 | ||
14 | <body> | 13 | <body> |
15 | <div class="pandoc"> | 14 | <div class="pandoc"> |
16 | <div class="main"> | 15 | <div class="main"> |
17 | <p class="title">自己的 git 托管</p> | 16 | <header id="title-block-header"> |
17 | <p class="title">自己的 git 托管</p> | ||
18 | </header> | ||
18 | <!-- git 远程存储 --> | 19 | <!-- git 远程存储 --> |
19 | <blockquote> | 20 | <blockquote> |
20 | <p>争名夺利几时休,早起迟眠不自由。</p> | 21 | <p>争名夺利几时休,早起迟眠不自由。</p> |
@@ -49,13 +50,13 @@ | |||
49 | <p>首先,本方法要求有一个本地 git 存储库,并且已经有 commit。如果是本地新建的仓库,需要先有一个 commit,然后继续操作。这个 commit | 50 | <p>首先,本方法要求有一个本地 git 存储库,并且已经有 commit。如果是本地新建的仓库,需要先有一个 commit,然后继续操作。这个 commit |
50 | 可以用编写<code>.gitignore</code>或者<code>push.sh</code>等不甚重要的文件来凑数。</p> | 51 | 可以用编写<code>.gitignore</code>或者<code>push.sh</code>等不甚重要的文件来凑数。</p> |
51 | <h2 id="远程仓库">远程仓库</h2> | 52 | <h2 id="远程仓库">远程仓库</h2> |
52 | <pre><code># 创建远程仓库,这里也叫test吧 | 53 | <pre><code class="language-bash"># 创建远程仓库,这里也叫test吧 |
53 | ssh git@127.0.0.1 git init --bare test.git</code></pre> | 54 | ssh git@127.0.0.1 git init --bare test.git</code></pre> |
54 | <p>注意,本处指明的 git 为远程用户名,127.0.0.1 代表云服务器的公网 ip,test.git | 55 | <p>注意,本处指明的 git 为远程用户名,127.0.0.1 代表云服务器的公网 ip,test.git |
55 | 为远程仓库名。使用的时候都需要换成自己的。如果仓库不想直接存储在用户目录下,需要指出其存储路径,如<code>code/fuck/test.git</code></p> | 56 | 为远程仓库名。使用的时候都需要换成自己的。如果仓库不想直接存储在用户目录下,需要指出其存储路径,如<code>code/fuck/test.git</code></p> |
56 | <h2 id="本地与远程连接">本地与远程连接</h2> | 57 | <h2 id="本地与远程连接">本地与远程连接</h2> |
57 | <p>本地和远程都有了,下一步就是建立联系了。</p> | 58 | <p>本地和远程都有了,下一步就是建立联系了。</p> |
58 | <pre><code># 本地添加远程库信息 | 59 | <pre><code class="language-bash"># 本地添加远程库信息 |
59 | git remote add origin git@127.0.0.1:test.git | 60 | git remote add origin git@127.0.0.1:test.git |
60 | 61 | ||
61 | # 此时尚不能直接推送,因为并未指定上游对应分支,需要指定 | 62 | # 此时尚不能直接推送,因为并未指定上游对应分支,需要指定 |
@@ -65,7 +66,7 @@ git push --set-upstream origin master | |||
65 | bash push.sh</code></pre> | 66 | bash push.sh</code></pre> |
66 | <h2 id="自动化">自动化</h2> | 67 | <h2 id="自动化">自动化</h2> |
67 | <p>整体操作过程可以说比较简单了。既然如此,<strong>脚本,启动!</strong></p> | 68 | <p>整体操作过程可以说比较简单了。既然如此,<strong>脚本,启动!</strong></p> |
68 | <pre><code>#!/bin/bash | 69 | <pre><code class="language-bash">#!/bin/bash |
69 | 70 | ||
70 | read -p "Local repo name: " local_name | 71 | read -p "Local repo name: " local_name |
71 | read -p "Remote repo name: " remote_name | 72 | read -p "Remote repo name: " remote_name |
@@ -136,7 +137,7 @@ echo "Success!"</code></pre> | |||
136 | </ul> | 137 | </ul> |
137 | <h2 id="nginx-配置与说明">nginx 配置与说明</h2> | 138 | <h2 id="nginx-配置与说明">nginx 配置与说明</h2> |
138 | <p>最初的设置是这样的:</p> | 139 | <p>最初的设置是这样的:</p> |
139 | <pre><code>server | 140 | <pre><code class="language-nginx">server |
140 | { | 141 | { |
141 | # 这里用于将 http 请求重定向到 https,是一种常用的方式 | 142 | # 这里用于将 http 请求重定向到 https,是一种常用的方式 |
142 | listen 80; | 143 | listen 80; |
@@ -167,7 +168,7 @@ server | |||
167 | } | 168 | } |
168 | }</code></pre> | 169 | }</code></pre> |
169 | <p>nginx 重新加载配置之后,我们就可以正常<code>git clone https://git.player.com/test.git</code>了。但当我们 push 时,会出现 403 错误:</p> | 170 | <p>nginx 重新加载配置之后,我们就可以正常<code>git clone https://git.player.com/test.git</code>了。但当我们 push 时,会出现 403 错误:</p> |
170 | <pre><code>$ git push | 171 | <pre><code class="language-bash">$ git push |
171 | fatal: unable to access 'https://git.player.com/test.git/': The requested URL returned error: 403</code></pre> | 172 | fatal: unable to access 'https://git.player.com/test.git/': The requested URL returned error: 403</code></pre> |
172 | <p>为了解决这个错误,我们可以在 <code>git-http-backend</code> 的官网文档 上找到这样的一段描述:</p> | 173 | <p>为了解决这个错误,我们可以在 <code>git-http-backend</code> 的官网文档 上找到这样的一段描述:</p> |
173 | <blockquote> | 174 | <blockquote> |
@@ -181,7 +182,7 @@ fatal: unable to access 'https://git.player.com/test.git/': The requeste | |||
181 | <p>我们可以在仓库中执行 <code>git config http.receivepack true</code> 来开启 push 权限,但是这样的话,所有人都可以 push | 182 | <p>我们可以在仓库中执行 <code>git config http.receivepack true</code> 来开启 push 权限,但是这样的话,所有人都可以 push |
182 | 代码了,这显然不是我们想要的。我们可以通过 <code>git config http.receivepack false</code> 来关闭 push 权限,这样的话,所有人都不能 push | 183 | 代码了,这显然不是我们想要的。我们可以通过 <code>git config http.receivepack false</code> 来关闭 push 权限,这样的话,所有人都不能 push |
183 | 代码了,这也不是我们想要的。那么,我们应该怎么做呢?更好的做法是这样的:</p> | 184 | 代码了,这也不是我们想要的。那么,我们应该怎么做呢?更好的做法是这样的:</p> |
184 | <pre><code>$HTTP["querystring"] =~ "service=git-receive-pack" { | 185 | <pre><code class="language-nginx">$HTTP["querystring"] =~ "service=git-receive-pack" { |
185 | include "git-auth.conf" | 186 | include "git-auth.conf" |
186 | } | 187 | } |
187 | $HTTP["url"] =~ "^/git/.*/git-receive-pack$" { | 188 | $HTTP["url"] =~ "^/git/.*/git-receive-pack$" { |
@@ -189,16 +190,15 @@ $HTTP["url"] =~ "^/git/.*/git-receive-pack$" { | |||
189 | }</code></pre> | 190 | }</code></pre> |
190 | <p>看上去挺简单,但是想要理解为什么这样配置,就必须了解下 Git 的内部原理。正如上面 git-http-backend 文档上的那段描述,当 Git 客户端执行 | 191 | <p>看上去挺简单,但是想要理解为什么这样配置,就必须了解下 Git 的内部原理。正如上面 git-http-backend 文档上的那段描述,当 Git 客户端执行 |
191 | <code>git fetch/git pull/git clone</code>时,会调用 <code>upload-pack</code> 服务,当执行 <code>git push</code> | 192 | <code>git fetch/git pull/git clone</code>时,会调用 <code>upload-pack</code> 服务,当执行 <code>git push</code> |
192 | 时,会调用 <code>receive-pack</code> 服务。我们可以查看 nginx 的访问日志,目录在<code>/var/log/nginx/access.log</code>: | 193 | 时,会调用 <code>receive-pack</code> 服务。我们可以查看 nginx 的访问日志,目录在<code>/var/log/nginx/access.log</code>:</p> |
193 | </p> | ||
194 | <p>执行 git clone:</p> | 194 | <p>执行 git clone:</p> |
195 | <pre><code>[27/Nov/2018:22:18:00] "GET /test.git/info/refs?service=git-upload-pack HTTP/1.1" 200 363 "-" "git/1.9.1" | 195 | <pre><code class="language-plaintext">[27/Nov/2018:22:18:00] "GET /test.git/info/refs?service=git-upload-pack HTTP/1.1" 200 363 "-" "git/1.9.1" |
196 | [27/Nov/2018:22:18:00] "POST /test.git/git-upload-pack HTTP/1.1" 200 306 "-" "git/1.9.1"</code></pre> | 196 | [27/Nov/2018:22:18:00] "POST /test.git/git-upload-pack HTTP/1.1" 200 306 "-" "git/1.9.1"</code></pre> |
197 | <p>执行 git pull:</p> | 197 | <p>执行 git pull:</p> |
198 | <pre><code>[27/Nov/2018:22:20:25] "GET /test.git/info/refs?service=git-upload-pack HTTP/1.1" 200 363 "-" "git/1.9.1" | 198 | <pre><code class="language-plaintext">[27/Nov/2018:22:20:25] "GET /test.git/info/refs?service=git-upload-pack HTTP/1.1" 200 363 "-" "git/1.9.1" |
199 | [27/Nov/2018:22:20:25] "POST /test.git/git-upload-pack HTTP/1.1" 200 551 "-" "git/1.9.1"</code></pre> | 199 | [27/Nov/2018:22:20:25] "POST /test.git/git-upload-pack HTTP/1.1" 200 551 "-" "git/1.9.1"</code></pre> |
200 | <p>执行 git push:</p> | 200 | <p>执行 git push:</p> |
201 | <pre><code>[27/Nov/2018:22:19:33] "GET /test.git/info/refs?service=git-receive-pack HTTP/1.1" 401 204 "-" "git/1.9.1" | 201 | <pre><code class="language-plaintext">[27/Nov/2018:22:19:33] "GET /test.git/info/refs?service=git-receive-pack HTTP/1.1" 401 204 "-" "git/1.9.1" |
202 | admin [27/Nov/2018:22:19:33] "GET /test.git/info/refs?service=git-receive-pack HTTP/1.1" 200 193 "-" "git/1.9.1" | 202 | admin [27/Nov/2018:22:19:33] "GET /test.git/info/refs?service=git-receive-pack HTTP/1.1" 200 193 "-" "git/1.9.1" |
203 | admin [27/Nov/2018:22:19:33] "POST /test.git/git-receive-pack HTTP/1.1" 200 63 "-" "git/1.9.1"</code></pre> | 203 | admin [27/Nov/2018:22:19:33] "POST /test.git/git-receive-pack HTTP/1.1" 200 63 "-" "git/1.9.1"</code></pre> |
204 | <p>可以看到执行 clone 和 pull 请求的接口是一样的,先请求 <code>/info/refs?service=git-upload-pack</code>,然后再请求 | 204 | <p>可以看到执行 clone 和 pull 请求的接口是一样的,先请求 <code>/info/refs?service=git-upload-pack</code>,然后再请求 |
@@ -206,10 +206,9 @@ admin [27/Nov/2018:22:19:33] "POST /test.git/git-receive-pack HTTP/1.1" | |||
206 | <code>/git-receive-pack</code>,所以在上面的的配置中我们看到了两条记录,如果要对 push 做访问控制,那么对这两个请求都要限制。关于 Git 传输的原理可以参考 《Pro | 206 | <code>/git-receive-pack</code>,所以在上面的的配置中我们看到了两条记录,如果要对 push 做访问控制,那么对这两个请求都要限制。关于 Git 传输的原理可以参考 《Pro |
207 | Git》的 <a | 207 | Git》的 <a |
208 | href="https://git-scm.com/book/zh/v2/Git-%E5%86%85%E9%83%A8%E5%8E%9F%E7%90%86-%E4%BC%A0%E8%BE%93%E5%8D%8F%E8%AE%AE">Git | 208 | href="https://git-scm.com/book/zh/v2/Git-%E5%86%85%E9%83%A8%E5%8E%9F%E7%90%86-%E4%BC%A0%E8%BE%93%E5%8D%8F%E8%AE%AE">Git |
209 | 内部原理 - 传输协议</a> 这一节。 | 209 | 内部原理 - 传输协议</a> 这一节。</p> |
210 | </p> | ||
211 | <p>于是,我们对 nginx 的配置文件进行修改:</p> | 210 | <p>于是,我们对 nginx 的配置文件进行修改:</p> |
212 | <pre><code>server | 211 | <pre><code class="language-nginx">server |
213 | { | 212 | { |
214 | listen 80; | 213 | listen 80; |
215 | server_name git.player.com; | 214 | server_name git.player.com; |
@@ -274,21 +273,21 @@ server | |||
274 | </blockquote> | 273 | </blockquote> |
275 | <h2 id="认证文件">认证文件</h2> | 274 | <h2 id="认证文件">认证文件</h2> |
276 | <p>nginx 的配置中我们用到了认证文件,它的生成是这样的:</p> | 275 | <p>nginx 的配置中我们用到了认证文件,它的生成是这样的:</p> |
277 | <pre><code># 创建认证文件并添加第一个用户 | 276 | <pre><code class="language-bash"># 创建认证文件并添加第一个用户 |
278 | htpasswd -cd <文件名> <用户名> <密码> | 277 | htpasswd -cd <文件名> <用户名> <密码> |
279 | # 在已有的文件中继续添加用户 | 278 | # 在已有的文件中继续添加用户 |
280 | htpasswd -d <文件名> <用户名> <密码></code></pre> | 279 | htpasswd -d <文件名> <用户名> <密码></code></pre> |
281 | <p>到了这里,我们重启 nginx 然后进行测试,也许就可以正常使用了……吗?</p> | 280 | <p>到了这里,我们重启 nginx 然后进行测试,也许就可以正常使用了……吗?</p> |
282 | <h2 id="问题">问题</h2> | 281 | <h2 id="问题">问题</h2> |
283 | <p>我在测试的时候发现了一个问题:</p> | 282 | <p>我在测试的时候发现了一个问题:</p> |
284 | <pre><code>$ git clone https://git.player.com/test.git | 283 | <pre><code class="language-bash">$ git clone https://git.player.com/test.git |
285 | Cloning into 'test'... | 284 | Cloning into 'test'... |
286 | fatal: repository 'https://git.player.com/test.git/' not found</code></pre> | 285 | fatal: repository 'https://git.player.com/test.git/' not found</code></pre> |
287 | <p>看起来很匪夷所思:我们明明把仓库放进了指定目录啊,nginx 也已经配置好了,为什么就是找不到呢?我在网上找了很久也没找到答案。最后自己发现了问题所在:<strong>仓库文件夹权限不对</strong>。 | 286 | <p>看起来很匪夷所思:我们明明把仓库放进了指定目录啊,nginx 也已经配置好了,为什么就是找不到呢?我在网上找了很久也没找到答案。最后自己发现了问题所在:<strong>仓库文件夹权限不对</strong>。 |
288 | </p> | 287 | </p> |
289 | <h3 id="linux-权限描述">Linux 权限描述</h3> | 288 | <h3 id="linux-权限描述">Linux 权限描述</h3> |
290 | <p>当我们使用<code>ls -l</code>命令查看文件夹时,会看到类似这样的输出:</p> | 289 | <p>当我们使用<code>ls -l</code>命令查看文件夹时,会看到类似这样的输出:</p> |
291 | <pre><code>drwxr-xr-x 2 git git 4096 Nov 27 22:19 test.git</code></pre> | 290 | <pre><code class="language-bash">drwxr-xr-x 2 git git 4096 Nov 27 22:19 test.git</code></pre> |
292 | <p>其中前 10 个字符就是用来描述该目录权限的。</p> | 291 | <p>其中前 10 个字符就是用来描述该目录权限的。</p> |
293 | <ul> | 292 | <ul> |
294 | <li>第一位字符代表文件类型 | 293 | <li>第一位字符代表文件类型 |
@@ -334,7 +333,7 @@ fatal: repository 'https://git.player.com/test.git/' not found</code></p | |||
334 | </li> | 333 | </li> |
335 | </ul> | 334 | </ul> |
336 | <p><strong>这也就是上文我推荐为 git 仓库托管设立单独用户的原因。</strong>因而,最后我选择了第三种方案。具体操作如下:</p> | 335 | <p><strong>这也就是上文我推荐为 git 仓库托管设立单独用户的原因。</strong>因而,最后我选择了第三种方案。具体操作如下:</p> |
337 | <pre><code>usermod -aG git root | 336 | <pre><code class="language-bash">usermod -aG git root |
338 | usermod -aG git www-data</code></pre> | 337 | usermod -aG git www-data</code></pre> |
339 | <p>此时再进行测试,应该就可以正常使用了。</p> | 338 | <p>此时再进行测试,应该就可以正常使用了。</p> |
340 | <h1 id="cgit-拥抱图形化">cgit 拥抱图形化</h1> | 339 | <h1 id="cgit-拥抱图形化">cgit 拥抱图形化</h1> |
@@ -349,7 +348,7 @@ usermod -aG git www-data</code></pre> | |||
349 | </p> | 348 | </p> |
350 | <h2 id="依赖">依赖</h2> | 349 | <h2 id="依赖">依赖</h2> |
351 | <p><code>nginx</code>/<code>git</code>/<code>vim</code>等工具不必赘述,还有一些依赖项需要安装:</p> | 350 | <p><code>nginx</code>/<code>git</code>/<code>vim</code>等工具不必赘述,还有一些依赖项需要安装:</p> |
352 | <pre><code># apache2-utils是用其htpasswd命令创建认证文件的 | 351 | <pre><code class="language-bash"># apache2-utils是用其htpasswd命令创建认证文件的 |
353 | # fcgiwrap是用于将 FastCGI 转换为 HTTP 协议的工具 | 352 | # fcgiwrap是用于将 FastCGI 转换为 HTTP 协议的工具 |
354 | # 这两个工具上文均已提到和使用,不再赘述 | 353 | # 这两个工具上文均已提到和使用,不再赘述 |
355 | sudo apt update | 354 | sudo apt update |
@@ -363,14 +362,14 @@ sudo apt install -y libssl-dev | |||
363 | sudo apt install liblua5.1-0 liblua5.1-0-dbg liblua5.1-dev lua5.1</code></pre> | 362 | sudo apt install liblua5.1-0 liblua5.1-0-dbg liblua5.1-dev lua5.1</code></pre> |
364 | <h2 id="cgit-安装">cgit 安装</h2> | 363 | <h2 id="cgit-安装">cgit 安装</h2> |
365 | <p>cgit 最近的正式发行版已经好几年了,但是它的开发仍然很活跃,所以建议从它的 git 仓库中获取最新的代码,而非直接安装:</p> | 364 | <p>cgit 最近的正式发行版已经好几年了,但是它的开发仍然很活跃,所以建议从它的 git 仓库中获取最新的代码,而非直接安装:</p> |
366 | <pre><code>git clone https://git.zx2c4.com/cgit | 365 | <pre><code class="language-bash">git clone https://git.zx2c4.com/cgit |
367 | cd cgit | 366 | cd cgit |
368 | git submodule init | 367 | git submodule init |
369 | git submodule update</code></pre> | 368 | git submodule update</code></pre> |
370 | <p>在仓库目录下创建<code>cgit.conf</code>文件,用来存放 cgit 构建时可以覆盖的配置:</p> | 369 | <p>在仓库目录下创建<code>cgit.conf</code>文件,用来存放 cgit 构建时可以覆盖的配置:</p> |
371 | <pre><code>sed -n '3,31p' Makefile > cgit.conf</code></pre> | 370 | <pre><code class="language-bash">sed -n '3,31p' Makefile > cgit.conf</code></pre> |
372 | <p>我们可以按需编辑之:</p> | 371 | <p>我们可以按需编辑之:</p> |
373 | <pre><code>CGIT_VERSION = v1.2.3 | 372 | <pre><code class="language-plaintext">CGIT_VERSION = v1.2.3 |
374 | CGIT_SCRIPT_NAME = cgit.cgi | 373 | CGIT_SCRIPT_NAME = cgit.cgi |
375 | CGIT_SCRIPT_PATH = /var/www/cgit # 本文只改了这里 | 374 | CGIT_SCRIPT_PATH = /var/www/cgit # 本文只改了这里 |
376 | CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH) | 375 | CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH) |
@@ -400,7 +399,7 @@ ASCIIDOC_HTML = xhtml11 | |||
400 | ASCIIDOC_COMMON = $(ASCIIDOC) $(ASCIIDOC_EXTRA) | 399 | ASCIIDOC_COMMON = $(ASCIIDOC) $(ASCIIDOC_EXTRA) |
401 | TXT_TO_HTML = $(ASCIIDOC_COMMON) -b $(ASCIIDOC_HTML)</code></pre> | 400 | TXT_TO_HTML = $(ASCIIDOC_COMMON) -b $(ASCIIDOC_HTML)</code></pre> |
402 | <p>编译 && 安装:</p> | 401 | <p>编译 && 安装:</p> |
403 | <pre><code># 如果不需要lua支持 | 402 | <pre><code class="language-bash"># 如果不需要lua支持 |
404 | make NO_LUA=1 | 403 | make NO_LUA=1 |
405 | # 有lua支持的话 | 404 | # 有lua支持的话 |
406 | make LUA_PKGCONFIG=lua5.1 | 405 | make LUA_PKGCONFIG=lua5.1 |
@@ -411,7 +410,7 @@ sudo make install | tee install.log</code></pre> | |||
411 | <h2 id="nginx-配置">nginx 配置</h2> | 410 | <h2 id="nginx-配置">nginx 配置</h2> |
412 | <p>首先,参照<a href="认证文件">这里</a>生成一个自己的认证文件,再继续往下看。</p> | 411 | <p>首先,参照<a href="认证文件">这里</a>生成一个自己的认证文件,再继续往下看。</p> |
413 | <p>在<code>/etc/nginx/git-http-backend.conf</code>中写入以下内容,注意把域名、ssl 路径、htpasswd 认证文件换成自己的:</p> | 412 | <p>在<code>/etc/nginx/git-http-backend.conf</code>中写入以下内容,注意把域名、ssl 路径、htpasswd 认证文件换成自己的:</p> |
414 | <pre><code># /etc/nginx/git-http-backend.conf | 413 | <pre><code class="language-nginx"># /etc/nginx/git-http-backend.conf |
415 | fastcgi_pass unix:/var/run/fcgiwrap.socket; | 414 | fastcgi_pass unix:/var/run/fcgiwrap.socket; |
416 | include fastcgi_params; | 415 | include fastcgi_params; |
417 | fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend; | 416 | fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend; |
@@ -420,7 +419,7 @@ fastcgi_param GIT_PROJECT_ROOT /home/git; | |||
420 | fastcgi_param PATH_INFO $1; | 419 | fastcgi_param PATH_INFO $1; |
421 | fastcgi_param REMOTE_USER $remote_user;</code></pre> | 420 | fastcgi_param REMOTE_USER $remote_user;</code></pre> |
422 | <p>而后,在<code>/etc/nginx/conf.d/cgit.conf</code>中写:</p> | 421 | <p>而后,在<code>/etc/nginx/conf.d/cgit.conf</code>中写:</p> |
423 | <pre><code># /etc/nginx/conf.d/cgit.conf | 422 | <pre><code class="language-nginx"># /etc/nginx/conf.d/cgit.conf |
424 | server { | 423 | server { |
425 | listen 80; | 424 | listen 80; |
426 | server_name git.player.com; | 425 | server_name git.player.com; |
@@ -491,11 +490,11 @@ server { | |||
491 | } | 490 | } |
492 | }</code></pre> | 491 | }</code></pre> |
493 | <p>最后,重启 nginx 服务:</p> | 492 | <p>最后,重启 nginx 服务:</p> |
494 | <pre><code>sudo nginx -s reload</code></pre> | 493 | <pre><code class="language-bash">sudo nginx -s reload</code></pre> |
495 | <p><em>看吧,一个个仓库,向我们列队走来!</em></p> | 494 | <p><em>看吧,一个个仓库,向我们列队走来!</em></p> |
496 | <h2 id="cgit-高级配置">cgit 高级配置</h2> | 495 | <h2 id="cgit-高级配置">cgit 高级配置</h2> |
497 | <p>可以安装一些包,用于 cgit 的代码高亮、Markdown 渲染、Gravatar 头像渲染等:</p> | 496 | <p>可以安装一些包,用于 cgit 的代码高亮、Markdown 渲染、Gravatar 头像渲染等:</p> |
498 | <pre><code>sudo apt install -y python3-docutils python3-markdown highlight python3-pygments | 497 | <pre><code class="language-bash">sudo apt install -y python3-docutils python3-markdown highlight python3-pygments |
499 | 498 | ||
500 | # 编译安装 LuaoSSL | 499 | # 编译安装 LuaoSSL |
501 | # https://25thandclement.com/~william/projects/luaossl.html | 500 | # https://25thandclement.com/~william/projects/luaossl.html |
@@ -511,7 +510,7 @@ sudo chown -R www-data:www-data /usr/local/share/cgit/ | |||
511 | sudo chmod +x /usr/local/share/cgit/filters/email-gravatar.lua</code></pre> | 510 | sudo chmod +x /usr/local/share/cgit/filters/email-gravatar.lua</code></pre> |
512 | <p>然后编辑上边我们已经指定的配置文件<code>/etc/cgitrc</code>,更多配置项参见<a | 511 | <p>然后编辑上边我们已经指定的配置文件<code>/etc/cgitrc</code>,更多配置项参见<a |
513 | href="https://git.zx2c4.com/cgit/tree/cgitrc.5.txt">cgitrc.5.txt</a>。</p> | 512 | href="https://git.zx2c4.com/cgit/tree/cgitrc.5.txt">cgitrc.5.txt</a>。</p> |
514 | <pre><code># /etc/cgitrc | 513 | <pre><code class="language-plaintext"># /etc/cgitrc |
515 | # 包含 cgit 的所有运行时设置 | 514 | # 包含 cgit 的所有运行时设置 |
516 | # 格式 NAME=VALUE | 515 | # 格式 NAME=VALUE |
517 | # 以 "#" 开头的行是注释 | 516 | # 以 "#" 开头的行是注释 |
@@ -595,7 +594,7 @@ scan-path=/home/git | |||
595 | <p>在上面的配置文件里,我们使用了<a href="https://pygments.org/styles/">Pygments</a>的代码高亮。其默认使用的高亮是 | 594 | <p>在上面的配置文件里,我们使用了<a href="https://pygments.org/styles/">Pygments</a>的代码高亮。其默认使用的高亮是 |
596 | pastie,我们可以根据自己的喜好修改高亮风格。</p> | 595 | pastie,我们可以根据自己的喜好修改高亮风格。</p> |
597 | <p>首先,看看有哪些可用的高亮风格。</p> | 596 | <p>首先,看看有哪些可用的高亮风格。</p> |
598 | <pre><code># 查看可用的高亮风格 | 597 | <pre><code class="language-bash"># 查看可用的高亮风格 |
599 | pygmentize -L styles | 598 | pygmentize -L styles |
600 | 599 | ||
601 | # 编辑我们使用的代码高亮脚本 | 600 | # 编辑我们使用的代码高亮脚本 |
@@ -617,9 +616,9 @@ sudo vim /usr/local/share/cgit/filters/syntax-highlighting.py</code></pre> | |||
617 | <p>cgit 的<a href="https://git.zx2c4.com/cgit/">官网</a>上不仅能实现 Gravatar 头像,还能在鼠标移动到头像上的时候以大图显示。这不是原生功能,而是需要动 | 616 | <p>cgit 的<a href="https://git.zx2c4.com/cgit/">官网</a>上不仅能实现 Gravatar 头像,还能在鼠标移动到头像上的时候以大图显示。这不是原生功能,而是需要动 |
618 | lua 脚本自己实现。原博客大佬在 cgit 的<a | 617 | lua 脚本自己实现。原博客大佬在 cgit 的<a |
619 | href="https://lists.zx2c4.com/pipermail/cgit/2014-March/002036.html">邮件列表</a>找到了实现方式。</p> | 618 | href="https://lists.zx2c4.com/pipermail/cgit/2014-March/002036.html">邮件列表</a>找到了实现方式。</p> |
620 | <pre><code>sudo vim /usr/local/share/cgit/filters/email-libravatar-korg.lua</code></pre> | 619 | <pre><code class="language-bash">sudo vim /usr/local/share/cgit/filters/email-libravatar-korg.lua</code></pre> |
621 | <p>在脚本中写入以下内容:</p> | 620 | <p>在脚本中写入以下内容:</p> |
622 | <pre><code>-- This script may be used with the email-filter or repo.email-filter settings in cgitrc. | 621 | <pre><code class="language-lua">-- This script may be used with the email-filter or repo.email-filter settings in cgitrc. |
623 | -- It adds gravatar icons to author names. It is designed to be used with the lua: | 622 | -- It adds gravatar icons to author names. It is designed to be used with the lua: |
624 | -- prefix in filters. It is much faster than the corresponding python script. | 623 | -- prefix in filters. It is much faster than the corresponding python script. |
625 | -- | 624 | -- |
@@ -656,7 +655,7 @@ function filter_write(str) | |||
656 | buffer = buffer .. str | 655 | buffer = buffer .. str |
657 | end</code></pre> | 656 | end</code></pre> |
658 | <p>只有 lua 还不够,我们需要将以下内容添加到<code>/var/www/cgit/cgit.css</code>中:</p> | 657 | <p>只有 lua 还不够,我们需要将以下内容添加到<code>/var/www/cgit/cgit.css</code>中:</p> |
659 | <pre><code>/* libgravatar */ | 658 | <pre><code class="language-css">/* libgravatar */ |
660 | div#cgit span.libravatar img.onhover { | 659 | div#cgit span.libravatar img.onhover { |
661 | display: none; | 660 | display: none; |
662 | border: 1px solid gray; | 661 | border: 1px solid gray; |
@@ -697,7 +696,7 @@ div#cgit span.libravatar:hover > img.onhover { | |||
697 | <p>对于 cgit 显示出来的界面,你可能并不太满意(比如我就嫌界面的字太小、颜色不舒适啥的)。修改办法也很简单,找到<code>/var/www/cgit/cgit.css</code>文件,然后修改之。</p> | 696 | <p>对于 cgit 显示出来的界面,你可能并不太满意(比如我就嫌界面的字太小、颜色不舒适啥的)。修改办法也很简单,找到<code>/var/www/cgit/cgit.css</code>文件,然后修改之。</p> |
698 | <p>而对于我们的 Markdown 或者别的什么语言写的 README,如果觉得渲染效果不好,都是可以自己去修改的。</p> | 697 | <p>而对于我们的 Markdown 或者别的什么语言写的 README,如果觉得渲染效果不好,都是可以自己去修改的。</p> |
699 | <p>找到<code>/usr/local/share/cgit/filters/about-formatting.sh</code>文件,我们会看到以下内容:</p> | 698 | <p>找到<code>/usr/local/share/cgit/filters/about-formatting.sh</code>文件,我们会看到以下内容:</p> |
700 | <pre><code>#!/bin/sh | 699 | <pre><code class="language-bash">#!/bin/sh |
701 | 700 | ||
702 | # This may be used with the about-filter or repo.about-filter setting in cgitrc. | 701 | # This may be used with the about-filter or repo.about-filter setting in cgitrc. |
703 | # It passes formatting of about pages to differing programs, depending on the usage. | 702 | # It passes formatting of about pages to differing programs, depending on the usage. |
@@ -741,6 +740,7 @@ esac</code></pre> | |||
741 | </ul> | 740 | </ul> |
742 | <p>这篇博客前前后后有二十多天了,有空再折腾吧。看电视去也~</p> | 741 | <p>这篇博客前前后后有二十多天了,有空再折腾吧。看电视去也~</p> |
743 | <!-- 2024.1.3 --> | 742 | <!-- 2024.1.3 --> |
743 | <p class="time">2024.1.3</p> | ||
744 | <script src="https://www.qin-juan-ge-zhu.top/common/js/comment.js"></script> | 744 | <script src="https://www.qin-juan-ge-zhu.top/common/js/comment.js"></script> |
745 | </div> | 745 | </div> |
746 | </div> | 746 | </div> |