shithub: shithub

Download patch

ref: 31bbd02bc477e884f96bef9abc6cd6381fd159c5
parent: 2f4a9aee3262d3c876851b803b1aeb2ad5376cc1
author: phil9 <telephil9@gmail.com>
date: Mon Feb 1 00:36:34 EST 2021

split shithub script into individual page scripts

	all scripts now reside under /rc/bin/shithub
	rule is now: one page one script

--- /dev/null
+++ b/files
@@ -1,0 +1,57 @@
+#!/bin/rc -e
+
+. /sys/lib/shithub/common.rc
+
+cd $1
+shift
+
+rfork ne
+nl='
+'
+
+
+gituser=$1
+repo=$2
+refname=$3
+
+repons $gituser $repo
+repodir=/mnt/$repo/.git
+if(! ref=`{resolveref $refname}){
+	echo '<b>invalid ref '$refname'</b>'
+	exit
+}
+
+if(test -f /mnt/git/$ref/hash)
+	hash=`{cat /mnt/git/$ref/hash}
+if not
+	hash=$ref
+
+user_prelude $gituser $repo $hash
+
+if(! test -d /mnt/git/$ref/tree){
+	echo '	<p>No code pushed</p>
+		</body>
+		</html>
+	'
+	exit
+}
+
+cd /mnt/git/$ref/tree
+
+echo '	<p>
+	<b>ref:</b> <a href="'/git/$gituser/$repo/$hash/files.html'">'$hash'</a><br/>
+	<b>tar:</b> <a href="'/git/$gituser/$repo/$hash/snap.tar.gz'">snap.tar.gz</a><br/></p>'
+
+echo '<p><div id="code">'
+for(f in `$nl{ls}){
+	url=`$nl{echo -n $f/f.html | urlencode}
+	fname=`$nl{echo -n $f | htcat}
+	echo -n '<a href="'$url'">'$fname
+	if (test -d $f) echo '/'
+	echo '</a><br/>'
+}		
+echo '	</div>
+	</p>
+	</body>
+	</html>'
+
--- /dev/null
+++ b/info
@@ -1,0 +1,61 @@
+#!/bin/rc -e
+
+. /sys/lib/shithub/common.rc
+
+cd $1
+shift
+
+rfork ne
+nl='
+'
+
+gituser=$1
+repo=$2
+refname=$3
+
+repons $gituser $repo
+repodir=/mnt/$repo/.git
+if(! ref=`{resolveref $refname}){
+	echo '<b>invalid ref '$refname'</b>'
+	exit
+}
+
+if(test -f /mnt/git/$ref/hash)
+	hash=`{cat /mnt/git/$ref/hash}
+if not
+	hash=$ref
+
+user_prelude $gituser $repo $hash		
+echo '	<h3>Clone</h3>
+	<div>
+	<b>clone:</b> git://shithub.us/'$gituser/$repo' gits://shithub.us/'$gituser/$repo'<br>
+	<b>push:</b> hjgit://shithub.us/'$gituser/$repo'<br>'
+if(test -f $repodir/contact)
+	echo '	<b>patches to: </b>'^`$nl{cat $repodir/contact}^'<br>'
+echo '	</div>'
+
+
+if(test -f /mnt/git/object/$hash/msg){
+	echo '	<h3>Last commit</h3>'
+	formatcommit $gituser $repo $hash
+}
+
+echo '	<h3>About</h3>
+	<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 if(test -f $repodir/description)
+	htcat $repodir/description
+if not
+	echo 'this repo has no description'
+echo '
+	</pre>
+	</body>
+	</html>
+'
--- /dev/null
+++ b/list
@@ -1,0 +1,35 @@
+#!/bin/rc -e
+
+. /sys/lib/shithub/common.rc
+
+cd $1
+shift
+
+rfork ne
+nl='
+'
+
+prelude Repolist
+echo '	<h1>Repos</h1>'
+udir=()
+for(repo in `$nl{ls */}){
+	ndir=`{basename -d $repo}
+	if(! ~ $udir $ndir)
+		echo '</dl>'
+	if(! ~ $udir $ndir){
+		echo '<h3>'$ndir'</h3>'
+		echo '<dl>'
+		udir=$ndir
+	}
+	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 if(test -f $repo/.git/description)
+			htcat $repo/.git/description
+		if not
+			echo 'probably some code'
+		echo '</dd>'
+	}
+}
--- /dev/null
+++ b/log
@@ -1,0 +1,42 @@
+#!/bin/rc -e
+
+. /sys/lib/shithub/common.rc
+
+cd $1
+shift
+
+rfork ne
+nl='
+'
+
+gituser=$1
+repo=$2
+refname=$3
+
+repons $gituser $repo
+repodir=/mnt/$repo/.git
+if(! ref=`{resolveref $refname}){
+	echo '<b>invalid ref '$refname'</b>'
+	exit
+}
+
+if(test -f /mnt/git/$ref/hash)
+	hash=`{cat /mnt/git/$ref/hash}
+if not
+	hash=$ref
+
+user_prelude $gituser $repo $hash
+
+if(! test -d /mnt/git/$ref/tree){
+	echo '	<p>No commits yet.</p>
+		</body>
+		</html>
+	'
+	exit
+}
+cd /mnt/git/$ref/tree
+echo '	<p>'
+shortlog $gituser $repo $ref 100
+echo '	</p>'
+echo '	</body>
+	</html>'
--- a/mkfile
+++ b/mkfile
@@ -1,7 +1,17 @@
 RCFILES=\
-	shithub\
 	newrepo
 
+PAGEFILES=\
+	list\
+	info\
+	files\
+	tar\
+	view\
+	viewraw\
+	log\
+	show\
+	patch
+
 LIBFILES=\
 	common.rc
 
@@ -10,6 +20,8 @@
 	toilet.jpg
 
 install:
+	mkdir -p /rc/bin/shithub
+	cp $PAGEFILES /rc/bin/shithub
 	mkdir -p /sys/lib/shithub
 	cp $LIBFILES /sys/lib/shithub
 	cp $RCFILES /rc/bin
--- /dev/null
+++ b/patch
@@ -1,0 +1,18 @@
+#!/bin/rc -e
+
+. /sys/lib/shithub/common.rc
+
+cd $1
+shift
+
+rfork ne
+nl='
+'
+
+gituser=$1
+repo=$2
+hash=$3
+
+repons $gituser $repo
+cd /mnt/$repo
+git/export $hash
--- a/shithub
+++ /dev/null
@@ -1,294 +1,0 @@
-#!/bin/rc -e
-
-. /sys/lib/shithub/common.rc
-
-cd $1
-shift
-
-rfork ne
-nl='
-'
-
-switch($1){
-case 'list'
-	rfork m
-	prelude Repolist
-	echo '	<h1>Repos</h1>'
-	udir=()
-	for(repo in `$nl{ls */}){
-		ndir=`{basename -d $repo}
-		if(! ~ $udir $ndir)
-			echo '</dl>'
-		if(! ~ $udir $ndir){
-			echo '<h3>'$ndir'</h3>'
-			echo '<dl>'
-			udir=$ndir
-		}
-		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 if(test -f $repo/.git/description)
-				htcat $repo/.git/description
-			if not
-				echo 'probably some code'
-			echo '</dd>'
-		}
-	}
-
-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
-	}
-
-	if(test -f /mnt/git/$ref/hash)
-		hash=`{cat /mnt/git/$ref/hash}
-	if not
-		hash=$ref
-
-	user_prelude $gituser $repo $hash		
-	echo '	<h3>Clone</h3>
-		<div>
-		<b>clone:</b> git://shithub.us/'$gituser/$repo' gits://shithub.us/'$gituser/$repo'<br>
-		<b>push:</b> hjgit://shithub.us/'$gituser/$repo'<br>'
-	if(test -f $repodir/contact)
-		echo '	<b>patches to: </b>'^`$nl{cat $repodir/contact}^'<br>'
-	echo '	</div>'
-	
-
-	if(test -f /mnt/git/object/$hash/msg){
-		echo '	<h3>Last commit</h3>'
-		formatcommit $gituser $repo $hash
-	}
-
-	echo '	<h3>About</h3>
-		<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 if(test -f $repodir/description)
-		htcat $repodir/description
-	if not
-		echo 'this repo has no description'
-	echo '
-		</pre>
-		</body>
-		</html>
-	'
-
-case 'files'
-	gituser=$2
-	repo=$3
-	refname=$4
-
-	repons $gituser $repo
-	repodir=/mnt/$repo/.git
-	if(! ref=`{resolveref $refname}){
-		echo '<b>invalid ref '$refname'</b>'
-		exit
-	}
-
-	if(test -f /mnt/git/$ref/hash)
-		hash=`{cat /mnt/git/$ref/hash}
-	if not
-		hash=$ref
-
-	user_prelude $gituser $repo $hash
-
-	if(! test -d /mnt/git/$ref/tree){
-		echo '	<p>No code pushed</p>
-			</body>
-			</html>
-		'
-		exit
-	}
-
-	cd /mnt/git/$ref/tree
-
-	echo '	<p>
-		<b>ref:</b> <a href="'/git/$gituser/$repo/$hash/files.html'">'$hash'</a><br/>
-		<b>tar:</b> <a href="'/git/$gituser/$repo/$hash/snap.tar.gz'">snap.tar.gz</a><br/></p>'
-
-	echo '<p><div id="code">'
-	for(f in `$nl{ls}){
-		url=`$nl{echo -n $f/f.html | urlencode}
-		fname=`$nl{echo -n $f | htcat}
-		echo -n '<a href="'$url'">'$fname
-		if (test -d $f) echo '/'
-		echo '</a><br/>'
-	}		
-	echo '	</div>
-		</p>
-		</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}
-
-	user_prelude $gituser $repo $hash
-
-	echo '	<p>
-		<b>ref:</b> <a href="'/git/$gituser/$repo/$hash/files.html'">'$hash'</a><br/>
-		</p>'
-	if(test -f $file){
-		echo '	<a href="'/git/$gituser/$repo/$hash/$file'/raw">View raw version</a>'
-		type=`{file -m $file}
-		switch($type){
-		case text/*
-			echo '	<pre id="code">'
-			htcat $file
-			echo '	</pre>'
-		case image/*
-			echo '	<br/><div><img src="'/git/$gituser/$repo/$hash/$file'/raw" /></div>'
-		case *
-			echo '	<p>Binary file not displayed</p>'
-		}
-	}
-	if not if(test -d $file){
-		cd $file
-		echo '	<div 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><br/>'
-		}
-		echo '	</div>'
-	}
-	echo '	</body>
-		</html>'
-
-case 'viewraw'
-	gituser=$2
-	repo=$3
-	refname=$4
-	file=$5
-
-	repons $gituser $repo
-	if(! ref=`{resolveref $refname}){
-		echo 'invalid ref '$refname''
-		exit
-	}
-	cd /mnt/git/$ref/tree
-	cat $file
-
-case 'log'
-	gituser=$2
-	repo=$3
-	refname=$4
-
-	repons $gituser $repo
-	repodir=/mnt/$repo/.git
-	if(! ref=`{resolveref $refname}){
-		echo '<b>invalid ref '$refname'</b>'
-		exit
-	}
-
-	if(test -f /mnt/git/$ref/hash)
-		hash=`{cat /mnt/git/$ref/hash}
-	if not
-		hash=$ref
-
-	user_prelude $gituser $repo $hash
-
-	if(! test -d /mnt/git/$ref/tree){
-		echo '	<p>No commits yet.</p>
-			</body>
-			</html>
-		'
-		exit
-	}
-	cd /mnt/git/$ref/tree
-	echo '	<p>'
-	shortlog $gituser $repo $ref 100
-	echo '	</p>'
-	echo '	</body>
-		</html>'
-
-case 'show'
-	gituser=$2
-	repo=$3
-	refname=$4
-
-	repons $gituser $repo
-	repodir=/mnt/$repo/.git
-	if(! ref=`{resolveref $refname}){
-		echo '<b>invalid ref '$refname'</b>'
-		exit
-	}
-
-	user_prelude $gituser $repo $refname
-
-	oldcommit=`{cat /mnt/git/$ref/parent}
-	author=`''{htcat /mnt/git/$ref/author}
-	date=`''{date `{mtime /mnt/git/$ref/msg | awk '{print $1}'}}
-	msg=`''{htcat /mnt/git/$ref/msg}
-	echo '	<p>
-		<a href="/git/'$gituser/$repo/$refname'/patch">Download patch</a><br/>
-		</p>
-		<p>
-		<b>ref:</b> <a href="/git/'$gituser/$repo/$refname'/files.html">'$refname'</a><br/>'
-	if(! ~ $#oldcommit 0) {
-		echo '<b>parent:</b> <a href="/git/'$gituser/$repo/$oldcommit'/files.html">'$oldcommit'</a><br/>'
-	}
-	echo '	<b>author:</b> '$author'<br/>
-		<b>date:</b> '$date'
-		<pre id="commit">'$msg'</pre><br/>
-		</p>'
-	cd /mnt/$repo
-	echo '	<div id="diff">'
-	git/export $refname | htcat | difftohtml
-	echo '	</div>
-		</body>
-		</html>'
-
-case 'patch'
-	gituser=$2
-	repo=$3
-	hash=$4
-
-	repons $gituser $repo
-	cd /mnt/$repo
-	git/export $hash
-
-}
-
--- /dev/null
+++ b/show
@@ -1,0 +1,46 @@
+#!/bin/rc -e
+
+. /sys/lib/shithub/common.rc
+
+cd $1
+shift
+
+rfork ne
+nl='
+'
+
+gituser=$1
+repo=$2
+refname=$3
+
+repons $gituser $repo
+repodir=/mnt/$repo/.git
+if(! ref=`{resolveref $refname}){
+	echo '<b>invalid ref '$refname'</b>'
+	exit
+}
+
+user_prelude $gituser $repo $refname
+
+oldcommit=`{cat /mnt/git/$ref/parent}
+author=`''{htcat /mnt/git/$ref/author}
+date=`''{date `{mtime /mnt/git/$ref/msg | awk '{print $1}'}}
+msg=`''{htcat /mnt/git/$ref/msg}
+echo '	<p>
+	<a href="/git/'$gituser/$repo/$refname'/patch">Download patch</a><br/>
+	</p>
+	<p>
+	<b>ref:</b> <a href="/git/'$gituser/$repo/$refname'/files.html">'$refname'</a><br/>'
+if(! ~ $#oldcommit 0) {
+	echo '<b>parent:</b> <a href="/git/'$gituser/$repo/$oldcommit'/files.html">'$oldcommit'</a><br/>'
+}
+echo '	<b>author:</b> '$author'<br/>
+	<b>date:</b> '$date'
+	<pre id="commit">'$msg'</pre><br/>
+	</p>'
+cd /mnt/$repo
+echo '	<div id="diff">'
+git/export $refname | htcat | difftohtml
+echo '	</div>
+	</body>
+	</html>'
--- /dev/null
+++ b/tar
@@ -1,0 +1,23 @@
+#!/bin/rc -e
+
+. /sys/lib/shithub/common.rc
+
+cd $1
+shift
+
+rfork ne
+nl='
+'
+
+gituser=$1
+repo=$2
+refname=$3
+
+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
--- /dev/null
+++ b/view
@@ -1,0 +1,57 @@
+#!/bin/rc -e
+
+. /sys/lib/shithub/common.rc
+
+cd $1
+shift
+
+rfork ne
+nl='
+'
+
+gituser=$1
+repo=$2
+refname=$3
+file=$4
+
+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}
+
+user_prelude $gituser $repo $hash
+
+echo '	<p>
+	<b>ref:</b> <a href="'/git/$gituser/$repo/$hash/files.html'">'$hash'</a><br/>
+	</p>'
+if(test -f $file){
+	echo '	<a href="'/git/$gituser/$repo/$hash/$file'/raw">View raw version</a>'
+	type=`{file -m $file}
+	switch($type){
+	case text/*
+		echo '	<pre id="code">'
+		htcat $file
+		echo '	</pre>'
+	case image/*
+		echo '	<br/><div><img src="'/git/$gituser/$repo/$hash/$file'/raw" /></div>'
+	case *
+		echo '	<p>Binary file not displayed</p>'
+	}
+}
+if not if(test -d $file){
+	cd $file
+	echo '	<div 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><br/>'
+	}
+	echo '	</div>'
+}
+echo '	</body>
+	</html>'
--- /dev/null
+++ b/viewraw
@@ -1,0 +1,23 @@
+#!/bin/rc -e
+
+. /sys/lib/shithub/common.rc
+
+cd $1
+shift
+
+rfork ne
+nl='
+'
+
+gituser=$1
+repo=$2
+refname=$3
+file=$4
+
+repons $gituser $repo
+if(! ref=`{resolveref $refname}){
+	echo 'invalid ref '$refname''
+	exit
+}
+cd /mnt/git/$ref/tree
+cat $file