summaryrefslogtreecommitdiff
path: root/cgit.html
diff options
context:
space:
mode:
authorLuke Smith <luke@lukesmith.xyz>2021-09-14 14:07:45 -0400
committerLuke Smith <luke@lukesmith.xyz>2021-09-14 14:07:45 -0400
commit8b00228bbf202f6982c4228892beede22bb27cca (patch)
tree54e145d4ffe850838c09798f15221757d48fbfc7 /cgit.html
parent208d31af3e0cd8141aa27ef02695f388ecd352fb (diff)
cgit
Diffstat (limited to 'cgit.html')
-rw-r--r--cgit.html151
1 files changed, 151 insertions, 0 deletions
diff --git a/cgit.html b/cgit.html
new file mode 100644
index 0000000..2ca026d
--- /dev/null
+++ b/cgit.html
@@ -0,0 +1,151 @@
+<!DOCTYPE html>
+<html lang=en>
+
+<head>
+ <title>Setting up Cgit &ndash; LandChad.net</title>
+ <meta charset="utf-8" />
+ <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
+ <link rel='stylesheet' type='text/css' href='style.css'>
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <link rel='alternate' type='application/rss+xml' title='Land Chad RSS' href='/rss.xml'>
+</head>
+
+<body>
+ <header>
+ <h1>Setting up Cgit</h1>
+ <img src="pix/cgit.svg" class="titleimg">
+ </header>
+ <main>
+ <p>
+ Once you have your server hosting your git repositories, you might want to allow others to browse
+ your repositories on the web. Cgit is a Free Software that allows browsing git repositories through
+ the web. </p>
+
+ <p>
+ Note that Cgit is a read-only frontend for Git repositories and doesn't have issues, pull requests
+ or user management. If that's what you want, consider installing Gitea instead.</p>
+
+ <h2>Installing cgit and fcgiwrap</h2>
+ <h3>Install fcgiwrap</h3>
+ <p>
+ NGINX doesn't have the capability to run CGI scripts by itself, it depends on an intermediate layer
+ like fcgiwrap to run CGI scripts like cgit:</p>
+
+ <pre><code>apt install fcgiwrap</code></pre>
+
+ <p>And now we can install cgit itself with:</p>
+
+ <pre><code>apt install cgit</code></pre>
+
+ <h2>Setting up NGINX</h2>
+ <p>
+ You should have an NGINX server running with a TLS certificate by now. Add the following configuration
+ to your server to pass the requests to Cgit, while serving static files directly:</p>
+
+ <pre><code>
+server {
+ listen 443 ssl;
+ listen [::]:443 ssl;
+ ssl_certificate /etc/ssl/nginx/<strong>git.example.org</strong>.crt;
+ ssl_certificate_key /etc/ssl/nginx/<strong>git.example.org</strong>.key;
+ server_name <strong>git.example.org</strong>;
+
+ root /usr/share/cgit ;
+ try_files $uri @cgit ;
+
+ location @cgit {
+ include fastcgi_params;
+ fastcgi_param SCRIPT_FILENAME /usr/lib/cgit/cgit.cgi;
+ fastcgi_param PATH_INFO $request_uri;
+ fastcgi_param QUERY_STRING $query_string;
+ fastcgi_pass unix:/run/fcgiwrap.socket;
+ }
+}
+ </code></pre>
+
+ <p>Then get NGINX to reload your configuration.</p>
+
+ <h2>Configuring cgit</h2>
+ <p>You've got cgit up and running now, but you'll probably see it without any style and without any repository.
+ To change this, we need to configure Cgit to our liking, by editing <code>/etc/cgitrc</code>.
+ </p>
+
+ <pre><code>
+css=/cgit.css
+logo=/cgit.svg
+virtual-root=/
+
+# Title and description shown on top of each page
+root-title=<strong>Chad's git server</strong>
+root-desc=<strong>A web interface to LandChad's git repositories, powered by Cgit</strong>
+
+# The location where git repos are stored on the server
+scan-path=/srv/git/
+ </code></pre>
+
+ <p>This configuration assumes you followed the <a href="/git">git hosting guide</a> and store your repositories
+ on the <code>/srv/git/</code> directory.</p>
+
+ <p>Cgit's configuration allows changing many settings, as documented on the cgitrc(5) manpage installed with
+ Cgit.</p>
+
+ <h3>Changing the displayed repository owner</h3>
+
+ <p>Cgit's main page shows each repo's owner, which is "git" in case you followed the git hosting guide, but you
+ might want to change the name to yours. Cgit shows the owner's system name, so you need to modify the git
+ user
+ to give it your name:</p>
+
+ <pre><code>
+usermod -c "<strong>Your Name</strong>" git
+ </code></pre>
+
+ <h3>Changing the repository description</h3>
+
+ <p>Navigate to your bare repository on the server and edit the <code>description</code> file inside it</p>
+
+ <h3>Displaying the repository idle time</h3>
+
+ <p>To do this, we need to create a post-receive hook for each repository that updates the file cgit uses
+ to determine the idle time. Inside your repository, create a file <code>hooks/post-receive</code> and add
+ the following contents:</p>
+
+ <pre><code>
+#!/bin/sh
+
+agefile="$(git rev-parse --git-dir)"/info/web/last-modified
+
+mkdir -p "$(dirname "$agefile")" &&
+git for-each-ref \
+ --sort=-authordate --count=1 \
+ --format='%(authordate:iso8601)' \
+ >"$agefile"
+ </code></pre>
+
+ <p>And give it execution permissions with:</p>
+
+ <pre><code>chmod +x hooks/post-receive</code></pre>
+
+ <p>Next time you push to that repository, the idle time should reset and show the correct value.</p>
+
+ <h2>Contribution</h2>
+ <ul>
+ <li>Ariel Costas &ndash; <a href="https://costas.dev">website</a>, <a
+ href="https://costas.dev/donations/">donations</a></li>
+ </ul>
+ </main>
+ <footer><a href="https://landchad.net">LandChad.net</a></br>Because Everyone should be an Internet LandChad.</br><a
+ href="index.html">
+ <li><img src="pix/chad.gif" alt="chad"></li>
+ </a><a href="rss.xml">
+ <li><img src="pix/rss.svg" alt="RSS"></li>
+ </a><a href="pix/btc.png">
+ <li><img src="pix/btc.svg" alt="BTC"></li>
+ </a><a href="pix/xmr.png">
+ <li><img src="pix/xmr.svg" alt="XMR"></li>
+ </a><a href="https://github.com/lukesmithxyz/landchad">
+ <li><img src="pix/git.svg" alt="Github"></li>
+ </a></footer>
+</body>
+
+</html>