2016-02-14 04:18:33 +00:00
|
|
|
#!/bin/rc
|
|
|
|
rfork e
|
|
|
|
|
|
|
|
argv0=$0
|
|
|
|
fn usage {
|
2018-01-07 01:44:53 +00:00
|
|
|
echo 'usage:' $argv0 '[-u user] [-k keypattern] [-P patternfile] [-p] [-t timeout] [-h host] [-c cmd arg ...]' >[1=2]
|
2016-02-14 04:18:33 +00:00
|
|
|
exit 'usage'
|
|
|
|
}
|
|
|
|
|
|
|
|
fn server {
|
|
|
|
mount -nc /fd/0 /mnt/term || exit
|
|
|
|
bind -q /mnt/term/dev/cons /dev/cons
|
|
|
|
</mnt/term/fd/10 >/mnt/term/fd/11 >[2]/mnt/term/fd/12 {
|
|
|
|
~ $#dir 0 || cd $"dir || echo 'can''t change directory: '^$"dir >[1=2]
|
|
|
|
switch($#cmd){
|
|
|
|
case 0; cmd=(rc -li)
|
|
|
|
case 1; cmd=(rc -lc $cmd)
|
|
|
|
case *; cmd=(rc -lc '$*' $cmd)
|
|
|
|
}
|
|
|
|
rm -f /env/^(cmd dir 'fn#server')
|
|
|
|
service=cpu exec $cmd
|
|
|
|
} &
|
|
|
|
if(test -d /mnt/term/mnt/cpunote) {
|
|
|
|
rfork e
|
|
|
|
mainproc=$apid
|
2016-02-27 01:08:00 +00:00
|
|
|
{cat; echo -n hangup} </mnt/term/mnt/cpunote/data >/proc/$mainproc/notepg &
|
2016-02-14 04:18:33 +00:00
|
|
|
noteproc=$apid
|
|
|
|
wait $mainproc
|
|
|
|
echo -n $status >/mnt/term/env/rstatus >[2]/dev/null
|
2016-02-27 01:08:00 +00:00
|
|
|
echo -n hangup >/proc/$noteproc/notepg
|
2016-02-14 04:18:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn client {
|
|
|
|
echo -n >/env/rstatus
|
|
|
|
rfork n
|
|
|
|
bind '#|' /mnt/cpunote || exit
|
|
|
|
</fd/0 exec $exportfs -r / &
|
|
|
|
</dev/null >/mnt/cpunote/data1 {
|
|
|
|
fn sigkill { echo -n kill >/mnt/cpunote/data1 }
|
|
|
|
fn sighup { echo -n hangup >/mnt/cpunote/data1 }
|
|
|
|
fn sigint { status=interrupted }
|
|
|
|
wait
|
|
|
|
while(~ $status interrupted) {
|
|
|
|
echo -n interrupt
|
|
|
|
wait
|
|
|
|
}
|
|
|
|
status=`{cat /env/rstatus}
|
|
|
|
exit $"status
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd=()
|
|
|
|
host='$cpu'
|
2017-01-15 17:25:54 +00:00
|
|
|
if(~ $#cpu 1) host=$cpu
|
2016-02-14 04:18:33 +00:00
|
|
|
exportfs=/bin/exportfs
|
|
|
|
connect=/bin/rconnect
|
|
|
|
|
|
|
|
while(~ $1 -*){
|
|
|
|
switch($1){
|
|
|
|
case -p; connect=($connect $1)
|
|
|
|
case *
|
|
|
|
~ $#* 1 && usage
|
|
|
|
switch($1){
|
|
|
|
case -P; exportfs=($exportfs $1 $2)
|
2018-01-07 01:44:53 +00:00
|
|
|
case -[ukt]; connect=($connect $1 $2)
|
2016-02-14 04:18:33 +00:00
|
|
|
case -h; host=$2
|
|
|
|
case -c; cmd=$*(2-); *=()
|
|
|
|
case *; usage
|
|
|
|
}
|
|
|
|
shift
|
|
|
|
}
|
|
|
|
shift
|
|
|
|
}
|
|
|
|
~ $#* 0 || usage
|
|
|
|
|
|
|
|
fn pvar {
|
|
|
|
while(! ~ $#* 0){
|
2018-11-13 10:03:37 +00:00
|
|
|
~ $#$1 0 && echo $1'=()' ||
|
|
|
|
path=/dev/null builtin whatis $1
|
2016-02-14 04:18:33 +00:00
|
|
|
shift
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-19 18:05:35 +00:00
|
|
|
>/env/rscript {
|
|
|
|
dir=`{pwd} pvar dir cmd
|
|
|
|
builtin whatis server
|
|
|
|
echo server
|
|
|
|
}
|
|
|
|
exec $connect $host /env/rscript client <[10=0] >[11=1] >[12=2]
|