Compare commits

...

10 Commits

10 changed files with 184 additions and 81 deletions

View File

@ -1,37 +1,34 @@
# stagit
> static git page generator
## Information
#### Information
This is my personal fork of [stagit](https://codemadness.org/stagit.html) which is running [git.acid.vegas](https://git.acid.vegas/)
## Dependencies
- C compiler *(C99)*
- libc *(tested with OpenBSD, FreeBSD, NetBSD, Linux: glibc & musl)*
- [libgit2](https://github.com/libgit2/libgit2) *(v0.22+)*
- [md4c](https://github.com/mity/md4c) *(v0.4.4+)*
- POSIX make *(optional)*
## Setup
```shell
cd stagit
make
sudo make install
```
## Features & Issues
###### Features
- Markdown rendering to HTML for README files
- ~~Syntax hilighting~~
- Repository categories
- Direct download to repository tar.gz
- Style changes
- ~~Raw file viewing~~
###### New Features
- [X] Markdown rendering to HTML for README files
- [ ] Syntax hilighting
- [X] Repository categories
- [ ] Direct download to repository tar.gz
- [X] Style changes
- [ ] Raw file viewing
###### Fixes
###### Issues
- [ ] Clickable heading *(h1-h6)* links in README *(md4c does not FULLY transform markdown)*
- [ ] Top/bottom padding for multi-lined `<code>` blocks
- [ ] Missing image references in README files *(md4c does not look in /files/ for the .screens directory)*
- [ ] Generating html for binary content is pointless. No links at all for these files.
###### Props
## Props
- Hiltjo Posthuma *(orignal author of [stagit](https://codemadness.org/git/stagit/))*
- Larry Burns *([stagit-md](https://github.com/lmburns/stagit-md))*
- Oscar Benedito *([md4c implementation](https://oscarbenedito.com/blog/2020/08/adding-about-pages-to-stagit/))*
- Oscar Benedito *([md4c implementation](https://oscarbenedito.com/blog/2020/08/adding-about-pages-to-stagit/))*
___
###### Mirrors
[acid.vegas](https://git.acid.vegas/stagit) • [GitHub](https://github.com/acidvegas/stagit) • [GitLab](https://gitlab.com/acidvegas/stagit) • [SuperNETs](https://git.supernets.org/acidvegas/stagit)

32
assets/deploy-git Executable file
View File

@ -0,0 +1,32 @@
#!/bin/sh
apt-get install -y git
[ ! $(grep -q /usr/bin/git-shell /etc/shells) ] && echo "/usr/bin/git-shell" >> /etc/shells
[ ! $(getent passwd git) ] && userdel -f git
useradd -d /srv/git -k /dev/null -m -s /usr/bin/git-shell -U git
mkdir -p /srv/git/git-shell-commands && wget -O /srv/git/git-shell-commands https://raw.githubusercontent.com/acidvegas/stagit/master/assets/repo
chmod +x /srv/git/git-shell-commands/* && chown -R git:git /srv/git/git-shell-commands
usermod -p '*' git
printf "[Unit]\nDescription=Start Git Daemon\n\n[Service]\nExecStart=/usr/bin/git daemon --reuseaddr --base-path=/srv/git/ /srv/git/\n\nRestart=always\nRestartSec=500ms\nUser=git\nGroup=git\n\n[Install]\nWantedBy=multi-user.target\n" > /etc/systemd/system/git-daemon.service
systemctl start git-daemon && systemctl enable git-daemon
echo "Be sure to use 'AuthorizedKeysFile /etc/ssh/authorized_keys/%u' in your /etc/ssh/sshd_config"
echo "Add your public key to /etc/ssh/authorized_keys/git prefixed with 'no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty'"
apt-get install libmd4c-dev libmd4c-html0 libmd4c-html0-dev libmd4c0
apt-get install libgit2-dev
certbot --nginx -d example.com -d www.example.com
git config --system init.defaultBranch main # <- THIS MOTHER FUCKER
# Not finished yet
git clone https://github.com/acidvegas/stagit
#STAGIT_CFLAGS += -DGIT_OPT_SET_OWNER_VALIDATION=-1
Makefile uncomment

View File

@ -7,65 +7,57 @@ URL="git.acid.vegas"
PROTO="https"
CLONE_URL="git://$URL"
COMMIT_LIMIT=100
HTML_DIR="$HOME/dev/git/acidvegas/git.acid.vegas"
REPOS_DIR="$HOME/dev/git"
REPOS_EXCLUDE="git.acid.vegas mirror readme"
find_repos() {
args=""
for dir in $REPOS_EXCLUDE; do
args="$args -type d -name $dir -prune -o"
done
echo "$(find $1 $args -type d -name .git -printf "%h\\n " | sort | xargs echo)"
}
HTML_DIR="/srv/http"
REPOS_DIR="/srv/git"
prepair() {
[ -d $HTML_DIR ] && rm -rf $HTML_DIR/*
mkdir -p $HTML_DIR/assets
echo "[~] populating custom assets..."
cp acidvegas.png favicon.png logo.png mostdangerous.png style.css $HTML_DIR/assets
echo $URL > $HTML_DIR/CNAME
}
make_index() {
echo "[~] creating index..."
args=""
for dir in $(ls $REPOS_DIR | grep -v 'mirror'); do
echo "[~] indexing '$dir' repositories..."
DIR_REPOS="$(find_repos $REPOS_DIR/$dir)"
args="$args -c \"$dir\" $DIR_REPOS"
done
args=""
for category in $(cat /srv/git/*/owner | xargs -n1 | sort -u | xargs); do
echo "[~] indexing '$category' repositories..."
REPOS=$(grep -rl "$category" /srv/git/*/owner | xargs -I{} dirname {} | sort -f | tr '\n' ' ')
args="$args -c \"$category\" $REPOS"
done
echo "$args" | xargs stagit-index > $HTML_DIR/index.html
echo "[+] finished"
}
make_repos() {
for dir in $(find_repos $REPOS_DIR); do
USER=$(basename $(dirname $dir))
REPO=$(basename $dir)
if [ -f $dir/.git/description ]; then
if [ "$(cat $dir/.git/description)" = "Unnamed repository; edit this file 'description' to name the repository." ]; then
read -p "description for '$USER/$REPO':" desc
echo "$desc" > $dir/.git/description
echo "[+] updated default 'description' file for '$REPO'"
fi
else
read -p "description for '$USER/$REPO':" desc
echo "$desc" > $dir/.git/description
echo "[+] added missing 'description' file for '$REPO'"
make_repo() {
REPO=$(basename "$(echo "$1" | sed 's/\.git$//')")
if [ -f $1/description ]; then
if [ "$(cat $1/description)" = "Unnamed repository; edit this file 'description' to name the repository." ]; then
read -p "description for '$REPO':" desc
echo "$desc" > $1/description
echo "[+] updated default 'description' file for '$REPO'"
fi
if [ ! -f $dir/.git/url ]; then
echo "$CLONE_URL/$REPO.git" > $dir/.git/url
echo "[+] added missing 'url' file for '$REPO'"
fi
echo "[~] processing '$REPO' repository..."
mkdir -p $HTML_DIR/$REPO && cd $HTML_DIR/$REPO && stagit -l $COMMIT_LIMIT -u "$PROTO://$URL/$REPO" $dir
ln -sf log.html index.html
git --git-dir $dir/.git archive --format=tar.gz -o "$HTML_DIR/$REPO/$REPO.tar.gz" --prefix="$REPO/" HEAD
else
read -p "description for '$REPO':" desc
echo "$desc" > $1/description
echo "[+] added missing 'description' file for '$REPO'"
fi
if [ ! -f $1/url ]; then
echo "$CLONE_URL/$REPO.git" > $1/url
echo "[+] added missing 'url' file for '$REPO'"
fi
echo "[~] processing '$REPO' repository..."
mkdir -p $HTML_DIR/$REPO && cd $HTML_DIR/$REPO && stagit -l $COMMIT_LIMIT -u "$PROTO://$URL/$REPO" $1
ln -sf log.html index.html
git --git-dir $1 archive --format=tar.gz -o "$HTML_DIR/$REPO/archive.tar.gz" --prefix="$REPO/" HEAD
}
make_all_repos() {
for dir in $(find $REPOS_DIR -type d -name "*.git" | sort); do
make_repo $dir
done
}
# Main
prepair
make_repos
make_index
make_all_repos
make_index

24
assets/post-receive Executable file
View File

@ -0,0 +1,24 @@
#!/bin/sh
# stagit post-receive script - developed by acidevegas (https://git.acid.vegas/stagit)
URL="git.acid.vegas"
PROTO="https"
CLONE_URL="git://$URL"
COMMIT_LIMIT=100
HTML_DIR="/srv/http"
DIR="$PWD"
REPO=$(basename "$DIR" .git)
command -v stagit >/dev/null 2>&1 || { echo "stagit not found" >&2; exit 1; }
mkdir -p "$HTML_DIR/$REPO" || { echo "Failed to create directory $HTML_DIR/$REPO" >&2; exit 1; }
if cd "$HTML_DIR/$REPO"; then
stagit -l "$COMMIT_LIMIT" -u "$PROTO://$URL/$REPO" "$DIR" || { echo "stagit failed to generate static pages" >&2; exit 1; }
ln -sf log.html index.html
git --git-dir="$DIR" archive --format=tar.gz -o "$HTML_DIR/$REPO/archive.tar.gz" --prefix="$REPO/" HEAD || { echo "git archive failed" >&2; exit 1; }
else
echo "Failed to change directory to $HTML_DIR/$REPO" >&2
exit 1
fi

View File

@ -1,14 +0,0 @@
#!/bin/sh
# stagit post-recieve script - developed by acidevegas (https://git.acid.vegas/stagit)
URL="git.acid.vegas"
PROTO="https"
CLONE_URL="git://$URL"
COMMIT_LIMIT=100
HTML_DIR="/srv/http"
DIR=$PWD
REPO=$(basename $DIR .git)
mkdir -p $HTML_DIR/$REPO && cd $HTML_DIR/$REPO && stagit -l $COMMIT_LIMIT -u "$PROTO://$URL/$REPO" $DIR
ln -sf log.html index.html
git --git-dir $DIR archive --format=tar.gz -o "$HTML_DIR/$REPO/$REPO.tar.gz" --prefix="$REPO/" HEAD

56
assets/repo Executable file
View File

@ -0,0 +1,56 @@
#!/bin/sh
# git-shell-commands helper for stagit - developed by acidvegas (https://git.acid.vegas/stagit)
check_description() {
if [ -f $1/description ]; then
if [ "$(cat $1/description)" = "Unnamed repository; edit this file 'description' to name the repository." ]; then
read -p "description for '$REPO':" desc
echo "$desc" > $1/description
echo "[+] updated default 'description' file for '$REPO'"
fi
else
read -p "description for '$REPO':" desc
echo "$desc" > $1/description
echo "[+] added missing 'description' file for '$REPO'"
fi
}
remake_index() {
echo "[~] recreating index..."
args=""
for category in $(cat /srv/git/*/owner | xargs -n1 | sort -u | xargs); do
echo "[~] indexing '$category' repositories..."
REPOS=$(grep -rl "$category" /srv/git/*/owner | xargs -I{} dirname {} | sort -f | tr '\n' ' ')
args="$args -c \"$category\" $REPOS"
done
echo "$args" | xargs stagit-index > $HTML_DIR/index.html
}
if [ "$#" -ne 2 ]; then
echo "invalid arguments (use -c or -d)" >&2
exit 1
fi
if [ "$1" = '-c' ]; then
if [ -d "$2.git" ]; then
echo "repository already exists" >&2
exit 1
fi
if [ ! -f post-receive ]; then
echo "missing post-receive script" >&2
exit 1
fi
mkdir "$2.git" && git init --bare "$2.git" || exit 1
touch "$2.git/git-daemon-export-ok"
ln /srv/git/git-shell-commands/post-receive "$2.git/hooks/post-receive" || exit 1
echo "https://git.acid.vegas/$2.git" > "$2.git/url"
elif [ "$1" = '-d' ]; then
if [ ! -d "$2.git" ]; then
echo "repository does not exist" >&2
exit 1
fi
rm -rf "$2.git"
else
echo "invalid arguments (use -c or -d)" >&2
exit 1
fi

14
assets/sshd_config Normal file
View File

@ -0,0 +1,14 @@
AuthenticationMethods publickey
AuthorizedKeysFile /etc/ssh/authorized_keys/%u
ClientAliveInterval 0
DisableForwarding yes
PermitRootLogin no
Port 22
Port CHANGEME
PrintLastLog no
Match LocalPort 22
AllowUsers git
Match LocalPort CHANGEME
AllowUsers acidvegas

View File

@ -28,7 +28,7 @@ td.num{text-align:right;}
a.d, a.h, a.i, a.line {text-decoration:none;}
h1, h2, h3, h4, h5, h6{font-size:1em;margin:0;}
img, h1, h2{vertical-align middle;}
img, h1, h2{vertical-align: middle;}
#branches tr td:nth-child(3),
#branches tr:hover td, #tags tr:hover td{background-color:#111;}
#tags tr td:nth-child(3){white-space:normal;}

View File

@ -83,7 +83,7 @@ void writeheader(FILE *fp) {
fputs("<center>\n<img src=\"/assets/acidvegas.png\"><br>\n<img src=\"/assets/mostdangerous.png\"><br><br>\n", fp);
fputs("<div class=\"container\">\n\t<center>\n\t<table>\n\t\t<tr><td>\n"
"<b>contact</b> : <a href=\"https://discord.gg/BCqRZZR\">discord</a> &bull; <a href=\"ircs://irc.supernets.org/superbowl\">irc</a> &bull; <a href=\"mailto://acid.vegas@acid.vegas\">mail</a> &bull; <a href=\"https://twitter.com/acidvegas\">twitter</a>\n"
"<br><b>mirrors</b> : <a href=\"https://github.com/acidvegas\">github</a> &bull; <a href=\"https://gitlab.com/acidvegas\">gitlab</a> &bull; <a href=\"https://git.sr.ht/~acidvegas\">sourcehut</a> &bull; <a href=\"https://git.supernets.org/acidvegas\">supernets</a>\n"
"<br><b>mirrors</b> : <a href=\"https://github.com/acidvegas\">github</a> &bull; <a href=\"https://gitlab.com/acidvegas\">gitlab</a> &bull; <a href=\"https://git.supernets.org/acidvegas\">supernets</a>\n"
"\t\t</td></tr>\n\t</table>\n\t</center>\n</div>\n<br>\n", fp);
fputs("<div id=\"content\">\n\t<table id=\"index\">\n\t\t<thead>\n\t\t\t<tr><td>Name</td><td>Description</td><td>Last commit</td></tr>\n\t\t</thead>\n\t\t<tbody>", fp);
}

View File

@ -493,7 +493,8 @@ void writeheader(FILE *fp, const char *title) {
fputs("\t\t<tr><td>\n", fp);
fprintf(fp, "<a href=\"%slog.html\">Log</a> | ", relpath);
fprintf(fp, "<a href=\"%sfiles.html\">Files</a> | ", relpath);
fprintf(fp, "<a href=\"%srefs.html\">Refs</a>", relpath);
fprintf(fp, "<a href=\"%srefs.html\">Refs</a> | ", relpath);
fprintf(fp, "<a href=\"%sarchive.tar.gz\">Archive</a>", relpath);
if (submodules)
fprintf(fp, " | <a href=\"%sfile/%s.html\">Submodules</a>", relpath, submodules);
if (readme)
@ -501,6 +502,7 @@ void writeheader(FILE *fp, const char *title) {
fprintf(fp, " | <a href=\"%sREADME.html\">README</a>", relpath);
if (license)
fprintf(fp, " | <a href=\"%sfile/%s.html\">LICENSE</a>", relpath, license);
fputs("</td></tr>\n\t</table>\n</div>\n<br>\n", fp);
}