-
Notifications
You must be signed in to change notification settings - Fork 5
/
testfn.rc
213 lines (176 loc) · 3.46 KB
/
testfn.rc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/bin/rc
#rfork e
nl='
'
fn die {
echo $* : $status>[1=2]
exit die
}
fn usage {
echo usage: $1 >[1=2]
exit usage
}
switch($#TRASRVOPT){
case 0
OTRASRVOPT=()
case *
OTRASRVOPT=-o^$TRASRVOPT
}
if(~ $#TRASRV 0)
TRASRV=(8.trasrv)
if(~ $#SYNC 0)
SYNC=(8.minisync -A)
if(~ $#TRADUMP 0)
TRADUMP=(8.tradump)
if(~ $#TRAMKDB 0)
TRAMKDB=(8.tramkdb)
if(~ $#TRASCAN 0)
TRASCAN=(8.trascan)
if(~ $#TRATMP 0)
TRATMP=/tmp/tratest
RMFLAG=()
if(~ $#RCSHELL 0){
if(test -x /bin/rc)
RCSHELL=/bin/rc
if(~ $#RCSHELL 0 && test -x /usr/local/bin/rc){
RMFLAG=-d
RCSHELL=/usr/local/bin/rc
}
if(~ $#RCSHELL 0 && test -x /home/ny3/rsc/bin/^`{uname}^/^`{uname -m}^/rc){
RMFLAG=-d
RCSHELL=/home/ny3/rsc/bin/^`{uname}^/^`{uname -m}^/rc
}
if(~ $#RCSHELL 0)
die cannot find rcj
}
fn replica {
if(~ $TRATMP '') die not going to remove slash
/bin/rm -fr $TRATMP/*
for(i){
/bin/mkdir $TRATMP/$i || die
echo tramkdb... >[1=2]
echo >$TRATMP/$i.ignore || die
$TRAMKDB -R $TRATMP/$i.db $i || die
{
echo '#!'$RCSHELL
echo $TRASRV '$*' $OTRASRVOPT -i $TRATMP/$i.ignore $TRATMP/$i.db $TRATMP/$i
} >$TRATMP/$i.s || die
chmod +x $TRATMP/$i.s || die replica $i
}
}
fn proto {
if(! ~ $#* 2)
usage 'mount replica proto-addition'
if(test -f $TRATMP/$1.emptyproto)
/bin/rm -f $TRATMP/$1.emptyproto $TRATMP/$1.proto
echo $2 >>$TRATMP/$1.proto || die proto $1
}
fn sync {
if(test -f /etc/passwd)
sleep 1
flags=()
if(~ $1 -*){
flags=$1
shift
}
if(! ~ $#* 2 3)
usage 'sync [-flags] from to [path]'
@{
# rfork e
fn rm
fn mkdir
echo sync... >[1=2]
$SYNC $flags $TRATMP/$1.s $TRATMP/$2.s $3 || die sync $1 $2 $3
} || die sync $1 $2 $3
}
fn change {
if(! ~ $#* 2 || ! ~ $1 */*)
usage 'create replica/path contents'
test -f $TRATMP/$1 || die change non-file $1
echo $2 >$TRATMP/$1 || die change $1
}
fn create {
if(! ~ $#* 2 || ! ~ $1 */*)
usage 'create replica/path contents'
test ! -e $TRATMP/$1 || die create extant file $1
echo $2 >$TRATMP/$1 || die create $1
}
fn mkdir {
if(! ~ $#* 1 || ! ~ $1 */*)
usage 'mkdir replica/path'
/bin/mkdir $TRATMP/$1 || die mkdir $1
}
fn isfile {
if(! ~ $#* 1 2 || ! ~ $1 */*)
usage 'isfile replica/path [contents]'
test -f $TRATMP/$1 || die isfile $1
if(~ $#* 2)
cmp $TRATMP/$1 <{echo $2} || die isfile $1 $2
status=''
}
fn isdir {
if(! ~ $#* 1 || ! ~ $1 */*)
usage 'isfile replica/path'
test -d $TRATMP/$1 || die isdir $1
}
fn isnot {
if(! ~ $#* 1 || ! ~ $1 */*)
usage 'isfile replica/path'
test ! -e $TRATMP/$1 || die isnot $1
}
fn rm {
if(! ~ $#* 1 || ! ~ $1 */*)
usage 'rm replica/path'
test -e $TRATMP/$1 || die rm $1: nonexist
if(test -d $TRATMP/$1 && test -f /etc/passwd)
rmdir $TRATMP/$1
if(! test -d $TRATMP/$1|| ! test -f /etc/passwd)
/bin/rm -f $TRATMP/$1
}
fn ignore {
if(~ $#* 0 1)
usage 'ignore replica line ...'
r=$1
shift
{
for(i){
echo $i
}
} >$TRATMP/$r.ignore
}
fn x {
echo '***' $*
}
fn dump {
if(! ~ $#* 1 || ~ $1 */*)
usage 'dump replica'
echo '______________' db $1 '________________'
$TRADUMP $TRATMP/$1.db
echo '____________________________________'
}
fn scan {
if(! ~ $#* 1 || ~ $1 */*)
usage 'scan replica'
$TRASCAN $TRATMP/$1.s
}
fn uncover {
/bin/rm .coverage *,cover >[2]/dev/null
}
fn coverage {
python coverage.py -a sync.py
}
# fn scan {
# if(! ~ $#* 1 || ~ $1 */*)
# usage 'scan replica'
#
# echo 'Tscan /' | $TRATMP/$1.s -t >/dev/null
# }
fn run {
for(i){
echo $i
. $i
}
}
if(~ $#* 0)
prompt=('TRATEST: ' ' ') exec rc -i
run $*