======stagit – Static Git Web Interface======
Stagit generates static HTML pages for a git repository. This guide assumes that you already have a git user on your system.
=====Installation=====
Install stagit:
git clone git://git.codemadness.org/stagit
cd stagit
make
make install
And install git:
apt install git
useradd -m git -d /var/git -s /bin/bash
=====nginx (server side)=====
Our stagit projects only need a repo folder for (of course) our bare repos and a html folder for (guess what) our from stagit generated html files.
mkdir -p /var/www/stagit/repos
git init --bare /var/www/stagit/repos/project1.git ← we need this
git init --bare /var/www/stagit/repos/project2.git ← and this later
mkdir -p /var/www/stagit/html
mkdir -p /var/www/stagit/html/project1
mkdir -p /var/www/stagit/html/project2
Create the file ''%%/etc/nginx/sites-available/stagit%%'' and add the following (i highly recommend using a central enryptfile):
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name git.example.com www.git.example.com;
root /var/www/stagit/html;
index index.html;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
location / {
try_files $uri $uri/ =404;
}
location ~ /\. {
deny all;
}
}
server {
listen 80;
listen [::]:80;
server_name git.example.com www.git.example.com;
return 301 https://$host$request_uri;
}
Then copy your basic website files to the stagit folder (here is an example [[https://git.marlonivo.com/style.css|style.css]]):
/var/www/stagit/html
├── project2
├── project1
├── style.css ← 1.
├── favicon.ico ← 2.
└── logo.png ← 3.
Set the right permissions for the complete directory, ''%%www-data%%'' for nginx and ''%%git%%'' for git:
chown -R git:www-data /var/www/stagit
At last enable the site and restart nginx:
ln -s /etc/nginx/sites-available/stagit /etc/nginx/sites-enabled/
systemctl reload nginx
=====stagit (local side)=====
Then go to your local project directory and initialise a git project, point it to your server's project destination and optionally set your git user name and mail:
cd project1
git init
git remote add stagit git@git.example.org:/var/www/stagit/repos/project1.git
git remote -v
git config user.name "Your Name"
git config user.email "your@mail.com"
Now inside your freshly generated bare git folder found in ''%%.git%%'', change the project description, the owner name and the clone url as well as creating a git-daemon-export-ok (leave empty) in order to let anyone clone your repo.
/project1/.git/
├── description ← 1.
├── owner ← 2.
├── url ← 3.
└── git-daemon-export-ok ← 4.
As well as in your ''%%.git/hooks%%'' folder add a ''%%post-receive%%'' script to update all necessary files after git pushing to your server (change file destination and repo name accordingly) with the following content:
#!/bin/sh
set -eu
REPO_NAME="project1"
REPO="/var/www/stagit/repos/${REPO_NAME}.git"
HTML_DIR="/var/www/stagit/html/${REPO_NAME}"
rm -rf "$HTML_DIR"
mkdir -p "$HTML_DIR"
cd "$HTML_DIR"
stagit "$REPO"
cd /var/www/stagit/html
stagit-index ../repos/*.git > index.html
ln -sf style.css "$HTML_DIR"
ln -sf logo.png "$HTML_DIR"
ln -sf favicon.png "$HTML_DIR"
I also created an alias script in my ''%%.config/shell/aliasrc%%'' so i only have to type git-sync.
git-sync() {
printf "Commit message: "
read -r msg
git add .
git commit -m "$msg"
git push stagit master
# git push aur master <- if you own aur
# git push github master <- and github remotes
}
=====Cloning=====
Create a systemd unit on your server:
vim /etc/systemd/system/git-daemon.service
With the following Content:
[Unit]
Description=Git Daemon
After=network.target
[Service]
ExecStart=/usr/bin/git-daemon \
--base-path=/var/www/stagit/repos \
--export-all \
--reuseaddr \
--informative-errors \
--verbose
User=git
Group=git
Restart=always
[Install]
WantedBy=multi-user.target
Activate it:
sudo systemctl daemon-reexec
sudo systemctl enable --now git-daemon.service
Then open port 9418 in your firewall to let anyone clone your repo:
sudo ufw allow 9418/tcp
Now you can do something like:
git clone git://git.example.org/project1
Finish! Enjoy your own statit git server \(^O^)/.