Import sources from 2011-03-30 iso image - rc

Taru Karttunen 2011-03-30 17:14:36 +03:00
parent e463eb4036
commit 2959e1ede0
186 changed files with 5318 additions and 0 deletions

2
rc/bin/0a Executable file
View File

@ -0,0 +1,2 @@
#!/bin/rc
exec va -L $*

2
rc/bin/0c Executable file
View File

@ -0,0 +1,2 @@
#!/bin/rc
exec vc -l $*

2
rc/bin/0l Executable file
View File

@ -0,0 +1,2 @@
#!/bin/rc
exec vl -L $*

55
rc/bin/9fs Executable file
View File

@ -0,0 +1,55 @@
#!/bin/rc
# 9fs filesystem [mountpoint] - srv & mount filesystem, usually from plan 9
rfork e
switch($1){
case ''
echo usage: 9fs service '[mountpoint]' >[1=2]
exit usage
case kfs
if(! test -f /srv/kfs)
disk/kfs
mount -c /srv/kfs /n/kfs
case dump
mount /srv/boot /n/dump dump >[2]/dev/null ||
mount /srv/boot /n/dump main/archive ||
mount /srv/boot /n/dump dump # again to print error
case snap
mount /srv/boot /n/snap main/snapshot
case other
mount -C /srv/boot /n/other other
case juke # ye olde file server
srv -q il!jukefs && mount /srv/il!jukefs /n/juke
case sources
srv -nq tcp!sources.cs.bell-labs.com sources /n/sources
case sourcesdump
9fs sources
mount -n /srv/sources /n/sourcesdump main/archive
case sourcessnap
9fs sources
mount -n /srv/sources /n/sourcessnap main/snapshot
# arbitrary venti archives
case vac:*
vacfs <{echo $1}
case *.vac
if (test -e $1)
score=$1
if not if (! ~ $1 /* && test -e $home/lib/vac/$1)
score=$home/lib/vac/$1
if not if (! ~ $1 /* && test -e /lib/vac/$1)
score=/lib/vac/$1
if not {
echo $0: $1: no such score file >[1=2]
exit 'no score file'
}
vacfs -m /n/`{basename $1 .vac} `{cat $score}
case wiki
srv -m 'net!plan9.bell-labs.com!wiki' wiki /mnt/wiki
case *
switch($#*){
case 1
srv -m $1
case *
srv -m $1 $1 $2
}
}

40
rc/bin/B Executable file
View File

@ -0,0 +1,40 @@
#!/bin/rc
files=()
dest=()
if(~ $#* 0){
echo usage: B file ... >[1=2]
exit usage
}
for(i)
switch($i){
case /*
files = ( $files $i )
case *
files = ( $files `{cleanname `{pwd}^/$i} )
}
if(test -f /mnt/plumb/edit || test -f /mnt/term/mnt/plumb/edit){
plumb -s B -d edit $files
exit
}
# using sam srv file
if(test -f /mnt/term/srv/sam.$user) dest = /mnt/term/srv/sam.$user
if not if(test -f /srv/sam.$user) dest = /srv/sam.$user
if not {
echo B: can''''t find sam server file >[1=2]
exit open
}
switch($files){
case *:*
for(i in $files)
echo $i | sed 's/^/B /;s/:([0-9]+)$/\n\1/g' >> $dest
case *
echo B $files >> $dest
}

66
rc/bin/C Executable file
View File

@ -0,0 +1,66 @@
#!/bin/rc
# C system - connect to system's console
rfork en
oflag=()
opt=-r
while(~ $1 -*)
switch($1){
case -r
shift
opt=''
case -O -o
oflag=-O
shift
case *
opt=-r
shift
}
switch($1){
case ella
exec C office0
exit
case erika
exec C office1
exit
case *
# look for server in /lib/ndb
server=`{ndb/query sys $1 console}
switch($server){
case ''
echo C: unknown console server for $1
exit 1
}
}
# can't cpu to old servers any more
switch($server){
case dinar bones
ssh $server C $1
exit 0
}
if(! test -e /mnt/consoles/$1){
switch($sysname){
case $server
mount /srv/consoles /mnt/consoles
case *
import $oflag $server /mnt/consoles
}
}
if(! test -e /mnt/consoles/$1 && test -e /srv/consoles)
mount /srv/consoles /mnt/consoles
if(! test -e /mnt/consoles/$1){
echo console not found
exit 'console not found'
}
if (test -w /dev/label) {
olab=`{cat /dev/label}
label $1
}
con -l $opt /mnt/consoles/$1
if (test -w /dev/label)
label $olab

11
rc/bin/D003753 Executable file
View File

@ -0,0 +1,11 @@
#!/bin/rc
rfork e
flop=/dev/fd0disk
if(! test -r $flop)
flop='#f'/fd0disk
if(! test -f /srv/dos)
dossrv >/dev/null </dev/null >[2]/dev/null
unmount /n/a:>[2]/dev/null
mount -c /srv/dos /n/a: $flop
unmount /n/a >[2]/dev/null
mount -c /srv/dos /n/a $flop

9
rc/bin/D003754 Executable file
View File

@ -0,0 +1,9 @@
#!/bin/rc
rfork e
if(test -f /dev/sd*/dos*){
dosmnt 1 /n/c:
dosmnt 1 /n/c
exit
}

68
rc/bin/F000050 Executable file
View File

@ -0,0 +1,68 @@
#!/bin/rc
# usbfat: [disk [mtpt]] - mount a USB disk's MS FAT file system,
# which might be the only thing on the disk, or might be
# a partition within the disk.
rfork e
disk = ()
mtpt = /n/usb
test -e /dev/usb || bind -a '#u' /dev || {
echo no '#u/usb' >[1=2]
exit nousb
}
test -e /dev/usbdctl || mount -a /srv/usb /dev || {
echo cannot mount /srv/usb >[1=2]
exit nousbd
}
disks=()
mtpt=()
switch ($#*) {
case 0
;
case 1
disks = $1
case 2
disks = $1
mtpt = $2
case *
echo usage: $0 ' [disk [mtpt]]' >[1=2]
exit usage
}
if(~ `{ls /n/usb >[2]/dev/null | wc -l} 0)
mount /srv/usb /n/usb >[2]/dev/null
if (~ $#disks 0){
disks = /dev/sdU*/data
if(! test -e $disks(1)){
echo no usb disks >[1=2]
exit nodisk
}
disks = (/dev/sdU*/9fat /dev/sdXX/9fat /dev/sdU*/data /dev/sdXX/data)
}
for(d in $disks){
if(! ~ $done yes) {
if(~ $d sdU*.[0-9]* sdXX*)
d=/dev/$d/data
if(test -e $d){
name=`{echo $d | sed 's/.*(sd(XX|U[0-9]+\.[0-9]+)).*/\1/'}
if(~ $#mtpt 0)
mnt=/n/$name
if not
mnt=$mtpt
# don't mount it if it seems to be already mounted.
# if(! test -e $mnt/* && grep -s geometry /dev/$name/ctl)
{
blk = `{disk/fdisk -p $d |
awk '/^part dos / {print $3}'}
if (! ~ $#blk 0 && ~ $blk [0-9]*)
d=$d:$blk
if (mount -c <{dossrv -sf $d >[2]/dev/null} $mnt) {
echo $mnt
done = yes
}
}
}
}
}
exit ''

18
rc/bin/F003758 Executable file
View File

@ -0,0 +1,18 @@
#!/bin/rc
rfork e
part=`{ls /dev/fs/9fat /dev/sd*/9fat >[2]/dev/null}
if(~ $#part 0) {
echo 'no 9fat partition found' >[1=2]
exit no.9fat
}
part=$part(1)
if(! test -f /srv/dos)
dossrv >/dev/null </dev/null >[2]/dev/null
unmount /n/9fat >/dev/null >[2]/dev/null
mount -c /srv/dos /n/9fat $part
unmount /n/9 >/dev/null >[2]/dev/null
mount -c /srv/dos /n/9 $part

7
rc/bin/F003763 Executable file
View File

@ -0,0 +1,7 @@
#!/bin/rc
if(! test -f /srv/dos)
dossrv >/dev/null </dev/null >[2]/dev/null
unmount /n/b:>[2]/dev/null
mount -c /srv/dos /n/b: /dev/fd1disk
unmount /n/b >[2]/dev/null
mount -c /srv/dos /n/b /dev/fd1disk

4
rc/bin/Kill Executable file
View File

@ -0,0 +1,4 @@
#!/bin/rc
for(i){
ps | sed -n '/ '^$i^'$/s%^[^ ]* *([^ ]*).*%chmod 666 /proc/\1/ctl;echo kill > /proc/\1/ctl%p'
}

8
rc/bin/addaoe Executable file
View File

@ -0,0 +1,8 @@
#!/bin/rc
# addaoe let unit - add an AoE logical unit as sd$let
if (! ~ $#* 2 || ! ~ $1 ? || ! ~ $2 *.*) {
echo usage: $0 letter aoe-lun >[1=2]
exit usage
}
if (test -e /dev/aoe/$2 && ! test -e /dev/sd^$1^0)
echo config switch on spec $1 type aoe//dev/aoe/$2 >/dev/sdctl

5
rc/bin/addpsfonts Executable file
View File

@ -0,0 +1,5 @@
#!/bin/rc
# addpsfonts [file]... - add postscript fonts named in %%DocumentFonts comments
# of postscript input
echo %!PS-Adobe-2.0
exec aux/download -f -mfontmap -plw+ -r/sys/lib/postscript/font/lw+ $*

36
rc/bin/ap Executable file
View File

@ -0,0 +1,36 @@
#!/bin/rc
#
# get AP news headline list or the given story
#
wire='http://www.newsday.com/news/nationworld/wire'
if ( ~ $#* 0 )
hget $wire | #tee /tmp/ap.$pid |
sed -n '/<h1>AP Top News/,/AP News Wire/p' |
htmlfmt -a -w 100 |
sed -n '
/^• / {
N
s/^• / /g
s/\n/ /g
s/\[\/news\/nationworld\/wire\//|/
s/sns-ap-//
s/\.story.*$//
p
}' |
awk -F '|' '
{
s = "";
for (i = 1; i < NF; i++)
s = s " " $i;
printf("ap %-40s # %s\n", $NF, s);
}'
if not
hget $wire/sns-ap-^$1^.story |
htmlfmt |
sed '
1,/^AP Top News$/d
/^\* __$/,$d
/^Subscribe to Newsday home delivery/,$d
'

15
rc/bin/ape/ar89 Executable file
View File

@ -0,0 +1,15 @@
#!/bin/rc
flagfmt='c,d,p,r,t,u,v,x'
args='archive [files ...]'
if(! ifs=() eval `{aux/getflags $*} || ~ $#* 0) {
aux/usage
exit usage
}
key=''
for(i in c d p r t x u v)
if(f=flag$i ~ $#$f 1)
key=$key$i
exec /$cputype/bin/ar $key $*

2
rc/bin/ape/c89 Executable file
View File

@ -0,0 +1,2 @@
#!/bin/rc
exec /$cputype/bin/ape/cc $*

18
rc/bin/ape/cat Executable file
View File

@ -0,0 +1,18 @@
#!/bin/rc
rfork e
files=()
while(! ~ $#* 0){
switch($1){
case -
files=($files /fd/0)
case -*
;
case *
files=($files $1)
}
shift
}
exec /$cputype/bin/cat $files

4
rc/bin/ape/chown Executable file
View File

@ -0,0 +1,4 @@
#!/bin/rc
echo 'Permission denied'
exit 1

9
rc/bin/ape/dircp Executable file
View File

@ -0,0 +1,9 @@
#!/bin/rc
# dircp src dest - copy a tree with ape's tar
switch($#*){
case 2
@{cd $1 && tar cf /fd/1 .} | @{cd $2 && tar xf /fd/0}
case *
echo usage: dircp from to >[1=2]
exit usage
}

2
rc/bin/ape/egrep Executable file
View File

@ -0,0 +1,2 @@
#!/bin/rc
exec /rc/bin/ape/grep $*

2
rc/bin/ape/false Executable file
View File

@ -0,0 +1,2 @@
#!/bin/rc
exit 1

2
rc/bin/ape/fgrep Executable file
View File

@ -0,0 +1,2 @@
#!/bin/rc
exec /rc/bin/ape/grep $*

22
rc/bin/ape/grep Executable file
View File

@ -0,0 +1,22 @@
#!/bin/rc
rfork e
opts=()
files=()
argv0=$0
while(! ~ $#* 0){
switch($1){
case -[cefinsv]
opts=($opts $1)
case -q
opts=($opts -s)
case -*
echo $argv0 $1 not supported >[2=1]
exit 'not supported'
case *
files=($files $1)
}
shift
}
exec /$cputype/bin/grep $opts $files

40
rc/bin/ape/install Executable file
View File

@ -0,0 +1,40 @@
#!/bin/rc
# Usage: install [options] srcfile dstfile
# Usage: install srcfile dstfile owner group mode
fn usage {
echo 'usage: install [-c|-m mode] srcfile dstfile' >[1=2]
exit 1
}
mode=775
while(! ~ $#* 0){
switch($1){
case -c
;
case -m
mode=$2
shift
case -*
usage
case *
switch($#*) {
case 2
;
case 5
mode=$5 # backward compatibility
case *
usage
}
srcfile=$1
dstfile=$2
if (! test -f $dstfile || ! cmp -s $srcfile $dstfile) {
cp $srcfile $dstfile
chmod $mode $dstfile
chmod g+w $dstfile
}
exit 0
}
shift
}
usage

6
rc/bin/ape/ld Executable file
View File

@ -0,0 +1,6 @@
#!/bin/rc
# ld for ape, to keep configure happy
O=`{sed -n 's/^O=//p' /$cputype/mkfile}
$O^l $*

23
rc/bin/ape/ln Executable file
View File

@ -0,0 +1,23 @@
#!/bin/rc
argv0=$0
force=n
while(! ~ $#* 0 && ~ $1 -*){
switch($1){
case -f
force=y
case -s
;
case *
echo 'usage: ln [-s] [-f] source destination' >[2=1]
exit 'usage'
}
shift
}
if(~ $force n && test -e $2){
echo ln: $2 destination exists >[2=1]
exit 'usage'
}
exec cp -gux $1 $2

59
rc/bin/ape/ls Executable file
View File

@ -0,0 +1,59 @@
#!/bin/rc
# flags common to GNU and BSD ls
# -A all except . and ..
# -C force mc
# -F usual
# -H follow symlinks
# -L follow symlinks
# -R recursive list
# -U unsorted (gnu)
#
# -a include .files
# -c show ctime
# -d dirs
# -f no sorting
# -l long
# -p put slash after dir (-F)
# -r reverse
# -s sizes
# -t time sort
# -u utime
# -1 single-column
flagfmt='A,C,F,H,L,R,U,a,c,d,f,l,p,r,s,t,u,1'
args='[file ...]'
if(! ifs=() eval `{aux/getflags $*}){
aux/usage
exit usage
}
fn fixlong {
echo total 1000
/$cputype/bin/sed 's/^(.).(.........) . [0-9]+ /\1\2 1 /'
}
post=cat
all=()
# ignore -A
if(~ $flagC 1) post=mc
if(~ $flagF 1) all=($all -F)
# ignore -H, -L
# save -R for later
if(~ $flagU 1) all=($all -n)
# ignore -a, -c
if(~ $flagd 1) all=($all -d)
if(~ $flagf 1) all=($all -n)
if(~ $flagl 1) { all=($all -l); post=fixlong }
if(~ $flagp 1) all=($all -F)
if(~ $flagr 1) all=($all -r)
if(~ $flags 1) all=($all -s)
if(~ $flagt 1) all=($all -t)
if(~ $flagu 1) all=($all -u)
# ignore -1
/$cputype/bin/ls $all $* | $post

4
rc/bin/ape/printf Executable file
View File

@ -0,0 +1,4 @@
#!/bin/rc
# Here only for autoconf and friends.
echo -n $1

10
rc/bin/ape/psh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/rc
# set up a shell running in an approximate POSIX 1003.2 environment
rfork en
fn sigterm{}
HOME=$home
bind -b /rc/bin/ape /bin
bind -b /$cputype/bin/ape /bin
if(test -d /$cputype/bin/pub)
bind -a /$cputype/bin/pub /bin
/bin/sh $*

3
rc/bin/ape/ranlib Executable file
View File

@ -0,0 +1,3 @@
#!/bin/rc
exit 0

2
rc/bin/ape/rmdir Executable file
View File

@ -0,0 +1,2 @@
#!/bin/rc
rm $*

2
rc/bin/ape/true Executable file
View File

@ -0,0 +1,2 @@
#!/bin/rc
exit 0

2
rc/bin/ape/umask Executable file
View File

@ -0,0 +1,2 @@
#!/bin/rc
echo no umask in Plan 9

16
rc/bin/ape/yacc Executable file
View File

@ -0,0 +1,16 @@
#!/bin/rc
flagfmt='d,l,t,v,b stem'
args='grammar'
if(! ifs=() eval `{aux/getflags $*} || ! ~ $#* 1){
aux/usage
exit usage
}
y=-S
if (~ $#flagb 1) y=($y -s $flagb)
if (~ $#flagd 1) y=($y -d)
if (~ $#flagt 1) y=($y -D2)
if (~ $#flagv 1) y=($y -v)
exec /$cputype/bin/yacc $y $*

8
rc/bin/broke Executable file
View File

@ -0,0 +1,8 @@
#!/bin/rc
U=`{cat /dev/user}
if(~ $#* 1){
U=$1
}
ps | sed -n '/^'$U' .* Broken/s%[^ ]* *%~>/proc/%
s% *.* (.*)%/ctl # \1%
s%~%echo kill%p'

8
rc/bin/bundle Executable file
View File

@ -0,0 +1,8 @@
#!/bin/rc
echo '# To unbundle, run this file'
for(i in $*){
echo 'echo '$i
echo 'sed ''s/.//'' >'$i' <<''//GO.SYSIN DD '$i''''
sed 's/^/-/' $i
echo '//GO.SYSIN DD '$i
}

77
rc/bin/cpurc Executable file
View File

@ -0,0 +1,77 @@
#!/bin/rc
# cpu server start up
date > /env/boottime
# mount points
mntgen -s slashn && chmod 666 /srv/slashn
# name translation, cs sets /dev/sysname
ndb/cs
sysname=`{cat /dev/sysname}
# parallelism for mk
NPROC = `{wc -l </dev/sysstat}
# site-specific startup
if(test -e /rc/bin/cpurc.local)
. /rc/bin/cpurc.local
if (~ $#sysname 0 || ~ $sysname '') {
sysname = helix # default
echo -n $sysname >/dev/sysname
}
prompt=($sysname^'# ' ' ')
# cpu-specific startup
if(test -e /cfg/$sysname/cpurc)
. /cfg/$sysname/cpurc
# start up internet if we don't already have an address
if(! grep u /net/ipselftab | grep -sv 127.0.0.1)
ip/ipconfig
if(! grep -s 127.0.0.1 /net/ipselftab)
ip/ipconfig loopback /dev/null 127.1
# if we're not a server, start a dns resolver
if(! test -e /srv/dns)
ndb/dns -r
# If you are on an auth server, start these before listening:
#
# auth/keyfs -wp -m /mnt/keys /adm/keys >/dev/null >[2=1]
# auth/cron >>/sys/log/cron >[2=1] &
#
# also rename some files:
#
# if(! test -e /rc/bin/service.auth/tcp567){
# mv /rc/bin/service.auth/authsrv.il566 /rc/bin/service.auth/il566
# mv /rc/bin/service.auth/authsrv.tcp567 /rc/bin/service.auth/tcp567
# mv /rc/bin/service/il566 /rc/bin/service/_il566
# mv /rc/bin/service/tcp567 /rc/bin/service/_tcp567
# }
# start listeners if it hasn't already been done (dicey check)
if(! netstat -n | grep -s 'tcp.*Listen.* (7|9|21|22|23|25|110|113|565|993|17007|17009|17010) .*')
aux/listen -q tcp
# we don't use IL, maybe you do
if(! netstat -n | grep -v 17008 | grep -s il.*Listen)
aux/listen -q il
if(! ps|grep -s timesync) {
aux/timesync -n pool.ntp.org
if (test -e '#r/rtc') @ {
sleep 10 # let timesync correct the time
awk '{print $1}' /dev/time >'#r/rtc' # fix hw clock
} &
}
# cpu-specific late startup
if(test -e /cfg/$sysname/cpustart)
. /cfg/$sysname/cpustart
# mode of /proc/*/ctl is inherited across rfork, and sets modes on
# other /proc files, such as note, so let listen be killed.
dontkill '^(ipconfig|factotum|mntgen|venti|fossil|cs|dns|reboot)$'
# echo `{date} $sysname >>/sys/log/boot
exit ''

11
rc/bin/cpurc.local Executable file
View File

@ -0,0 +1,11 @@
#!/bin/rc
# local cpu startup
# used only by upas, as default return domain appended to all unqualified
# return addresses, even local ones
site=EXAMPLE
# replace FILESERVER with the name of your file server
# here we start with kfs, your local disk file system
fileserver=kfs
# replace FACEDOM with the local domain to be used in the faces database
facedom=FACEDOM

52
rc/bin/delkey Executable file
View File

@ -0,0 +1,52 @@
#!/bin/rc
rfork e
ctl = /mnt/factotum/ctl
if(test -r /mnt/term/mnt/factotum/ctl)
ctl = /mnt/term/mnt/factotum/ctl
fn forceit {
switch($force){
case no
echo -n $* '? [y/n]' > /dev/cons
ok = `{read}
switch($ok){
case y* Y*
echo yes
case q* Q*
exit ''
case *
echo no
}
case *
echo yes
}
}
fn deleteit {
key = `{echo $* | sed 's/ ![0-9a-zA-Z_]+\??/ /g' | sed 's/ +$//'}
if(~ `{forceit del$key} yes)
if(! echo del$key > $ctl)
exit bad
}
force = no
if(~ $1 '-f'){
force = yes
shift
}
ifs='
'
if(~ $#* 0){
for(i in `{cat $ctl})
deleteit $i
exit ''
}
for(i in `{grep $"* $ctl})
deleteit $i
exit ''

14
rc/bin/diffy Executable file
View File

@ -0,0 +1,14 @@
#!/bin/rc
# diffy [diff-opts] file... - diff file against yesterday's version(s)
rfork e
diffopts=()
while(! ~ $#* 0 && ~ $1 -* && ! ~ $1 --){
diffopts=($diffopts $1)
shift
}
if(~ $1 --)
shift
if(! ~ $#* 1)
diffopts=($diffopts -m)
for(f)
diff $diffopts `{yesterday $f} $f

9
rc/bin/dircp Executable file
View File

@ -0,0 +1,9 @@
#!/bin/rc
# dircp src dest - copy a tree with tar
switch($#*){
case 2
@ {builtin cd $1 && tar cif /fd/1 .} | @ {builtin cd $2 && tar xTf /fd/0}
case *
echo usage: dircp from to >[1=2]
exit usage
}

34
rc/bin/diskparts Executable file
View File

@ -0,0 +1,34 @@
#!/bin/rc
# set up any disk partitions
rfork e
if (! test -e /dev/sdctl)
bind -b '#S' /dev
# set up any /dev/sd partitions.
# note that really big disks (e.g., aoe devices) may have no mbr
# partition table because the mbr partition table can't cope with large
# block numbers, so we may have to examine the data file with prep if
# there's no plan9 file. beware that `disk/prep -p data' on a disk with
# no plan 9 partition table will delete all extant partitions.
for(disk in /dev/sd*) {
if(test -f $disk/data && test -f $disk/ctl)
{ disk/fdisk -p $disk/data |
grep -v '^delpart ' >$disk/ctl } >[2]/dev/null
if(test -f $disk/plan9)
parts=($disk/plan9*)
if not
parts=($disk/data)
for(part in $parts)
if(test -f $part)
{ disk/prep -p $part |
grep -v '^delpart ' >$disk/ctl } >[2]/dev/null
}
sysname=`{cat /dev/sysname}
# set up any fs(3) partitions
if (! test -e /dev/fs/ctl && test -e '#k/fs')
bind -b '#k' /dev
if (~ $#sysname 1 && ! ~ $sysname '' &&
test -r /cfg/$sysname/fsconfig && test -w /dev/fs/ctl)
read -m /cfg/$sysname/fsconfig >/dev/fs/ctl

7
rc/bin/dmaon Executable file
View File

@ -0,0 +1,7 @@
#!/bin/rc
# dmaon - turn on ide dma, if possible
rfork e
for (ctl in /dev/sd[C-H]?/ctl)
if (test -e $ctl && grep -s '^config .* dma ' $ctl &&
! grep -s '^config (848A|.* dma 00000000 )' $ctl)
echo 'dma on' >$ctl

21
rc/bin/doc2ps Executable file
View File

@ -0,0 +1,21 @@
#!/bin/rc
# doc2ps [file.doc] - convert ms word document to postscript
rfork e
fn usage {
echo usage: doc2ps '[file.doc]' >[1=2]
exit usage
}
switch ($#*) {
case 0
file=/tmp/antiword.doc.$pid
fn sigexit { rm $file; exit $s }
cat >$file
case 1
if(~ $1 -*)
usage
file=$1
case *
usage
}
aux/antiword -i0 -p letter $file
s=$status

31
rc/bin/doc2txt Executable file
View File

@ -0,0 +1,31 @@
#!/bin/rc
rfork en
if(! ~ $#* 0 1) {
echo 'Usage: doc2txt [file.doc]' >[1=2]
exit usage
}
switch($#*){
case 0
cat >/tmp/doc2txt.$pid
file=/tmp/doc2txt.$pid
case 1
file=$1
}
aux/olefs $file || {
echo 'doc2txt: couldn''t mount word document' >[1=2]
rm -f /tmp/doc2txt.$pid
exit word
}
if(! test -f /mnt/doc/WordDocument) {
echo 'doc2txt: is an msoffice doc but not a word document' >[1=2]
rm -f /tmp/doc2txt.$pid
exit worddoc
}
aux/mswordstrings /mnt/doc/WordDocument | tcs -f microsoft -t utf |fmt | uniq
unmount /mnt/doc
rm -f /tmp/doc2txt.$pid

76
rc/bin/doctype Executable file
View File

@ -0,0 +1,76 @@
#!/bin/rc
# doctype: synthesize proper command line for troff
troff=troff
eqn=eqn
prefer=prefer
opt=''
dev=''
while(~ $1 -*){
switch($1){
case -n;
troff=nroff
eqn=neqn
prefer='prefer -n'
case -T
dev=$1
case -*
opt=$opt' $1'
}
shift
}
ifs='
'{
files=`{echo $*}
}
grep -h '\$LIST|\|reference|Jp|^\.(EQ|TS|\[|PS|IS|GS|G1|GD|PP|BM|LP|BP|PI|cstart|begin|TH...)|^\.P$' $* |
sort -u |
awk '
BEGIN { files = "'$files'" }
/\$LIST/ { e++ }
/^\.PP/ { ms++ }
/^\.LP/ { ms++ }
/^\.EQ/ { eqn++ }
/^\.TS/ { tbl++ }
/^\.PS/ { pic++ }
/^\.IS/ { ideal++ }
/^\.GS/ { tped++ }
/^\.G1/ { grap++; pic++ }
/^\.GD/ { dag++; pic++ }
/^\.\[/ { refer++ }
/\|reference/ { prefer++ }
/^\.cstart/ { chem++; pic++ }
/^\.begin +dformat/ { dformat++; pic++ }
/^\.TH.../ { man++ }
/^\.BM/ { lbits++ }
/^\.P$/ { mm++ }
/^\.BP/ { pictures++ }
/^\.PI/ { pictures++ }
/^\.ft *Jp|\\f\(Jp/ { nihongo++ }
END {
x = ""
if (refer) {
if (e) x = "refer/refer -e " files " | "
else x = "refer/refer " files "| "
files = ""
}
else if (prefer) { x = "cat " files "| '$prefer'| "; files = "" }
if (tped) { x = x "tped " files " | "; files = "" }
if (dag) { x = x "dag " files " | "; files = "" }
if (ideal) { x = x "ideal -q " files " | "; files = "" }
if (grap) { x = x "grap " files " | "; files = "" }
if (chem) { x = x "chem " files " | "; files = "" }
if (dformat) { x = x "dformat " files " | "; files = "" }
if (pic) { x = x "pic " files " | "; files = "" }
if (tbl) { x = x "tbl " files " | "; files = "" }
if (eqn) { x = x "'$eqn' '$dev' " files " | "; files = "" }
x = x "'$troff' "
if (man) x = x "-man"
else if (ms) x = x "-ms"
else if (mm) x = x "-mm"
if (lbits) x = x " -mbits"
if (pictures) x = x " -mpictures"
if (nihongo) x = x " -mnihongo"
x = x " '$opt' '$dev' " files
print x
}'

10
rc/bin/dontkill Executable file
View File

@ -0,0 +1,10 @@
#!/bin/rc
# dontkill regexp - mark invoker's processes with names matching regexp
# as not killable when the kernel runs out of memory
if (! ~ $#* 1) {
echo $0 regexp >[1=2]
exit usage
}
# see /sys/src/9/port/proc.c:/^killbig
pids=`{psu | awk '$NF ~ /'$1'/ {print $2}'}
~ $#pids 0 || chmod -w /proc/^$pids^/ctl

18
rc/bin/dosmnt Executable file
View File

@ -0,0 +1,18 @@
#!/bin/rc
rfork e
if(! ~ $#* 2){
echo 'usage: dosmnt N mntpt' >[1=2]
exit usage
}
x=(`{ls /dev/sd??/dos* >[2]/dev/null |uniq})
if(test $#x -lt $1){
echo 'not that many dos disks' >[1=2]
exit usage
}
if(! test -f /srv/dos)
dossrv >/dev/null </dev/null >[2]/dev/null
mount -c /srv/dos $2 $x($1)

10
rc/bin/dpost Executable file
View File

@ -0,0 +1,10 @@
#!/bin/rc
# dpost [-f] [file...] - convert troff output to postscript,
# optionally include font def'ns
# exec lp -dstdout $*
if (! ~ $#* 0 && ~ $1 -f) {
shift
aux/tr2post $* | addpsfonts
}
if not
exec aux/tr2post $*

9
rc/bin/eject Executable file
View File

@ -0,0 +1,9 @@
#!/bin/rc
switch($1){
case 0
echo eject > /dev/fd0ctl
case 1
echo eject > /dev/fd1ctl
case *
echo eject > /dev/fd0ctl
}

126
rc/bin/fax Executable file
View File

@ -0,0 +1,126 @@
#!/bin/rc
# fax [-v] telephone-number recipient [file ...] - send files via fax
rfork e
view=no
stdin=no
fn usage {
echo 'usage: fax [-v] telephone-number recipient [file ...]' >[1=2]
exit usage
}
switch($1){
case -v
view=yes
shift
}
switch ($#*) {
case 0 1
usage
case 2
stdin=yes
}
telno=`{echo $1|sed 's/[ \-]//g'}
shift
if (! ~ $telno [0-9]* +[0-9]*)
usage
# our old phone system needed *9 to get outside; the new one just needs 9
switch($telno){
case ???????
telno='9,'^$telno
case ??????????
telno='9,1'^$telno
case 1??????????
telno='9,'^$telno
case 011*
telno='9,'^$telno
case +*
telno=`{echo $telno | sed 's/\+/9,011/'}
}
recip=$1
shift
script=/tmp/fax.$pid
header=/tmp/faxh.$pid
user=`{cat /dev/user}
tmp=/tmp/fax.g3.$pid
tmpin=/tmp/fax.in.$pid
tmpps=/tmp/fax.ps.$pid
tel=`{grep '\) '$user /lib/tel}
myname=`{echo $tel | sed 's/ \(.*//'}
if (~ $#myname 0)
myname=''
ext=`{echo $tel | sed 's/.*\) [^ ]* [^ ]* ([^ ]*).*/\1/'}
fn sigexit {
rm -f $tmp.* $script $header $header.* $tmpin $tmpps
}
fn sigint {
sigexit
exit interrupt
}
# gather input into a file
switch($stdin){
case yes
cat >$tmpin
infiles=$tmpin
case *
infiles=($*)
}
# convert to g3
g3files=()
a=1
for(i in $infiles){
switch(`{file $i}){
case *:*g3* *:*fax*
g3files=($g3files $i)
case *:*postscript
gs -dSAFER '-sDEVICE=dfaxlow' '-sOUTPUTFILE='$tmp'.'$#a'.%03d' \
-dNOPAUSE -dQUIET $i quit.ps
g3files=($g3files $tmp.$#a.*)
case *
lp -dstdout $i >$tmpps
gs -dSAFER '-sDEVICE=dfaxlow' '-sOUTPUTFILE='$tmp'.'$#a'.%03d' \
-dNOPAUSE -dQUIET $tmpps quit.ps
g3files=($g3files $tmp.$#a.*)
}
a=($a 1) # count by increasing list length
}
pages=`{echo $g3files|wc -w}
# use delimiters that are unlikely to be supplied in arguments
{
echo -n s∮FAXddd∮
echo -n `{date} # treat `{} output list specially
echo ∮
echo s∮FAXFFF∮$"myname^∮
echo s∮FAXEEE∮$"user^∮
echo s∮FAXVVV∮$"ext^∮
echo s∮FAXTTT∮$"recip^∮
echo s∮FAXfff∮$"telno^∮
echo s∮FAXPPP∮$"pages^∮
} >>$script
sed -f $script /sys/lib/fax/h.ps >$header
gs -dSAFER '-sDEVICE=dfaxlow' '-sOUTPUTFILE='$header'.%03d' \
-dNOPAUSE -dQUIET $header quit.ps
files=()
for(i in $header.* $g3files){
files=($files -f $i)
}
switch($view){
case yes
page $header.* $g3files
case *
upas/qer $files /mail/faxoutqueue fax $user $telno </dev/null
rx fax /sys/lib/fax/faxgoose </dev/null
}

62
rc/bin/fedex Executable file
View File

@ -0,0 +1,62 @@
#!/bin/rc
if(! ~ $#* 1) {
echo usage: fedex 123456789012 >[1=2]
exit usage
}
rfork e
fn bgrep{
pattern=`{echo $1 | sed 's;/;\\&;'}
shift
@{ echo 'X {
$
a
.
}
X ,x/(.+\n)+\n/ g/'$pattern'/p' |
sam -d $* >[2]/dev/null
}
}
fn awk2 {
awk 'NR%2==1 { a=$0; }
NR%2==0 { b=$0; printf("%-30s %s\n", a, b); }
' $*
}
fn awk3 {
awk '{line[NR] = $0}
END{
i = 4;
while(i < NR){
what=line[i++];
when=line[i];
comment="";
if(!(when ~ /..\/..\/.... ..:../)){
# out of sync
printf("%s\n", what);
continue;
}
i++;
if(!(line[i+1] ~ /..\/..\/.... ..:../) &&
(i+2 > NR || line[i+2] ~ /..\/..\/.... ..:../)){
what = what ", " line[i++];
}
printf("%s %s\n", when, what);
}
}' $*
}
# hget 'http://www.fedex.com/cgi-bin/track_it?airbill_list='$1'&kurrent_airbill='$1'&language=english&cntry_code=us&state=0' |
hget 'http://www.fedex.com/Tracking?action=track&language=english&cntry_code=us&initial=x&mps=y&tracknumbers='$1 |
htmlfmt >/tmp/fedex.$pid
sed -n '/Tracking number/,/^$/p' /tmp/fedex.$pid | awk2
echo
sed -n '/Reference number/,/^$/p' /tmp/fedex.$pid | awk2
echo
sed -n '/Date.time/,/^$/p' /tmp/fedex.$pid | sed 1,4d | fmt -l 4000 | sed 's/ [A-Z][A-Z] /&\n/g'
rm /tmp/fedex.$pid

108
rc/bin/fshalt Executable file
View File

@ -0,0 +1,108 @@
#!/bin/rc
# fshalt [-r] - sync (flush) and, if possible, halt all file servers
# and optionally reboot
rfork e
reboot=no
switch ($#*) {
case 0
case 1
reboot=yes
case *
echo usage: $0 '[-r]' >[1=2]
exit usage
}
path=(/bin)
builtin cd /
setrtc
# start venti flushing
venti/sync -h localhost >[2]/dev/null &
venti/sync >[2]/dev/null &
unmount /mnt/consoles >[2]/dev/null
kill consolefs | rc # don't compete with /mnt/consoles
sleep 1
f=`{ls /srv/fscons*>[2]/dev/null}
k=`{ls /srv/kfs*cmd >[2]/dev/null|sort -r}
echo -n syncing...
for(i in $f) @ {
echo -n $i...
{
echo
dial/drain &
sleep 2
echo fsys all sync
if(! dial/expect -t 120 ': ')
echo -n 'not synced...' > /dev/cons
} < $i >> $i
}
# flush the last bit of possible fossil traffic
echo -n venti...
venti/sync -h localhost >[2]/dev/null &
venti/sync >[2]/dev/null &
sleep 5
for (i in $k){
echo -n $i...
switch($i){
case /srv/kfs.cmd
disk/kfscmd sync
case *
disk/kfscmd -n `{echo $i | sed -n 's%/srv/kfs.(.*).cmd%\1%p'} sync
}
sleep 2
}
# halting (binaries we run can't be on the fs we're halting)
ramfs
builtin cd /tmp
cp /bin/dial/expect /tmp
cp /bin/echo /tmp
cp /bin/disk/kfscmd /tmp
cp /bin/rc /tmp
cp /bin/sed /tmp
cp /bin/ns /tmp
cp /bin/iostats /tmp
mkdir /tmp/lib
cp /rc/lib/rcmain /tmp/lib
bind /tmp /rc
bind /tmp /bin
# put this in a shell function so this rc script doesn't get read
# when it's no longer accessible
fn x {
echo
echo -n halting...
for(i in $f) @ {
echo -n $i...
{
echo fsys all halt
if(! expect -t 60 ': ')
echo -n 'not halted...' > /dev/cons
} < $i >> $i
}
for (i in $k){
echo -n $i...
switch($i){
case /srv/kfs.cmd
kfscmd halt
case *
kfscmd -n `{echo $i | sed -n 's%/srv/kfs.(.*).cmd%\1%p'} halt
}
}
echo
echo done halting
if (~ $reboot yes) {
echo rebooting...
echo reboot >'#c/reboot'
}
}
x

15
rc/bin/go.fishing Executable file
View File

@ -0,0 +1,15 @@
#!/bin/rc
# go.fishing - set up vacation responder
rfork e
cd /mail/box/$user
if (test -e gone.fishing) {
echo $0: /mail/box/$user/gone.fishing already exists >[1=2]
exit 'already fishing'
}
>gone.addrs
chmod -a gone.addrs
>gone.addrs
chmod +arw gone.addrs
>>gone.fishing

17
rc/bin/homespool Executable file
View File

@ -0,0 +1,17 @@
#!/bin/rc
echo creating spool directory
mkdir $home/spool
chmod 777 $home/spool
echo creating ctrl directory
mkdir $home/spool/ctrl
chmod 775 $home/spool/ctrl
echo creating seqno file
touch $home/spool/ctrl/seqno
echo creating options file
chmod 222 $home/spool/ctrl/seqno
cat >$home/spool/ctrl/options <<EOF
facedown
nobanner
$user
EOF

19
rc/bin/ipconf/inside Executable file
View File

@ -0,0 +1,19 @@
#!/bin/rc
ip/ipconfig
# supply unknowns with inside addresses
if( ! grep -s 'auth=' /net/ndb){
echo ' auth=135.104.9.7'>>/net/ndb
echo ' authdom=cs.bell-labs.com'>>/net/ndb
}
if( ! grep -s 'ntp=' /net/ndb)
echo ' ntp=135.104.9.2'>>/net/ndb
if( ! grep -s 'dns=' /net/ndb){
echo ' dns=135.104.8.38'>>/net/ndb
echo ' dns=135.104.70.11'>>/net/ndb
}
# start dns if it isn't already going
if(! test -e /srv/dns )
ndb/dns -r

92
rc/bin/ipconf/lra Executable file
View File

@ -0,0 +1,92 @@
#!/bin/rc
# on hook and initialize
fn initfn {
dial/drain
dial/at -q -t 5 zh0
}
# dial telephone number
fn dialfn {
dial/drain
dial/at -q -t 60 dt^$1
}
# process options
for(i in $*){
switch($i){
case '-P'
primary=-P
}
}
# the following can be inherited
switch($dev){
case ''
dev=/dev/eia1
}
switch($telno){
case ''
telno=18009878722
}
switch($baud){
case ''
baud=115200
}
{
# set up uart
if( test -e $dev^ctl ){
echo -n b^$baud # baud rate
echo -n m1 # cts/rts flow control
echo -n q64000 # big buffer
echo -n n1 # nonblocking writes
echo -n r1 # rts on
echo -n d1 # dtr on
echo -n c1 # handup wen we lose dcd
} > $dev^ctl
# get the modem's attention
while( ! initfn )
sleep 1
# dial
while( ! dialfn $telno )
sleep 30
if( ! dial/expect -it 60 'username:' ){
echo lra: can''t connect >[1=2]
exit connect
}
dial/pass
if( ! dial/expect -it 60 'password:' ){
echo lra: can''t connect >[1=2]
exit connect
}
dial/pass
if( ! dial/expect -t 60 'telnet:' ){
echo lra: can''t connect >[1=2]
exit connect
}
echo ppp
echo connected to lra >[1=2]
# start ppp
ip/ppp $primary -f
} < $dev > $dev
# supply unknowns with inside addresses
if( ! grep -s 'auth=' /net/ndb){
echo ' auth=135.104.9.7'>>/net/ndb
echo ' authdom=cs.bell-labs.com'>>/net/ndb
}
if( ! grep -s 'ntp=' /net/ndb)
echo ' ntp=135.104.9.2'>>/net/ndb
if( ! grep -s 'dns=' /net/ndb){
echo ' dns=135.104.8.38'>>/net/ndb
echo ' dns=135.104.70.11'>>/net/ndb
}
# start dns if it isn't already going
if(! test -e /srv/dns )
ndb/dns -r

24
rc/bin/ipconf/outside Executable file
View File

@ -0,0 +1,24 @@
#!/bin/rc
ip/ipconfig -dDG
# supply unknowns with outside addresses
if( ! grep -s 'auth=' /net/ndb){
echo ' auth=204.178.31.3'>>/net/ndb
echo ' authdom=cs.bell-labs.com'>>/net/ndb
}
if( ! grep -s 'ntp=' /net/ndb)
echo ' ntp=204.178.31.2'>>/net/ndb
if( ! grep -s 'dns=' /net/ndb){
echo ' dns=204.178.31.3'>>/net/ndb
echo ' dns=204.178.31.4'>>/net/ndb
}
# set ndbfile for termrc touse
NDBFILE=/lib/ndb/external
# start dns if it isn't already going
if(! test -e /srv/dns )
ndb/dns -r
# just in case we can't find achille
cpu=tcp!204.178.31.2

76
rc/bin/ipconf/theworld Executable file
View File

@ -0,0 +1,76 @@
#!/bin/rc
fn initfn {
dial/flush
echo +++
echo -n atzh0
dial/expect -q -t 5 OK
}
fn dialfn {
dial/flush
echo -n atdt^$telno^
dial/expect -q -t 60 CONNECT
}
# process options
for(i in $*){
switch($i){
case '-P'
primary=-P
}
}
switch($dev){
case ''
dev=/dev/eia1
}
switch($telno){
case ''
telno=18009878722
}
switch($baud){
case ''
baud=115200
}
{
# set up uart
if( test -e $dev^ctl ){
echo -n b^$baud
echo -n m1 # cts/rts flow control
echo -n q64000 # big buffer
echo -n n1 # nonblocking writes
echo -n r1 # rts on
echo -n d1 # dtr on
echo -n c1 # handup wen we lose dcd
} > $dev^ctl
# get the modem's attention
while( ! initfn )
sleep 1
# dial
while( ! dialfn )
sleep 30
echo connected to the world >[1=2]
# start ppp
ip/ppp $primary -f
} < $dev > $dev
# supply unknowns with outside addresses
if( ! grep -s 'auth=' /net/ndb){
echo ' auth=204.178.31.3'>>/net/ndb
echo ' authdom=cs.bell-labs.com'>>/net/ndb
}
if( ! grep -s 'ntp=' /net/ndb)
echo ' ntp=204.178.31.2'>>/net/ndb
if( ! grep -s 'dns=' /net/ndb){
echo ' dns=204.178.31.3'>>/net/ndb
echo ' dns=204.178.31.4'>>/net/ndb
}
# start dns if it isn't already going
if(! test -e /srv/dns )
ndb/dns -r

163
rc/bin/ipso Executable file
View File

@ -0,0 +1,163 @@
#!/bin/rc
# ipso - edit secstore files, reload factotum keys
if(! ~ $service terminal &&
! ~ $user `{ ls -ld /mnt/factotum/ctl | awk '{print $4}' }){
echo >[1=2] ipso should be run only on the terminal
exit terminal
}
rfork e
path=(/bin)
home=(/tmp)
editor = (acme -c1)
name = secstore
get = secstoreget
put = secstoreput
edit = no
load = no
flush = no
fn secstoreget{
auth/secstore -i -g $1 <_password
}
fn secstoreput{
auth/secstore -i -p $1 <_password
}
fn aesget{
if(! ~ $1 /*){
echo >[1=2] ipso: aescbc requires fully qualified pathname
exit usage
}
auth/aescbc -i -d < $1 > `{basename $1} <[3] _password
}
fn aesput{
auth/aescbc -i -e > $1 < `{basename $1} <[3] _password
}
fn editedfiles{
if(~ $get aesget){
for(i in $files)
if(ls -tr | sed '1,/^_timestamp$/d' | grep -s '^'^`{basename $i}^'$')
echo $i
}
if not
ls -tr | sed '1,/^_timestamp$/d'
}
edexp=`{grep '^editor=' /mnt/plumb/rules >[2]/dev/null}
if(~ $#edexp 1)
eval $edexp
while(~ $1 -*){
switch($1){
case -s
editor = sam
case -a
name = aescbc
get = aesget
put = aesput
case -f
flush = yes
case -e
edit = yes
case -l
load = yes
case *
echo >[2=1] 'usage: ipso [-a -f -e -l] [-s] [file ...]'
exit usage
}
shift
}
if(~ $flush no && ~ $edit no && ~ $load no){
load = yes
edit = yes
flush = yes
}
if(~ $flush yes && ~ $edit no && ~ $load no){
echo flushing old keys
echo delkey > /mnt/factotum/ctl
exit 0
}
if(~ $get aesget && ~ $#* 0){
echo >[2=1] ipso: must specify a fully qualified file name for aescbc '(-a)'
exit usage
}
rfork ne
ramfs -p >[2] /dev/null # silence 'i/o on hungup channel' message at exit
unmount /mnt/plumb
bind -c /tmp /srv
builtin cd /tmp
if ( ~ $edit yes ) echo '
Warning: The editor will display the secret contents of
your '$name' files in the clear.
'
# get password and remember it
{
echo rawon
echo -n $name password: >/dev/cons
read > _password
echo > /dev/cons
}</dev/cons > /dev/consctl
# get list of files
if(~ $#* 0){
if(! auth/secstore -G . -i < _password > _listing){
echo 'secstore read failed - bad password?'
sleep 2
exit password
}
files=`{sed 's/[ ]+.*//' _listing}
}
if not
files = $*
# copy the files to local ramfs
for(i in $files){
if(! $get $i){
echo $name ' read failed - bad password?'
sleep 2
exit password
}
}
sleep 2; date > _timestamp # so we can find which files have been edited.
# edit the files
if(~ $edit yes) $editor `{for(i in $files) basename $i}
if(~ $flush yes ){
echo flushing old keys
echo delkey > /mnt/factotum/ctl
}
if(~ $load yes){
echo loading factotum keys
if (~ factotum $files) read -m < factotum > /mnt/factotum/ctl
}
# copy the files back
for(i in `{editedfiles}){
echo -n copy ''''`{basename $i}^'''' back?' [y/n/x]'
switch(`{read}){
case [yY]*
if(! $put $i){
echo $name ' read failed - bad password?'
sleep 2
exit password
}
echo ''''$i'''' copied to $name
if(~ $i factotum)
read -m < $i > /mnt/factotum/ctl
case [xXqQ]*
exit
case [nN]* *
echo ''''$i'''' skipped
}
}
exit ''

94
rc/bin/ipv6on Executable file
View File

@ -0,0 +1,94 @@
#!/bin/rc
# ipv6on [netdir ndbfile [gwv4]] - configure an interface for ipv6,
# once ipv4 is configured.
if (! ~ $#* 0 2 3) {
echo usage: $0 '[netdir ndbfile [gw-v4-name]]' >[1=2]
exit usage
}
rfork e
if (~ $#* 0) {
netdir=/net
ndbf=/lib/ndb/local
gw=`{ndb/ipquery sys $sysname ipgw | sed 's/ipgw=//'}
}
if not {
netdir=$1
ndbf=$2
if (~ $#* 2)
# gw=()
gw=`{ndb/ipquery sys $sysname ipgw | sed 's/ipgw=//'}
if not
gw=$3
}
if (~ $netdir /net) {
xsfx=()
xdir=()
}
if not {
xsfx=(-x `{echo $netdir | sed 's;^/net;;'})
xdir=(-x $netdir)
}
fn nonnil { # variable
if (~ $#$1 0) {
echo no ip for $1
exit no-ip
}
if (! ~ $#$1 1) {
echo multiple ips for $1
exit multiple-ips
}
}
#
# configure v6 for link-local addresses (fe80::) & multicast (ff02::)
#
if (! ip/ipconfig -6 $xdir ether $netdir/ether?)
exit 'ipconfig -6 failed'
ip/ipconfig $xdir ether $netdir/ether? ra6 recvra 1
mev6=`{ndb/query -f $ndbf sys $sysname ipv6}
if (~ $#sysname 0 || ~ $sysname '')
mev6=`{ndb/query -f $ndbf sys $sysname ip | grep :}
# mev4=`{ndb/query -f $ndbf sys $sysname ip | grep -v :}
# for testing
mylnk=`{ip/linklocal `{cat $netdir/ether?/addr}}
nonnil mylnk
if (~ $#gw 1) {
if (~ $gw [0-9]*.[0-9]*.[0-9]*.[0-9]*)
gwv4 = $gw
if (~ $#gwv4 0 || ~ $gwv4 '') # assume namev6 and name
gwv4=`{ndb/query -f $ndbf sys $gw ip}
gwv6=`{ndb/query -f $ndbf sys $gw ipv6}
if (! ~ $#gwv4 0) {
# echo ping gw $gwv4...
# load arp cache with gw mac
ip/ping -qn 3 $netdir/icmp!$gwv4 >/dev/null >[2=1] &
sleep 1 # wait for ping
gweth=`{grep '* '^$gwv4^' ' $netdir/arp | awk '{print $4}' }
nonnil gweth
gwlnk=`{ip/linklocal $gweth}
nonnil gwlnk
}
}
nonnil mev6
#
# configure my global v6 addresses
#
ip/ipconfig $xdir ether $netdir/ether? add $mev6 /64
ip/ipconfig $xdir loopback /dev/null add $mev6 /128
if (~ $#gw 1) {
if (~ $#gwv6 0 || ~ $gwv6 '')
gwv6=`{ip/linklocal $gweth}
nonnil gwv6
#
# add default v6 route to v6 addr of v4 gw
#
echo add :: /0 $gwv6 >$netdir/iproute # need not be link-local
}
exit ''

87
rc/bin/iwhois Executable file
View File

@ -0,0 +1,87 @@
#!/bin/rc
# iwhois [-n] domain - print registration data for domain
rfork e
if (~ $#* 1 && ~ $1 -n)
noboiler=yes
person=`{echo $1|sed s/@.*//}
fn boilerplate { sed -n '/^[ ]*[A-Za-z][A-Za-z]*:$/,$p' $* }
switch($1){
case *@*
machine=`{echo $1|sed s/.*@//}
case *.ca
machine=whois.cira.ca
fn boilerplate { grep -v ':[ ]*$' $* }
case *.us
machine=whois.nic.us
fn boilerplate { sed '/^>* Whois database was last updated on/,$d' $* }
case *.co.uk *.net.uk *.org.uk
machine=whois.nic.uk
fn boilerplate { sed '/^ +WHOIS database last updated at/,$d' $* }
case *.ac.uk
machine=whois.ja.net
case *.au
machine=whois.aunic.net
fn boilerplate { grep -v ':[ ]*$' $* }
case *.be
machine=whois.dns.be
person='-T dn '^$person
fn boilerplate { cat $* }
case *.cn
machine=whois.cnnic.net.cn
fn boilerplate { cat $* }
case *.de
machine=whois.denic.de
person='-T dn '^$person
fn boilerplate { cat $* }
case *.dk
machine=whois.dk-hostmaster.dk
fn boilerplate { grep -v '^#' $* }
case *.es
echo no known whois server for .es
exit
case *.fr
machine=whois.nic.fr
fn boilerplate { grep -v '^%%' $* }
case *.in
machine=whois.inregistry.net
fn boilerplate { cat $* }
case *.jp
machine=whois.jprs.jp
person=$person^'/e'
fn boilerplate { cat $* }
case *.se
machine=whois.nic-se.se
fn boilerplate { grep -v '^#' $* | uniq }
case [0-9]*.[0-9]*.[0-9]*.[0-9]*
machine=whois.arin.net
fn boilerplate { cat $* }
case *
machine=whois.internic.net # alternate: whois.networksolutions.com
fn boilerplate { cat $* }
}
if (~ $noboiler yes)
fn boilerplate { cat $* }
file=/tmp/iwhois$pid
fn sigexit {
rm -f $file
}
echo $person | telnet -nr tcp!$machine!whois > $file
x=`{ sed -n -e 's/.*Whois Server: (.*)/\1/p' \
-e 's;.*ReferralServer: whois://(.*)(:43)?;\1;p' $file }
switch($#x){
case 0
; # e.g., for .ca
case 1
# chase the referral chain
echo $person | telnet -nr tcp!$x!whois > $file
case *
# echo $0: buggery: `{echo $x | tr ' ' '\12' | sort -u} >[1=2]
echo $person | telnet -nr tcp!^$x(1)^!whois > $file
}
if (test ! -s $file) {
echo $0: broken whois server tcp!$x!whois returned no data >[1=2]
exit broken
}
boilerplate $file
rm $file

60
rc/bin/juke Executable file
View File

@ -0,0 +1,60 @@
#!/bin/rc
wide=`{echo $vgasize | sed 's/(.*)x.*x.*/\1 > 240/' | hoc}
debug=0
tflag=''
wflag=''
host=''
kb=4096
flags=()
sname=$user
if (! ~ $wide 1) {
flags=($flags -t)
kb=1024
}
while(! ~ $#* 0) {
switch ($1) {
case -d
debug=$2
shift
case -t
tflag='-t'
case -h
host=$2
shift
case -w
wflags='-w'
case -s
sname=$2
shift
case -*
echo Usage: classical [-d level] [-t] [-h srvhost]
exit usage
}
shift
}
if (! test -e /mnt/playlist){
if (! ~ $debug '0') echo mounting playlistfs
if (! test -e /srv/playlist.$sname && ! ~ $host ''){
import -a $host /srv /srv
}
if (! mount -b /srv/playlist.$sname /mnt >/dev/null >[2]/dev/null){
rm -f /srv/playlist.$sname
if (! ~ $debug '0') echo starting playlistfs
games/playlistfs -s $sname -d $debug
}
}
if (! test -w /mnt/juke) {
if (! test -e /srv/jukefs.$sname && ! ~ $host ''){
import -a $host /srv /srv
}
if (! mount -b /srv/jukefs.$sname /mnt >/dev/null >[2]/dev/null){
if (! ~ $debug '0') echo games/jukefs
games/jukefs -s $sname
}
}
if (~ $wflags '-w') {
exec games/jukebox -w -d $debug $tflag &
}
exec games/jukebox -d $debug $tflag

4
rc/bin/kill Executable file
View File

@ -0,0 +1,4 @@
#!/bin/rc
for(i){
ps | sed -n '/ '^$i^'$/s%^[^ ]* *([^ ]*).*%chmod 666 /proc/\1/ctl;echo kill > /proc/\1/ctl%p'
}

31
rc/bin/kmem Executable file
View File

@ -0,0 +1,31 @@
#!/bin/rc
# kmem [kernel] - print summary of allocate blocks in running kernel
rfork e
if(! ~ $#* 0 1){
echo 'usage: kmem [kernel]' >[1=2]
exit usage
}
if(~ $#* 1)
binary=$1
echo 'kinit(); blocksummary()' | acid -k -lkernel -lpool -lleak $pid $binary | awk '
$1 == "block" {
addr=$6
size=$3
alloc=$4
total[alloc] += size
count[alloc]++
}
$1 == "summary" {
alloc=$2
cnt=$3
size=$4
total[alloc] += size
count[alloc] += cnt
}
END{
for(i in count)
printf("%6d %11d %s\n", count[i], total[i], i);
}
' | sort -nr

6
rc/bin/label Executable file
View File

@ -0,0 +1,6 @@
#!/bin/rc
# label word ... - write words into our label, if any
if (test -w /dev/label)
echo -n $* > /dev/label
if not if (test -w /mnt/term/dev/label)
echo -n $* > /mnt/term/dev/label

2
rc/bin/lc Executable file
View File

@ -0,0 +1,2 @@
#!/bin/rc
ls -p $* | mc

95
rc/bin/leak Executable file
View File

@ -0,0 +1,95 @@
#!/bin/rc
rfork e
flagfmt='a,b,c,d,s,f binary,r res,x width'
args='name | pid list'
if(! ifs=() eval `{aux/getflags $*} || ~ $#* 0){
aux/usage
exit usage
}
conflicting=($flagb $flagc $flags)
if(~ $#conflicting 2 || ~ $#conflicting 3){
echo 'can only use one of -b, -c or -s' >[1=2]
exit usage
}
leakflags=()
if(~ $#flags 1)
leakflags=($leakflags -s)
if(~ $#flaga 1)
leakflags=($leakflags -a)
if(~ $#flagc 1)
leakflags=($leakflags -c)
if(~ $#flagd 1)
leakflags=($leakflags -d)
if(~ $#flagf 1)
leakflags=($leakflags -f $flagf)
acidleakflags=()
if(~ $#flagb 1)
acidleakflags=($acidleakflags -b)
if(~ $#flagr 1)
acidleakflags=($acidleakflags -r $flagr)
if(~ $#flagx 1)
acidleakflags=($acidleakflags -x $flagx)
if(! test -d /proc/$1) {
# x=`{psu | awk '$NF=="'$1'" {print $2}'}
x=`{psu | grep ' '$1'$' | sed 's/^[^ ]+ +([0-9]+).*/\1/'}
if(~ $#x 0) {
echo 'no processes named '$1 >[1=2]
exit usage
}
echo leak $leakflags $acidleakflags $x
exit
}
pidlist=`{echo $"* | tr ' ' ,}
echo 'leakdump({'$pidlist'})' | acid -lpool -lleak $1 $flagf |
{
if(~ $#flaga 1 && ~ $#flagd 1)
grep 'block|free'
if not
if(~ $#flaga 1)
grep block
if not
if(~ $#flagd 1)
grep free
if not
aux/acidleak $acidleakflags $flagf
} |
{
if(~ $#flags 1)
awk '{print $4}' |
sort | uniq -c | sort -nr |
sed 's! *(.*) (0x.*)!src(\2); // \1!'
if not
if(~ $#flagc 1)
awk 'BEGIN {
for(i=0; i<16; i++)
_unhex[sprintf("%x", i)] = _unhex[sprintf("%X", i)] = i
}
function unhex(s, i, v) {
sub("^0[xX]0*","",s)
for (i=1; i<=length(s); i++)
v = v*16 + _unhex[substr(s,i,1)]
return v
}
{ sum[$4] += unhex($3);
count[$4]++;
alloc[$4] = $6;
}
END {
for (v in sum) {
printf("src(%s);\t// %d\t%d\t%d\t%s\n", v, sum[v], count[v], sum[v] / count[v], alloc[v])
total += sum[v]
}
printf("// %d\n", total);
}
' | sort -nr +2
if not
cat
}

36
rc/bin/lookman Executable file
View File

@ -0,0 +1,36 @@
#!/bin/rc
# Usage: lookman key ...
# prints out the names of all manual pages containing all the given keywords
rfork e
index=/sys/lib/man/lookman/index
t1=/tmp/look1.$pid
t2=/tmp/look2.$pid
fn sigexit {
rm -f $t1 $t2
exit
}
fn sigint sighup sigterm {
rm -f $t1 $t2
exit note
}
*=`{echo $*|tr A-Z a-z|tr -dc 'a-z0-9_. \012'} # fold case, delete funny chars
if(~ $#* 0){
echo Usage: lookman key ... >/fd/2
exit usage
}
look $1 $index | sed 's/.* //' | sort -u >$t1
shift
for(i in $*){
look $i $index | sed 's/.* //' | sort -u |
awk 'BEGIN {
while (getline < "'$t1'" > 0)
table[$0] = 1
}
{ if (table[$0]) print }
' > $t2
mv $t2 $t1
}
sort $t1 | sed 's;/sys/man/;;
s;(.*)/(.*);man \1 \2 # \2(\1);'
exit ''

212
rc/bin/lp Executable file
View File

@ -0,0 +1,212 @@
#!/bin/rc
# lp - enqueues the file to be printed and starts the daemon, when necessary.
# Make changes to /sys/src/cmd/lp/lp.rc;
# changes made directly to /rc/bin/lp will be lost.
rfork en # so that environment and name space are not polluted
#
# put 'fn sigexit { rm /tmp/lpcrap; exit interrupted }' into processes that create /tmp/lpcrap.
ifs='
' # set ifs in case it is munged in user's environment
LPLIB=/sys/lib/lp # lp scripts directories and configuration file are here
LPBIN=/$cputype/bin/aux # lp specific binaries are here
LPSPOOL=$LPLIB/queue # lp queues
LPLOGDIR=$LPLIB/log # lp logs
$LPLIB/bin/lpscratch
x=$status
if(! ~ $x '') exit $x
# build /bin from the ground up
bind /$cputype/bin /bin # general compiled binaries
bind -a /rc/bin /bin # general rc scripts
# This needs to be fixed for the real thing
bind -a $LPLIB/bin /bin # lp specific rc scripts
bind -a $LPBIN /bin # lp specific compiled binaries
path=(/bin)
if (! test -w /tmp) bind -bc $LPLIB/tmp /tmp
USAGE='usage: lp [-d printer] [-p process] [options] [files]
lp [-d printer] -q
lp [-d printer] -k jobnos
options include:
-D turn on debugging output
-H no header
-L landscape mode
-M<mach> print on machine <mach>
-Q put task only into the queue
-R restart printer daemon
-c<n> make <n> copies
-f<font.size> specify font and size
-i<src> take media from <src> input bin
-l<n> print <n> lines per logical page
-m<n> magnify <n> times
-n<n> print <n> logical pages per physical page
-o<i-j,k> print only pages i-j and k
-r reverse pages
-u<userid> print as <userid>
-x<n> x page offset in inches
-y<n> y page offset in inches
'
# umask 000 # this doesn't work in plan 9
if (~ $#sysname 0)
THIS_HOST=plan9
if not {
THIS_HOST=`{ndb/query sys $sysname dom}
if(~ $#THIS_HOST 0)
THIS_HOST=$sysname
}
LPMACHID=$THIS_HOST
THIS_USERID=$user
LPUSERID=$THIS_USERID
LPLOC=''
# Set default printer to be output device
if (~ $#LPDEST 0 && test -f $LPLIB/defdevice) LPDEST=`{cat $LPLIB/defdevice}
# option parameters
COPIES=1
FONT=''
IBIN=''
KILLFLAG=0
LAND=''
LINES=''
LPQ=0
MAG=''
NOHEAD=''
NPAG=''
OLIST=''
POINT=''
RESET=''
REVERSE=''
QONLY=''
TRAY=''
XOFF=''
YOFF=''
# Process options
flagfmt='D,H,L,Q,R,r,q,M mach,c copies,d printer,f font.size,i src,k jobnos,l lines,m magnify,n lpages,o pages,p proc,u userid,x offset,y offset'
argv0=lp
if(! ifs=() eval `{aux/getflags $*}) {
echo $USAGE
exit usage
}
if(~ $flagd '?'){
awk 'BEGIN {print "device location host class"}
/^[^#]/ { printf "%-12s %-9s %-22s %s\n", $1, $2, $3, $6 }' $LPLIB/devices
exit
}
if(~ $flagp '?'){
ls $LPLIB/process
exit
}
if (! ~ $#flagD 0) { DEBUG=1; flag x + }; if not { DEBUG=''; flag x - }
if (! ~ $#flagH 0) NOHEAD=1
if (! ~ $#flagL 0) LAND=1
if (! ~ $#flagM 0 && ~ $LPUSERID daemon) LPMACHID=$flagM
if (! ~ $#flagQ 0) QONLY=1
if (! ~ $#flagR 0) RESET=1
if (! ~ $#flagc 0) COPIES=$flagc
if(! ~ $#flagd 0) LPDEST=$flagd
if (! ~ $#flagf 0) eval `{echo $flagf | sed -e 's/([^.]*)\.([0-9.]*)/FONT=\1;POINT=\2;/'}
if (! ~ $#flagi 0) IBIN=$flagi
if (! ~ $#flagk 0) KILLFLAG=1
if (! ~ $#flagl 0) LINES=$flagl
if (! ~ $#flagm 0) MAG=$flagm
if (! ~ $#flagn 0) NPAG=$flagn
if (! ~ $#flago 0) OLIST=-o^$flago
if (! ~ $#flagp 0) LPPROC=$flagp
if (! ~ $#flagq 0) LPQ=1
if (! ~ $#flagr 0) REVERSE=1
if (! ~ $#flagu 0) LPUSERID=$flagu
if (! ~ $#flagx 0) XOFF=$flagx
if (! ~ $#flagy 0) YOFF=$flagy
if (~ $#LPDEST 0) {
echo 'Set environment variable LPDEST or use the
''-d printer'' option to set the destination.' >[1=2]
exit 'LPDEST not set'
}
if (~ $LPDEST */*) { # handles MHCC destinations like mh/lino
LPLOC=`{echo $LPDEST|sed 's/^(.*)\/(.*)/\1/'}
LPDEST=`{echo $LPDEST|sed 's/^(.*)\/(.*)/\2/'}
}
# look up device, get info
LPDLINE=`{grep '^'$LPDEST'[ ]' $LPLIB/devices}
if (! ~ $status '') {
echo 'device '$LPDEST' is not in '$LPLIB'/devices' >[1=2]
exit 'LPDEST is bad'
}
LOC=$LPDLINE(2)
DEST_HOST=$LPDLINE(3)
OUTDEV=$LPDLINE(4)
SPEED=$LPDLINE(5)
LPCLASS=$LPDLINE(6)
if (~ $#LPPROC 0) LPPROC=$LPDLINE(7)
SPOOLER=$LPDLINE(8)
STAT=$LPDLINE(9)
KILL=$LPDLINE(10)
DAEMON=$LPDLINE(11)
SCHED=$LPDLINE(12)
if (~ $LPCLASS *nohead*)
NOHEAD=1
if (~ $LPCLASS *duplex*)
DUPLEX=1
if (~ $#SCHED 0) SCHED=FIFO # everyone uses FIFO
if (~ $KILLFLAG 1)
switch ($KILL) {
case -; echo kill option not available on $LPDEST >[1=2]
exit 'kill n/a'
case *; bind -b $LPLIB/kill /bin
exec $KILL $*
exit 'kill command '"$KILL"' not found'
}
if (~ $LPQ 1)
switch ($STAT) {
case -; echo queue status option not available on $LPDEST >[1=2]
exit 'stat option not available'
case *; bind -b $LPLIB/stat /bin
exec $STAT $* < /dev/null
exit 'stat command '"$STAT"' not found'
}
DATE=`{date}
LPLOG=$LPLOGDIR/$LPDEST
if (! test -e $LPLOG) {
>$LPLOG
chmod +rwa $LPLOG >[2]/dev/null
}
if (~ $RESET '') {
switch ($SPOOLER) {
case -; echo spooler does not exist for $LPDEST >[1=2]
exit 'no spooler'
case *; bind -b $LPLIB/spooler /bin
if (~ $#* 0) $SPOOLER
if not $SPOOLER $*
}
}
if not {
echo restarting daemon for printer $LPDEST >[1=2]
UNLOCK $LPSPOOL/$LPDEST
sleep 5
}
# run daemon
if (~ $QONLY '') {
if (! ~ $DAEMON -) {
bind -b $LPLIB/daemon /bin
$DAEMON $* >>$LPLOG >[2=1] &
}
}
exit ''

12
rc/bin/mail Executable file
View File

@ -0,0 +1,12 @@
#!/bin/rc
switch($#*){
case 0
exec upas/nedmail
}
switch($1){
case -f* -r* -c* -m*
exec upas/nedmail $*
case *
exec upas/marshal $*
}

149
rc/bin/man Executable file
View File

@ -0,0 +1,149 @@
#!/bin/rc
# man - print manual pages
rfork e
. /sys/man/fonts
cmd=n
sec=()
S=/sys/man
d=0
fn roff {
preproc=()
postproc=cat
x=`{doctype $2}
if (~ $1 t) {
if(~ $x *grap*)
preproc=($preproc grap)
if(~ $x *pic*)
preproc=($preproc pic)
Nflag=-Tutf
}
if not {
Nflag='-N'
Lflag='-rL1000i'
# setting L changes page length to infinity (sed script removes empty lines)
if (grep -s '^\.(2C|sp *[0-9]*\.)' $2)
postproc=col
}
if(~ $x *eqn*)
preproc=($preproc eqn)
if(~ $x *tbl*)
preproc=($preproc tbl)
{echo -n $FONTS; cat $2 </dev/null} |
switch($#preproc) {
case 0
troff $Nflag $Lflag -$MAN
case 1
$preproc | troff $Nflag $Lflag -$MAN
case 2
$preproc(1) | $preproc(2) | troff $Nflag $Lflag -$MAN
case 3
$preproc(1) | $preproc(2) | $preproc(3) |
troff $Nflag $Lflag -$MAN
case *
$preproc(1) | $preproc(2) | $preproc(3) |
$preproc(4) | troff $Nflag $Lflag -$MAN
} | $postproc
}
fn page {
if(test -d /mnt/wsys/acme)
/bin/page -w
if not
/bin/page
}
search=yes
while(~ $d 0) {
if(~ $#* 0) {
echo 'Usage: man [-bntpPSw] [0-9] [0-9] ... name1 name2 ...' >[1=2]
exit
}
if(test -d $S/$1){
sec=($sec $1)
shift
}
if not
switch($1) {
case -b ; cmd=b ; shift
case -n ; cmd=n ; shift
case -P ; cmd=P ; shift
case -p ; cmd=p ; shift
case -S ; search=no ; shift
case -t ; cmd=t ; shift
case -w ; cmd=w ; shift
case * ; d=1
}
}
if(~ $#sec 0) {
sec=`{ls -pd $S/[0-9]* }
}
ix=$S/$sec/INDEX
if(~ $#* 1) pat='^'^$1^' '
if not pat='^('^`{echo $* | sed 's/ /|/g'}^') '
fils=()
if(~ $search yes)
for(i in $S/$sec){
if(/bin/test -f $i/INDEX){
try=`{grep -i $pat $i/INDEX | sed 's/^[^ ]* //' | sort -u}
if(! ~ $#try 0)
fils=($fils $i/$try)
}
}
# bug: should also do following loop if not all pages found
if(~ $#fils 0) {
# nothing in INDEX. try for file of given name
for(i) {
if(~ $i intro) i=0intro
for(n in $sec) {
try=`{echo $S/$n/$i | tr A-Z a-z}
if (/bin/test -f $try)
fils=($fils $try)
}
}
if(~ $#fils 0) {
echo 'man: no manual page' >[1=2]
exit 'no man'
}
}
for(i in $fils) {
if(! /bin/test -f $i)
echo need $i >[1=2]
if not {
switch($cmd) {
case w
echo $i
case t
roff t $i
case p
roff t $i | grep -v '^x X html' | proof
case P
roff t $i | page
case n
roff n $i | sed '
${
/^$/p
}
//N
/^\n$/D'
case b
x=`{echo $i | sed 's;/sys/man/(.*)/(.*);\1 \2;'}
if(~ $x(2) 0intro) x=($x(1) intro)
roff n $i | sed '
${
/^$/p
}
//N
/^\n$/D' |
plumb -i -d edit -a 'action=showdata filename=/man/'$x(2)^'('$x(1)^')'
}
}
}

103
rc/bin/map Executable file
View File

@ -0,0 +1,103 @@
#!/bin/rc
rfork en
# F FEATUREs, M map files, A other arguments
FEATURE=no
if (~ $MAPPROG '')
MAPPROG=/bin/aux/mapd
if (~ $MAPDIR '')
MAPDIR=/lib/map
F=(); M=(); A=();
for (i) {
switch ($FEATURE) {
case no
switch ($i) {
case -f
FEATURE=yes
F=($F)
case *
A=($A $i)
}
case yes
switch ($i) {
case -f
case -*
A=($A $i)
FEATURE=no
case riv*2
F=($F 201 202)
case riv*3
F=($F 201 202 203)
case riv*4
F=($F 201 202 203 204)
case riv*
F=($F 201)
case iriv*2
F=($F 206 207)
case iriv*[34]
F=($F 206 207 208)
case iriv*
F=($F 206)
case coast*2 shore*2 lake*2
F=($F 102)
case coast*3 shore*3 lake*3
F=($F 102 103)
case coast*4 shore*4 lake*4
F=($F 102 103 104)
case coast* shore* lake*
case ilake*[234] ishore*[234]
F=($F 106 107)
case ilake* ishore*
F=($F 106)
case reef*
F=($F 108)
case canal*2
F=($F 210 211)
case canal*[34]
F=($F 210 211 212)
case canal*
F=($F 210)
case glacier*
F=($F 115)
case state* province*
F=($F 401)
case countr*2
F=($F 301 302)
case countr*[34]
F=($F 301 302 303)
case countr*
F=($F 301)
case salt*[234]
F=($F 109 110)
case salt*
F=($F 109)
case ice*[234] shel*[234]
F=($F 113 114)
case ice* shel*
F=($F 113)
case *
echo map: unknown feature $i >[1=2]
exits "unknown feature"
}
}
}
for (j in $F) {
if (test -r $MAPDIR/$j)
M=($M $MAPDIR/$j)
}
if (~ $F ?*) {
if (test -r $MAPDIR/101)
M=(101 $M)
M=(-m $M)
}
if (~ $MAP '')
MAP=world
MAP=$MAP MAPDIR=$MAPDIR $MAPPROG $A $M

83
rc/bin/mapdemo Executable file
View File

@ -0,0 +1,83 @@
#!/bin/rc
fn demo {proj=$1; shift;
label=$1; shift;
{ echo 'o'
echo 'ra -8192 -8492 8192 8492'
echo 'e'
echo 'm -8192 8192'
echo t $type
echo 'm -8192 -8192'
echo t $proj - $label
MAP=world MAPDIR=/lib/map map $proj $* -s -d 5
}
sleep 5
}
rfork en
{
type='Equatorial projections centered on long. 0. Parallels are straight lines.'
demo mercator 'equally spaced straight meridians, conformal, straight compass courses'
demo sinusoidal 'equally spaced parallels, equal-area, same as bonne(0)'
demo cylequalarea 'equally spaced straight meridians, equal-area, true scale on Eq' 0
demo cylindrical 'central projection on tangent cylinder'
demo rectangular 'equally spaced parallels, equally spaced straight meridians, true scale on Eq' 0
demo gall 'parallels spaced stereographically on prime meridian, equally spaced straight meridians, true scale on Eq' 0
demo mollweide '(homalographic) equal-area, hemisphere is a circle'
demo gilbert 'globe mapped conformally on hemisphere, viewed orthographically'
type='Azimuthal: centered on the North Pole, Parallels are concentric circles, Meridians are equally spaced radial lines'
demo azequidistant 'equally spaced parallels, true distances from pole'
demo azequalarea 'equal area'
demo gnomonic 'central projecton on tangent plane, straight great circles'
demo perspective 'viewed along earth''s axis 2 earth radii from center of earth' 2
demo orthographic 'viewed from infinity'
demo stereographic 'conformal, projected from opposite pole'
demo laue 'radius = tan(2\(mu colatitude ), used in xray crystallography'
demo fisheye 'fisheye view of stereographic map, index of refraction 2' 2 -o 40.75 74
demo newyorker 'New Yorker map from viewing pedestal of radius .5' .5 -o 40.75 74
type='Polar conic projections symmetric about the Prime Meridian. Parallels are segments of concentric circles.'
demo conic 'central projection on cone tangent at 40' 40
demo simpleconic 'equally spaced parallels, true scale on 20 and 50' 20 50
demo lambert 'conformal, true scale on 20 and 50' 20 50
demo albers 'equal-area, true scale on 20 and 50' 20 50
demo bonne 'equally spaced parallels, equal-area, parallel 40 developed from tangent cone' 40
type='Projections with bilateral symmetry about the Prime Meridian and the equator.'
demo polyconic 'parallels developed from tangent cones, equally spaced along Prime Meridian'
demo aitoff 'equal-area projection of globe onto 2-to-1 ellipse, based on azequalarea'
demo lagrange 'conformal, maps whole sphere into a circle'
demo bicentric 'points plotted at true azimuth from two centers on the equator at longitudes +-40, great circles are straight lines' 40
demo elliptic 'points are plotted at true distance from two centers on the equator at longitudes +-40' 40
demo globular 'hemisphere is circle, circular meridians and parallels'
demo vandergrinten 'sphere is circle, meridians as in globular, circular arc parallels resemble mercator'
type='Doubly periodic conformal projections.'
demo guyou 'W and E hemispheres are square'
demo square 'World is square with Poles at diagonally opposite corners'
demo tetra 'map on tetrahedron with edge tangent to Prime Meridian at S Pole, unfolded into equilateral triangle'
demo hex 'world is hexagon centered on N Pole, N and S hemispheres are equilateral
triangles'
type='Retroazimuthal projections. Directions to center are true.'
demo mecca 'equally spaced vertical meridians' 21.4 -o 90 -39.8
demo homing 'distances to Mecca are true' 21.4 -o 90 -39.8
type='Miscellaneous projections.'
demo harrison 'oblique perspective from above the North Pole, 2 earth radii from the earth, looking along the Date Line 40 degrees off vertical' 2 40
demo trapezoidal 'equally spaced parallels, straight meridians equally spaced along parallels, true scale at 20 and 50 on Prime Meridian' 20 50
demo lune 'conformal, polar cap above Eq is 60-degree lune' 0 60
type='Maps based on the spheroid'
demo sp_mercator 'equally spaced straight meridians, conformal'
demo sp_albers 'equal-area, true scale on 20 and 50' 20 50
} | plot

4
rc/bin/membername Executable file
View File

@ -0,0 +1,4 @@
#!/bin/rc
tr ' ' '\012' <<eof | sed -e 's/[^(]*\(([^)]*)\).*/\1/' | tr '\012' ' '
$*
eof

3
rc/bin/mousereset Executable file
View File

@ -0,0 +1,3 @@
#!/bin/rc
echo reset >/dev/mousectl

2
rc/bin/nroff Executable file
View File

@ -0,0 +1,2 @@
#!/bin/rc
exec troff -N $*

8
rc/bin/patch/applied Executable file
View File

@ -0,0 +1,8 @@
#!/bin/rc
if(~ $#* 0){
echo 'usage: patch/applied patch-name...' >[1=2]
exit usage
}
patch/move applied $*

79
rc/bin/patch/apply Executable file
View File

@ -0,0 +1,79 @@
#!/bin/rc
rfork e
if(! ~ $#* 1){
echo 'usage: patch/apply patch-name' >[1=2]
exit usage
}
if(! test -d /n/sources/patch){
rfork n
9fs sources
}
if(! test -d /n/sources/patch/$1){
echo 'no such patch' /n/sources/patch/$1 >[1=2]
exit nopatch
}
builtin cd /n/sources/patch/$1 || exit nopatch
if(! patch/okay .){
echo 'bad patch: '$status >[1=2]
exit badpatch
}
if(! echo >.tmp || ! rm .tmp){
echo no write permission >[1=2]
exit 'no write permission'
}
echo -n merge... >[1=2]
fn xxx {
if(! test -f $1)
cp $2 $2.new
if not
ape/diff3 -m $1 $2.orig $2 >$2.new
if(grep -s '^<<<<' $2.new){
echo conflicts merging $1';' see `{pwd}^/$2.new >[1=2]
touch failed
}
}
rm -f failed
cat files | sed 's/^/xxx /' | rc
if(test -f failed){
echo exiting without changes >[1=2]
exit failed
}
echo -n backup... >[1=2]
fn xxx {
# echo cp $1 $2.backup
cp $1 $2.backup
}
cat files | sed 's/^/xxx /' |rc
echo -n copy... >[1=2]
fn xxx {
# echo cp $2.new $1
cp $2.new $1 || touch failed
}
cat files | sed 's/^/xxx /' | rc
fn xxx {
# echo cp $2.backup $1
cp $2.backup $1
}
if(test -f failed){
echo copying failed, restoring backups >[1=2]
cat files | sed 's/^/xxx /' | rc
exit failed
}
echo >[1=2]
echo to update sources: >[1=2]
cat files | awk '{print " update " $1 }' >[1=2]

85
rc/bin/patch/create Executable file
View File

@ -0,0 +1,85 @@
#!/bin/rc
rfork e
fn xchmod {
chmod $* >[2]/dev/null
}
if(~ $#* 0 1 2){
echo 'usage: patch/create name email file... [< description]' >[1=2]
exit usage
}
if(! echo $1 | grep -s '^[a-z_0-9.\-]+$'){
echo 'bad name: [a-z0-9._\-]+ only' >[1=2]
exit usage
}
if(! echo $2 | grep -s '^(-|[A-Za-z0-9.\-+]+@[A-Za-z0-9.\-+]+)$'){
echo 'bad email: [a-z0-9.-+] only; use ''-'' to not leave an email address.' >[1=2]
exit usage
}
if(! test -d /n/sources/patch){
rfork n
9fs sources
}
patch=$1
email=$2
shift
shift
d=/n/sources/patch/$patch
if(! mkdir $d){
echo mkdir $d failed >[1=2]
exit mkdir
}
if(! ~ $email -){
echo $email >$d/email
}
xchmod o-w $d
>$d/readme
>$d/files
>$d/notes
for(i in $*){
i=`{cleanname -d `{pwd} $i}
if(! test -f $i){
echo error: cannot find $i >[1=2]
rm -rf $d
exit oops
}
short=`{basename $i}
uniq=$short
n=0
while(test -f $d/$uniq){
uniq=$short.$n
n=`{echo 1+$n | hoc}
}
cp $i $d/$uniq
if(test -f /n/sources/plan9/$i){
if(cmp -s /n/sources/plan9/$i $i)
echo warning: new file $i does not differ from sources >[1=2]
cp /n/sources/plan9/$i $d/$uniq.orig
}
if not
echo warning: new file $i not on sources >[1=2]
echo $i $uniq >>$d/files
}
@{builtin cd $d && xchmod ug+rw * && xchmod a+r *}
if(~ `{cat /proc/$pid/fd | awk 'NR==2{print $NF}'} */dev/cons && test -w /dev/consctl){
>/dev/consctl {
echo holdon
cat >$d/readme
}
}
if not
cat >$d/readme
if(! test -s $d/readme){
echo 'no description given; aborting' >[1=2]
rm -rf $d
exit oops
}
echo $d

45
rc/bin/patch/diff Executable file
View File

@ -0,0 +1,45 @@
#!/bin/rc
# patch/diff [-w] patch-name
rfork e
fn usage {
echo 'usage: patch/diff [-bmnwz] patch-name' >[1=2]
exit usage
}
dopts=(-c)
while (! ~ $#* 0 && ~ $1 -*) {
switch ($1) {
case -[bmnw]
dopts=($dopts $1)
case -z
dopts=()
case *
usage
}
shift
}
if(! ~ $#* 1)
usage
if(! test -d /n/sources/patch){
rfork n
9fs sources
}
if(! test -d /n/sources/patch/$1){
echo 'no such patch' /n/sources/patch/$1 >[1=2]
exit nopatch
}
builtin cd /n/sources/patch/$1 || exit nopatch
if(! patch/okay .){
echo 'bad patch: '$status >[1=2]
exit badpatch
}
d=/n/sources/patch/$1
fn xxx {
echo $1
diff $dopts $2.orig $d/$2 | sed 's/^/ /'
}
cat files | sed 's/^/xxx /' | rc

54
rc/bin/patch/list Executable file
View File

@ -0,0 +1,54 @@
#!/bin/rc
rfork e
if(! test -d /n/sources/patch){
rfork n
9fs sources
}
pref=''
builtin cd /n/sources/patch || {
echo 'can''t cd /n/sources/patch' >[2=1]
exit no-sources
}
if(~ $1 applied saved sorry maybe){
pref=$1^'/'
shift
}
if(~ $#* 0)
*=(`{
if(~ $pref *?*)
builtin cd $pref
ls -t | grep -v '^(applied|saved|sorry|maybe)$'
})
trunc=(sed 5q)
if(~ $#* 1)
trunc=cat
{
for(i in $*){
i=$pref^$i
if(test -f $i/origls)
cat $i/origls | awk '{$NF="'$i'"; print}'
if not
ls -ld $i
if(patch/okay $i){
if(test -r $i/email)
echo from `{cat $i/email}
cat $i/files | awk '{print " " $1}'
cat $i/readme | sed 's/^/ /' | $trunc
if(test -f $i/notes){
echo
cat $i/notes
}
}
if not
echo ' 'bad patch: $status >[2=1]
echo
}
} >/tmp/patchtmp.$pid
cat /tmp/patchtmp.$pid
rm -f /tmp/patchtmp.$pid

31
rc/bin/patch/move Executable file
View File

@ -0,0 +1,31 @@
#!/bin/rc
# patch/move target patch-tree... - move patch tree(s) to target dir
rfork e
pats=/n/sources/patch
if(~ $#* 0 1){
echo 'usage: patch/move dst patch-name...' >[1=2]
exit usage
}
if(! test -d $pats){
rfork n
9fs sources
}
cd $pats
dst=$1
shift
for(src){
patbase = `{basename $src}
patdest = $dst/$patbase
if (~ $dst $src $patbase)
echo $0: skipping $src >[1=2]
if not if(! test -d $src)
echo $0: no such patch $pats/$src >[1=2]
if not if(test -d $patdest)
echo $0: already have $pats/$patdest >[1=2]
if not
ls -ldp $src >$src/origls &&
mkdir $patdest && dircp $src $patdest && rm -rf $src &&
test -s $patdest/email && patch/notify $patdest
}

35
rc/bin/patch/note Executable file
View File

@ -0,0 +1,35 @@
#!/bin/rc
rfork e
if(! ~ $#* 1){
echo 'usage: patch/note patch-name' >[1=2]
exit usage
}
if(! test -d /n/sources/patch){
rfork n
9fs sources
}
if(! test -d /n/sources/patch/$1){
echo 'no such patch' /n/sources/patch/$1 >[1=2]
exit nopatch
}
builtin cd /n/sources/patch/$1 || exit nopatch
if(! patch/okay .){
echo 'bad patch: '$status >[1=2]
exit badpatch
}
if(~ `{cat /proc/$pid/fd | awk 'NR==2{print $NF}'} */dev/cons && ~ `{ls -l /dev/consctl | awk '{print $1}'} *w*){
>/dev/consctl {
echo holdon
{echo `{date} `{cat /dev/user}
cat |sed 's/^/ /'; echo } >>notes
}
}
if not
{echo `{date} `{cat /dev/user}
cat |sed 's/^/ /'; echo } >>notes

9
rc/bin/patch/notify Executable file
View File

@ -0,0 +1,9 @@
#!/bin/rc
# patch/notify
rfork e
for(i)
# don't flood sys when merely shuffling patches around
if (~ $i applied/* saved/* sorry/*) {
patch/list $i | mail -s 'patch/list '^$i sys \
`{cat /n/sources/patch/$i/email}
}

14
rc/bin/patch/okay Executable file
View File

@ -0,0 +1,14 @@
#!/bin/rc
rfork e
if(! ~ $#* 1){
echo usage: patch/okay dir >[1=2]
exit usage
}
i=$1
if(! test -s $i/files || ! test -s $i/readme)
exit 'missing files'
if(grep -v '^/[_a-zA-Z0-9.\-+/:]+ [_a-zA-Z0-9.\-+:]+$' $i/files)
exit 'bad file list'
exit 0

19
rc/bin/patch/remove Executable file
View File

@ -0,0 +1,19 @@
#!/bin/rc
rfork e
if(~ $#* 0){
echo 'usage: patch/remove patch-name...' >[1=2]
exit usage
}
if(! test -d /n/sources/patch){
rfork n
9fs sources
}
for(i){
if(! test -d /n/sources/patch/$i)
echo 'no such patch' /n/sources/patch/$i >[1=2]
if not
rm -rf /n/sources/patch/$i
}

8
rc/bin/patch/save Executable file
View File

@ -0,0 +1,8 @@
#!/bin/rc
if(~ $#* 0){
echo 'usage: patch/save patch-name...' >[1=2]
exit usage
}
patch/move saved $*

8
rc/bin/patch/sorry Executable file
View File

@ -0,0 +1,8 @@
#!/bin/rc
if(~ $#* 0){
echo 'usage: patch/sorry patch-name...' >[1=2]
exit usage
}
patch/move sorry $*

35
rc/bin/patch/undo Executable file
View File

@ -0,0 +1,35 @@
#!/bin/rc
rfork e
if(! ~ $#* 1){
echo 'usage: patch/undo patch-name' >[1=2]
exit usage
}
if(! test -d /n/sources/patch){
rfork n
9fs sources
}
if(! test -d /n/sources/patch/$1){
echo 'no such patch' /n/sources/patch/$1 >[1=2]
exit nopatch
}
d=$1
builtin cd /n/sources/patch/$1 || exit nopatch
if(! patch/okay .){
echo 'bad patch: '$status >[1=2]
exit badpatch
}
fn xxx {
if(cmp $2.new $1){
echo cp /n/sources/patch/$d/$2.backup $1
cp $2.backup $1
}
if not
echo $1 has changed since patch was applied! >[2=1]
}
cat files | sed 's/^/xxx /' |rc

22
rc/bin/pc/bootfloppy Executable file
View File

@ -0,0 +1,22 @@
#!/bin/rc
if(~ $#* 0 1) {
echo 'usage: bootfloppy /dev/fd0disk plan9.ini [files...]'>[1=2]
exit usage
}
if(! test -f $2) {
echo $2 does not exist >[1=2]
exit noplan9.ini
}
disk=$1
ini=$2
shift
shift
mkdir /tmp/bootfloppy.$pid
cp $ini /tmp/bootfloppy.$pid/plan9.ini
dd -bs 512 -count 1 < /dev/zero >/tmp/bootfloppy.$pid/plan9.nvr
disk/format -b /386/pbs -f -d $disk /386/9load /tmp/bootfloppy.$pid/* $*
rm -rf /tmp/bootfloppy.$pid

72
rc/bin/pc/bootplan9 Executable file
View File

@ -0,0 +1,72 @@
#!/bin/rc
rfork e
. /rc/bin/pc/defs
if(! ~ $#* 1) {
echo 'usage: bootplan9 /dev/sdC0' >[1=2]
echo 'sets active the plan 9 partition on the named disk.' >[1=2]
exit usage
}
disk=$1
fn x {
if(! test -f $disk/$1) {
echo 'could not find '$disk/$1
exit disk
}
}
x plan9
x data
x ctl
diskbase=`{basename `{cleanname $disk}}
first=`{ls -p '#S' | sed 1q}
if(! ~ $first $diskbase) {
echo 'warning: The plan 9 partition is not on the boot disk,' >[1=2]
echo 'so making it the active partition will have no effect.' >[1=2]
}
p9offset=`{disk/fdisk -p $disk/data |grep '^part plan9 ' | awk '{print $4}'}
if(! ~ $#p9offset 1) {
echo 'could not find plan 9 partition.' >[1=2]
echo 'cannot happen' >[1=2]
exit bad
}
if(test $p9offset -gt 4128705) { # 65536 * 63
echo >[1=2]
echo 'Your Plan 9 partition is more than 2GB into your disk,' >[1=2]
echo 'and the master boot records used by most operating systems' >[1=2]
echo 'cannot access it (and thus cannot boot it).' >[1=2]
echo >[1=2]
echo 'Would you like to install a master boot record' >[1=2]
echo 'that will be able to access partitions more than 2GB into the disk?' >[1=2]
echo >[1=2]
prompt 'Install a new mbr' y n
switch($rd) {
case n
echo >[1=2]
echo 'Not setting Plan 9 partition active, then.' >[1=2]
echo >[1=2]
exit bad
case y
disk/mbr -m /386/mbr $disk/data
}
}
p9part=`{disk/fdisk $disk/data >[2]/dev/null </dev/null |
grep PLAN9 | sed 1q | sed 's/ *(p.) .*/\1/'}
if(~ $#p9part 1) {
{ echo 'A '^$p9part; echo w } | disk/fdisk $disk/data >[2]/dev/null >/dev/null
}
if not {
echo 'Could not find Plan 9 partition.'
exit notdone
}
exit

115
rc/bin/pc/bootwin9x Executable file
View File

@ -0,0 +1,115 @@
#!/bin/rc
dosdisk=`{ls /dev/sd??/dos >[2]/dev/null | sed 1q | sed 's!.*/(.*)/dos!\1!'}
if(~ $#dosdisk 0 || ! c: || ! test -f /n/c:/autoexec.bat || ! test -f /n/c:/config.sys) {
echo 'Could not find autoexec.bat or config.sys on the first FAT disk.' >[1=2]
exit
}
for (i in autoexec config msdos)
if(test -f /n/c:/$i.p9) {
echo 'A Plan 9 backup already exists; will not edit system files again.' >[1=2]
exit
}
for (i in autoexec.bat config.sys msdos.sys)
if(! cp /n/c:/$i /n/c:/^`{echo $i | sed 's/\.(bat|sys)$/.p9/'}) {
echo 'Could not back up '^$i^'; will not continue.' >[1=2]
exit
}
if(! test -d /n/c:/plan9 && ! mkdir /n/c:/plan9) {
echo 'Could not create directory /n/c:/plan9.' >[1=2]
exit
}
if(! cp /386/^(9load ld.com) /386/9pcdisk /n/c:/plan9) {
echo 'Could not copy Plan 9 boot files into /n/c:/plan9.' >[1=2]
exit
}
chmod +w /n/c:/autoexec.bat /n/c:/config.sys /n/c:/msdos.sys
if(grep -si 'Plan ?9' /n/c:/config.sys || grep -si 'Plan ?9' /n/c:/autoexec.bat) {
echo 'Plan 9 entries already in config.sys or autoexec.bat.' >[1=2]
echo 'Not changing them; refer to Plan 9 install documentation' >[1=2]
echo 'to configure manually.' >[1=2]
exit
}
if(! grep -si '\[menu\]' /n/c:/config.sys) {
{
echo 1
echo i
echo '[menu] '
echo 'menuitem=windows, Windows '
echo 'menudefault=windows '
echo ' '
echo '[common] '
echo ' '
echo '[windows] '
echo .
echo w
echo q
} | ed /n/c:/config.sys >/dev/null >[2]/dev/null
}
{
echo 1
echo '/\[[Mm][Ee][Nn][Uu]\]'
echo '?^[Mm][Ee][Nn][Uu][Ii][Tt][Ee][Mm]='
echo a
echo 'menuitem=plan9, Plan 9 from Bell Labs '
echo .
echo '$'
echo a
echo ' '
echo '[plan9] '
echo ' '
echo .
echo w
echo q
} | ed /n/c:/config.sys >/dev/null >[2]/dev/null
{
echo 1
echo i
echo '@echo off '
echo 'if %config%==plan9 goto plan9 '
echo 'goto notplan9 '
echo ':plan9 '
echo 'plan9\ld '^$dosdisk^'!dos!plan9/9load '
echo ':notplan9 '
echo .
echo w
echo q
} | ed /n/c:/autoexec.bat >/dev/null >[2]/dev/null
fn zeroopt {
if(grep -s '^'^$1^'=1' /n/c:/msdos.sys) {
{
echo '/^'^$1^'=1/s/=1/=0/'
echo w
echo q
} | ed /n/c:/msdos.sys >/dev/null >[2]/dev/null
}
if not if (grep -s '^'^$1^'=0' /n/c:/msdos.sys)
;
if not {
{
echo 1
echo i
echo '[Options] '
echo 'Logo=0 '
echo .
echo w
echo q
} | ed /n/c:/msdos.sys >/dev/null >[2]/dev/null
}
}
if(grep -si '^\[paths\]' /n/c:/msdos.sys){ # Windows 9x rather than DOS
zeroopt Logo
}
exit

53
rc/bin/pc/bootwinnt Executable file
View File

@ -0,0 +1,53 @@
#!/bin/rc
disk=`{ls /dev/sd??/plan9 >[2]/dev/null | sed 1q | sed 's!.*/(.*)/plan9!\1!'}
if(! ~ $#disk 1) {
echo 'No plan 9 disk found' >[1=2]
exit
}
if(! c: || ! test -f /n/c:/boot.ini) {
echo 'Could not find NT''s boot.ini on the first FAT disk.' >[1=2]
exit
}
if(test -f /n/c:/boot.p9) {
echo 'A Plan 9 backup already exists; will not edit boot.ini again.' >[1=2]
exit
}
if(! cp /n/c:/boot.ini /n/c:/boot.p9) {
echo 'Could not back up boot.ini; will not continue.' >[1=2]
exit
}
chmod +w /n/c:/boot.ini
if(! grep -si '\[operating systems\]' /n/c:/boot.ini) {
echo 'Could not parse boot.ini.' >[1=2]
exit
}
if(grep -si 'Plan 9' /n/c:/boot.ini) {
p9file=`{grep 'Plan 9' /n/c:/boot.ini | sed 1q | sed 's/=.*//'}
if(! ~ $p9file [Cc]:'\'*) {
echo 'Unexpected Plan 9 entry in boot.ini already; not continuing.' >[1=2]
exit
}
}
if not {
p9file='c:\bootsect.p9'
echo 'c:\bootsect.p9 = "Plan 9 from Bell Labs" ' >>/n/c:/boot.ini
}
p9file=/n/^`{echo $p9file | sed 's!\\!/!g'}
if(dd -if /dev/$disk/plan9 -bs 512 -count 1 -of $p9file >/dev/null >[2]/dev/null) {
echo 'Plan 9 added to Windows NT boot menu.' >[1=2]
exit
}
echo 'Error copying Plan 9 boot sector to file.'
exit

72
rc/bin/pc/defs Executable file
View File

@ -0,0 +1,72 @@
nl='
'
tab=' '
fn prompt {
def=()
what=()
if(~ $1 -d && ! ~ $#* 1){
def=$2
shift
shift
}
optstr=()
if(~ $1 -w && ! ~ $#* 1){
optstr=$2
shift
shift
}
pr=$1
shift
opts=($*)
if(~ $#opts 0) {
suf=' '
}
if not if(! ~ $#optstr 0) {
if(~ $optstr '')
suf=' '
if not {
pr=$pr^' ('^$"optstr^')'
suf=''
}
}
if not {
pr=$pr^' ('^$1
shift
for(i)
pr=$pr^', '^$i
pr=$pr^')'
suf=''
}
if(~ $#def 1)
pr=$pr^$suf^'['^$def^']'
pr=$pr^': '
okay=no
while(~ $okay no) {
# whatis opts
echo -n $pr >[1=2]
ifs='' {rd=`{read}}
if(~ $#rd 0)
exit notdone
rd=`{echo $rd}
if(~ $#rd 0 || ~ $rd '')
rd=$def
switch($#opts){
case 0
if(! ~ $rd '')
okay=yes
case *
if(~ $rd $opts)
okay=yes
}
}
echo -n $rd >/env/rd # just in case
}

22
rc/bin/pc/isfat Executable file
View File

@ -0,0 +1,22 @@
#!/bin/rc
rfork e
# 0000000 eb 3c 90 P l a n 9 . 0 0 00 02 04 02 00
# 0000010 02 00 02 02 P f8 14 00 ? 00 ff 00 ~ 04 } 00
# 0000020 02 P 00 00 80 00 ) a8 04 } 00 C Y L I N
# 0000030 D R I C A L F A T 1 6 fa 8c
if(! ~ $#* 1) {
echo 'usage: isfat /dev/sdC0/part' >[1=2]
exit usage
}
arg=$1
fn fat {
cmp -s <{dd -if $arg -bs 1 -count 3 -skip $1 >[2]/dev/null} <{echo -n FAT}
}
fat 54 || fat 82
exit $status

7
rc/bin/pc/personalize Executable file
View File

@ -0,0 +1,7 @@
#!/bin/rc
switch($#*){
case 1
user=$1
}
disk/mkfs -s /n/emelie /sys/lib/sysconfig/proto/usrproto

33
rc/bin/pc/setup.9fat Executable file
View File

@ -0,0 +1,33 @@
#!/bin/rc
rfork e
if(! ~ $#* 2) {
echo 'usage: setup.9fat /dev/sdC0/9fat plan9.ini' >[1=2]
exit usage
}
. /rc/bin/pc/defs
fat=$1
ini=$2
if(! test -f $fat) {
echo fat partition not found >[1=2]
exit fat
}
if(! test -f $ini) {
echo plan9.ini not found >[1=2]
exit ini
}
if(pc/isfat $fat) {
echo 'Already a FAT partition in '^$fat^'; ream it?'
prompt 'ream 9fat' y n
switch($rd) {
case n
exit
}
}
disk/format -r 2 -d -b /386/pbs $fat /386/9load /386/9pcdisk
mount -c /srv/dos /n/9fat $fat
cp $ini /n/9fat/plan9.ini
unmount /n/9fat

37
rc/bin/pc/setup.disk Executable file
View File

@ -0,0 +1,37 @@
#!/bin/rc
rfork e
if(! ~ $#* 2) {
echo 'usage: setup.disk /dev/sdC0 plan9.ini' >[1=2]
exit usage
}
disk=$1
ini=$2
if(! test -d $disk) {
echo disk directory not found >[1=2]
exit fat
}
if(! test -f $ini) {
echo plan9.ini not found >[1=2]
exit ini
}
disk/fdisk -wa $disk/data
if(! test -f $disk/plan9) {
echo could not create plan 9 partition >[1=2]
exit noplan9
}
disk/prep -cwa $disk/plan9
if(! test -f $disk/fs) {
echo did not create fs partition '(weird)' >[1=2]
exit nofs
}
disk/kfs -rb4096 -f $disk/fs
pc/setup.9fat $disk/9fat $ini
pc/update
pc/personalize

Some files were not shown because too many files have changed in this diff Show More