Plan 9 from Bell Labs’s /usr/web/sources/contrib/anothy/bin/rc/contrindx

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/bin/rc

# Generate the contrib index page.  Look for README and INDEX files.
# Allows INDEX files to specify deep subdirs from a higher level.
# README files get the first 16 lines printed.
# Bug: deep references in INDEX are printed without the date.

rfork n
path = (/bin .) # speed hack

# Avoid conflicts with other connections in /srv.
prog=`{basename $0}
rm /srv/wiki.$prog >[2] /dev/null
srv 'net!plan9.bell-labs.com!wiki' wiki.$prog >[2] /dev/null || exit
mount -c /srv/wiki.$prog /mnt/wiki
rm /srv/sources.$prog >[2] /dev/null
srv 'net!sources.cs.bell-labs.com!9fs' sources.$prog >[2] /dev/null || exit
mount -n /srv/sources.$prog /n/sources

lastupdate=`{sed '/^D/q' < /mnt/wiki/contrib_index/current | sed -n 's,^D,,p'}
contrib=/n/sources/contrib/
cd $contrib || exit

#idirs = `{ ls */INDEX |sed 's%/INDEX%%' }
#idirs = (../extra anothy) # testing
idirs  = `{ls -d ../extra/ */ }

# Main loop
{
	echo Contrib Index
	echo D^$lastupdate
	echo Aanothy
	echo
	echo 'This is an automatically generated index of the packages part of the [Contrib] directory'
	echo 'in the [Sources repository]. Items marked as "From fgb''s contrib" can be downloaded'
	echo 'with the command'
	echo '! contrib/install user/package'
	echo 'contrib itself can be installed with'
	echo '! /n/sources/contrib/fgb/root/rc/bin/contrib/install fgb/contrib'
	echo
	echo  'Closer [Mirrors] may be available.'
	for(d in $idirs){
		echo
		echo $d | tr a-z A-Z
		if (test -f $d'/README') {
			#grep '^author:' README |	sed  -e 's/@/ at /' -e 's/^author: //'
			fmt -jl 100 $d'/README' | sed 's/^/!/' | sed 16q
		}

		echo
		{
			if (test -s $d'/INDEX') {
				cat $d'/INDEX' | grep '^[^ :]+:.+$' | sed 's%^%INDEX='$d'/%'
			}
			subdirs = `{ ls $d^/*/INDEX >[2] /dev/null | sed 's/INDEX$//'}
			for(i in $subdirs ) {
				cat $i/INDEX | grep '^[^ :]+:.+$' | sed 's%^%INDEX='$i'%'
			}
			ls -l $d $subdirs | grep -v '(INDEX|README)'

		} | grep -v '^$' | awk ' 
		/^INDEX=/ {
			$0 = substr($0,7)
			c = index($0,":")
			idx[substr($0,1,c-1)] = substr($0,c+1)
			pre[substr($0,1,c-1)] = "	* " substr($0,1,c-1) " -"
			next
		}
		{
			if (idx[$10] == "")
				idx[$10] = " "
			d = ""
			if (substr($0,1,1) == "d")
				d = "/"
			pre[$10] = "	* "$10 d " -"
			post[$10] = "  ("$7" "$8" "$9")"
		}
		END { for (f in idx)
			print pre[f] " " idx[f] " " post[f]
		}

		' | sort 
		if (! ~ $d ../extra) {
			echo
			controut=`{ contrib/list $d | sed 1q }
			if (! ~ $controut $d'/*: no such replica') {
				echo '	From fgb''s contrib:'
				contrib/list $d | sed 's@^'$d'/@	*@'
			}
		}
	}
} | {
	sed 's%^	\*[^/]*/%	*%'; 
	echo -n # Needed to 'commit' the write
} > /mnt/wiki/new


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.