ref: 8fff3bb075833db2da787166eb861075f7544473
author: glenda <[email protected]>
date: Sat Nov 28 16:47:51 EST 2020
shithub: initial commit Based off the files in git9/extra, but customized to handle multiple users.
--- /dev/null
+++ b/gitrules
@@ -1,0 +1,5 @@
+/repos.html /bin/shithub /usr/git list
+/([^'/]+)/info.html /bin/shithub /usr/git info '\1' '\2' HEAD
+/([^'/]+)/([^'/]+)/([^'/]+)/info.html /bin/shithub /usr/git info '\1' '\2' '\3'
+/([^'/]+)/([^'/]+)/([^'/]+)/snap.tar.gz /bin/shithub /usr/git tar '\1' '\2' '\3'
+/([^'/]+)/([^'/]+)/([^'/]+)/(([^']+)/)?f.html /bin/shithub /usr/git view '\1' '\2' '\3' '\5'
--- /dev/null
+++ b/mkfile
@@ -1,0 +1,3 @@
+install:
+ cp shithub newrepo /rc/bin
+ cp gitrules /sys/lib/tcp80
--- /dev/null
+++ b/newrepo
@@ -1,0 +1,25 @@
+#!/bin/rc -e
+
+flagfmt='p:priv, d:desc desc, c:contact contact'
+args='[repo ...]'
+eval `''{aux/getflags $*} || exec aux/usage
+
+fn whoami{
+ if(test -f /adm/keys.who){
+ if(~ $email '')
+ email=`{awk -F'|' '$1=="'$user'" {x=$5} END{print x}' </adm/keys.who}
+ }
+ if(~ $email '')
+ [email protected]
+}
+
+cd /usr/git/$user
+for(repo in $*){
+ git/init $1
+ if(~ $#priv 0)
+ touch $1/.git/webpublish
+ if(! ~ $#desc 0)
+ echo $desc >$1/.git/desc
+ if(! ~ $#contact 0)
+ echo $contact >$1/.git/contact
+}
--- /dev/null
+++ b/shithub
@@ -1,0 +1,203 @@
+#!/bin/rc -e
+
+cd $1
+shift
+
+rfork ne
+nl='
+'
+
+fn htcat {
+ sed '
+ s/&/\&/g;
+ s/</\</g;
+ s/>/\>/g;
+ s/"/\"/g;
+ s/''/\'/g
+ ' $*
+}
+
+fn resolveref {
+ if(~ $refname HEAD)
+ echo $refname
+ if not if(test -d /mnt/git/branch/$refname/tree)
+ echo branch/$refname
+ if not if(test -d /mnt/git/object/$refname/tree)
+ echo object/$refname
+ if not
+ status='bad ref'
+}
+
+fn repons {
+ mntgen
+ mntgen /mnt/mnt
+ bind /bin /mnt/bin
+ bind /tmp /mnt/tmp
+ bind -c /env /mnt/env
+ bind $1/$2 /mnt/$repo
+ bind /mnt /
+ cd /mnt/$repo
+ git/fs
+ rfork m
+}
+
+
+fn prelude {
+ echo '
+ <!DOCTYPE html>
+ <html>
+
+ <head>
+ <style type="text/css">
+ body{
+ margin: 3em auto;
+ max-width: 50em;
+ font-family: sans-serif;
+ }
+ h1,h2{
+ font-size: 1.3em;
+ color: #4c4c99;
+ }
+ h3{
+ font-size: 1em;
+ color: #4c4c99;
+ }
+
+ #code{
+ background: #ffffea;
+ border: #99994cff
+ }
+ </style>
+ <link rel="alternate" type="application/rss+xml" href="feed.rss" title="rss">
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>Shithub</title>
+ </head>
+ <body>
+ '
+}
+
+switch($1){
+case 'list'
+ rfork m
+ prelude
+ echo ' <h1>Repos</h1>
+ <dl>'
+ for(repo in `$nl{ls */}){
+ if(test -e $repo/.git/webpublish){
+ echo '<dt><a href="/git/'$repo'/HEAD/info.html">'$repo'</a></dt>'
+ echo '<dd>'
+ if(test -f $repo/.git/desc)
+ htcat $repo/.git/desc
+ if not
+ echo 'code some guy wrote'
+ echo '</dd>'
+ }
+ }
+ echo '</dl>'
+
+case 'tar'
+ gituser=$2
+ repo=$3
+ refname=$4
+
+ repons $gituser $repo
+ if(! ref=`{resolveref $refname}){
+ echo '<b>invalid ref '$refname'</b>'
+ exit
+ }
+ bind /mnt/git/$ref/tree /mnt/$repo
+ cd /mnt
+ tar cz $repo
+
+case 'info'
+ gituser=$2
+ repo=$3
+ refname=$4
+
+ repons $gituser $repo
+ repodir=/mnt/$repo/.git
+ if(! ref=`{resolveref $refname}){
+ echo '<b>invalid ref '$refname'</b>'
+ exit
+ }
+ cd /mnt/git/$ref/tree
+ hash=`{cat /mnt/git/$ref/hash}
+
+ prelude $repo $ref $repo
+ echo ' <h1><a href="/git/repos.html">Git</a>: <a
+ href=/git/'$gituser/$repo'/'$ref'/info.html>'$repo'</a></h1>
+ <p>'$repo' @ <a href='/git/$gituser/$repo/$hash/f.html'>'$hash'</a>
+ <pre id="desc">'
+ htcat /mnt/git/object/$hash/msg
+ echo ' </pre>
+ <h2>Code</h2>
+ <p>
+ <b>clone:</b> git://orib.dev/'$gituser/$repo', gits://orib.dev/'$gituser/$repo'<br>
+ <b>push:</b> hjgit://orib.dev/'$gituser/$repo'<br>
+ <b>tar:</b> <a href="'/git/$gituser/$repo/$hash/snap.tar.gz'">snap.tar.gz</a><br>'
+ if(test -f $repodir/contact)
+ echo '<b>patches to: </b>'^`$nl{cat $repodir/contact}^'<br>
+ </p>'
+
+ echo '<pre id="code">'
+ for(f in `$nl{ls}){
+ url=`$nl{echo -n $f/f.html | urlencode}
+ fname=`$nl{echo -n $f | htcat}
+ echo '<a href="'$url'">'$fname'</a>'
+ }
+ echo '</pre>
+
+ <h2>About This Repo</h2>
+ <pre id="desc">'
+ if(test -f $repodir/README)
+ htcat $repodir/README
+ if not if(test -f README)
+ htcat README
+ if not if (test -f README.md)
+ htcat README.md
+ if not if(test -f $repodir/desc)
+ htcat $repodir/desc
+ if not
+ echo 'this repo has no description'
+ echo '
+ </pre>
+ </body>
+ </html>
+ '
+
+case 'view'
+ gituser=$2
+ repo=$3
+ refname=$4
+ file=$5
+
+ repons $gituser $repo
+ if(! ref=`{resolveref $refname}){
+ echo '<b>invalid ref '$refname'</b>'
+ exit
+ }
+ cd /mnt/git/$ref/tree
+ if(~ $file '')
+ file='.'
+ hash=`{cat /mnt/git/$ref/hash}
+
+ prelude
+ echo ' <h1><a href="/git/repos.html">Git</a>: <a
+ href='/git/$gituser/$repo/$ref/info.html'>'$repo'</a></h1>
+ <p>'$repo' @ <a href="'/git/$gituser/$repo/$hash/f.html'">'$hash'</a>
+ <pre id="code">'
+ if(test -f $file){
+ htcat $file
+ }
+ if not if(test -d $file){
+ cd $file
+ for(f in `$nl{ls}){
+ url=`$nl{echo -n $f/f.html | urlencode}
+ fname=`$nl{echo -n $f | htcat}
+ echo '<a href="'$url'">'$fname'</a>'
+ }
+ }
+ echo ' </pre>
+ </body>
+ </html>'
+}