changelog shortlog tags branches changeset files revisions annotate raw help

Mercurial > hg > plan9front / rc/bin/rconnect

changeset 7243: 34f64dcbbc25
parent: b3f02338356b
author: cinap_lenrek@felloff.net
date: Fri, 17 May 2019 18:14:10 +0200
permissions: -rwxr-xr-x
description: 7l: don't hardcode 4k pagesize, use INITRND
1 #!/bin/rc
2 rfork e
3 
4 argv0=$0
5 aanto=86400 #one day
6 fn usage {
7  echo 'usage:' $argv0 '[-u user] [-k keypattern] [-p] [-t timeout] host remotescript localcommand arg ...' >[1=2]
8  exit 'usage'
9 }
10 
11 fn pvar {
12  while(! ~ $#* 0){
13  ~ $#$1 0 && echo $1'=()' ||
14  path=/dev/null builtin whatis $1
15  shift
16  }
17 }
18 
19 filter=()
20 keyspec=()
21 while(~ $1 -*){
22  switch($1){
23  case -p; filter=aan
24  case *
25  ~ $#* 1 && usage
26  switch($1){
27  case -k; keyspec=($keyspec $2)
28  case -u; keyspec=($keyspec `{user=$2 pvar user})
29  case -t; aanto=$2
30  case *; usage
31  }
32  shift
33  }
34  shift
35 }
36 
37 ~ $#* 0 1 2 && usage
38 
39 host=$1
40 shift
41 
42 fn sendscript {
43  echo -n $host >/proc/$pid/args
44  cat $1 >/env/v; wc -c </env/v; cat /env/v; rm /env/v
45  shift
46  $*
47 }
48 
49 if(~ $filter aan){
50  fn aanserver {
51  ~ $#netdir 1 || netdir=/net/tcp/clone
52  netdir=`{basename -d $netdir} || exit
53  <>$netdir/clone {
54  netdir=$netdir/`{read} || exit
55  >[3] $netdir/ctl {
56  echo -n 'announce *!0' >[1=3]
57  echo `{cat $netdir/local} || exit
58  bind '#|' /mnt/aan || exit
59  exec aan -m $aanto $netdir <>/mnt/aan/data1 >[1=0] >[2]/dev/null &
60  }
61  }
62  <>/mnt/aan/data >[1=0] >[2]/dev/null {
63  rfork n
64  fn server {
65  echo -n aanserver $netdir >/proc/$pid/args
66  rm -f /env/^('fn#server' 'fn#aanserver' 'aanto')
67  . <{n=`{read} && ! ~ $#n 0 && read -c $n} >[2=1]
68  }
69  exec tlssrv -A /bin/rc -c server
70  exit
71  }
72  }
73  fn aanclient {
74  host=`{echo $host | sed 's/(.*)!([^!]+)$/\1/'}^!^`{read | sed 's/(.*)!([^!]+)$/\2/'} || exit
75  tlsclient -a -o <>{rfork s; aan -m $aanto -c $host >[1=0]} /bin/rc -c 'sendscript $*' $*
76  }
77  exec $argv0 -k $"keyspec $host <{builtin whatis aanserver; pvar aanto; echo aanserver} aanclient $*
78  exit
79 }
80 
81 switch($host){
82 case *!*!*;
83 case *!*; host=$host!rcpu
84 case *; host=net!$host!rcpu
85 }
86 
87 exec tlsclient -ak $"keyspec $host /bin/rc -c 'sendscript $*' $*