|
0
|
1 |
#!/bin/bash
|
|
|
2 |
base=$(dirname $0)
|
|
|
3 |
P=dejsem
|
|
|
4 |
DEB=${DEB:-4}
|
|
|
5 |
CHAN=${CHAN:-2}
|
|
|
6 |
HOST=${HOST:-racek.hh.cz}
|
|
|
7 |
export DEB CHAN HOST
|
|
|
8 |
xclip="xclip -selection clipboard"
|
|
|
9 |
eta="tplzKrx6tž88ČJGlŘeMf."
|
|
|
10 |
tmp=/tmp/dejsem
|
|
|
11 |
tmpf=$tmp/file
|
|
|
12 |
tmpd=$tmp/dir
|
|
|
13 |
|
|
|
14 |
red="\e[1;31m"
|
|
|
15 |
green="\e[1;32m"
|
|
|
16 |
std="\e[0;39m"
|
|
|
17 |
|
|
|
18 |
help() {
|
|
|
19 |
n=$(basename $0)
|
|
|
20 |
echo -e "syntax:"
|
|
|
21 |
echo -e "\t$n clip { short | long }"
|
|
|
22 |
echo -e "\t$n hist"
|
|
|
23 |
echo -e "\t$n srv { short | long | dir }"
|
|
|
24 |
echo -e "\t$n peer { short | long | dir }"
|
|
|
25 |
echo -e "\t$n all"
|
|
|
26 |
echo
|
|
|
27 |
echo ENVIRONMENT:
|
|
|
28 |
echo DEB=0-5
|
|
|
29 |
echo HOST="<server>"
|
|
|
30 |
echo SSL="<path to ssl repository>"
|
|
|
31 |
exit 1
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
clean() { rm -rf /tmp/dejsem; }
|
|
|
35 |
|
|
|
36 |
etalon() {
|
|
|
37 |
#----------------------------------------
|
|
|
38 |
# create etalon file of specified size
|
|
|
39 |
#----------------------------------------
|
|
|
40 |
mkdir -p $tmpf/chk
|
|
|
41 |
rm -f $tmpf/etalon
|
|
|
42 |
echo -n $eta >$tmpf/etalon
|
|
|
43 |
cat $tmpf/etalon >$tmpf/f
|
|
|
44 |
for i in `seq $1`
|
|
|
45 |
do cat $tmpf/etalon >> $tmpf/f
|
|
|
46 |
cat $tmpf/f >> $tmpf/etalon
|
|
|
47 |
done
|
|
|
48 |
[[ $# -gt 1 ]] && echo -n "$2 " | cat - $tmp/f >$tmpf/etalon
|
|
|
49 |
touch -r /etc $tmpf/etalon
|
|
|
50 |
( cd $tmpf; ls -l etalon >chk/0.stat; )
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
etadir() {
|
|
|
54 |
#----------------------------------------
|
|
|
55 |
# create etalon directory
|
|
|
56 |
#----------------------------------------
|
|
|
57 |
mkdir -p $tmpd/chk
|
|
|
58 |
rm -rf $tmpd/etalon
|
|
|
59 |
mkdir -p $tmpd/etalon/d/alev
|
|
|
60 |
mkdir -p $tmpd/etalon/epol
|
|
|
61 |
|
|
|
62 |
etalon 3
|
|
|
63 |
cp $tmpf/etalon $tmpd/etalon/f0
|
|
|
64 |
touch -r /etc $tmpd/etalon/f0
|
|
|
65 |
cp $tmpf/etalon $tmpd/etalon/d/f1
|
|
|
66 |
|
|
|
67 |
etalon 5
|
|
|
68 |
cp $tmpf/etalon $tmpd/etalon/epol/f2
|
|
|
69 |
touch -r /lib $tmpd/etalon/epol/f2
|
|
|
70 |
cp $tmpf/etalon $tmpd/etalon/d/alev/f3
|
|
|
71 |
touch -r /usr/lib $tmpd/etalon/d/alev/f3
|
|
|
72 |
|
|
|
73 |
touch -r /home $tmpd/etalon/d/alev
|
|
|
74 |
touch -r /bin $tmpd/etalon/epol
|
|
|
75 |
touch -r /usr $tmpd/etalon
|
|
|
76 |
|
|
|
77 |
( cd $tmpd
|
|
|
78 |
zip -qr chk/0.zip etalon
|
|
|
79 |
set - $(du -sbx etalon)
|
|
|
80 |
echo $1 >chk/0.size
|
|
|
81 |
ls -R etalon >chk/0.list
|
|
|
82 |
ls -lR etalon >chk/0.stat
|
|
|
83 |
)
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
say() {
|
|
|
87 |
echo -e $*
|
|
|
88 |
echo
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
chkdir() {
|
|
|
92 |
#----------------------------------------
|
|
|
93 |
# compare sent and received etalon directory
|
|
|
94 |
#----------------------------------------
|
|
|
95 |
( cd $tmpd/chk
|
|
|
96 |
zip -qr 1.zip etalon || return 1
|
|
|
97 |
set - $(du -sbx etalon)
|
|
|
98 |
echo $1 >1.size
|
|
|
99 |
ls -R etalon >1.list
|
|
|
100 |
ls -lR etalon >1.stat
|
|
|
101 |
|
|
|
102 |
if diff 0.list 1.list &>/dev/null
|
|
|
103 |
then say file/dir names ${green}OK${std}.
|
|
|
104 |
else say original and result file list ${red}differ${std}!!!
|
|
|
105 |
return 1
|
|
|
106 |
fi
|
|
|
107 |
if diff 0.size 1.size &>/dev/null
|
|
|
108 |
then say total byte count ${green}OK${std}.
|
|
|
109 |
else say original and result byte count ${red}differ${std}!!!
|
|
|
110 |
return 1
|
|
|
111 |
fi
|
|
|
112 |
if diff 0.stat 1.stat &>/dev/null
|
|
|
113 |
then say time stamps ${green}OK${std}.
|
|
|
114 |
else say original and result time stamps ${red}differ${std}!!!
|
|
|
115 |
return 1
|
|
|
116 |
fi
|
|
|
117 |
if diff 0.zip 1.zip &>/dev/null
|
|
|
118 |
then return 0
|
|
|
119 |
else say data contents ${red}differ${std}!!!
|
|
|
120 |
return 1
|
|
|
121 |
fi
|
|
|
122 |
)}
|
|
|
123 |
|
|
|
124 |
chkfile() {
|
|
|
125 |
#----------------------------------------
|
|
|
126 |
# compare sent and received etalon files
|
|
|
127 |
#----------------------------------------
|
|
|
128 |
if diff $tmpf/etalon $tmpf/chk/etalon
|
|
|
129 |
then say content of received file ${green}OK$std.
|
|
|
130 |
else say data content ${red}differs${std}!!!
|
|
|
131 |
return 1
|
|
|
132 |
fi
|
|
|
133 |
( cd $tmpf/chk; ls -l etalon >1.stat; )
|
|
|
134 |
if diff $tmpf/chk/0.stat $tmpf/chk/1.stat
|
|
|
135 |
then say time stamps ${green}OK${std}.
|
|
|
136 |
else say original and result time stamps ${red}differ${std}!!!
|
|
|
137 |
return 1
|
|
|
138 |
fi
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
clip() {
|
|
|
142 |
#----------------------------------------
|
|
|
143 |
# test clipboard exchange
|
|
|
144 |
#----------------------------------------
|
|
|
145 |
[[ $1 ]] || help
|
|
|
146 |
case $1 in
|
|
|
147 |
short ) n=2 ;;
|
|
|
148 |
long ) n=7 ;;
|
|
|
149 |
esac
|
|
|
150 |
etalon $n
|
|
|
151 |
clf=$tmpf/etalon
|
|
|
152 |
$xclip -i <$clf
|
|
|
153 |
$xclip -o >$tmpf/f1
|
|
|
154 |
cl=$($xclip -o)
|
|
|
155 |
echo
|
|
|
156 |
say ">>> clipboard $1: ${#cl} chars >>> $($xclip -o | head -c 66)"
|
|
|
157 |
$P --push
|
|
|
158 |
echo
|
|
|
159 |
read -p ">>> on Android perform pull clipboard "
|
|
|
160 |
echo
|
|
|
161 |
echo "" | $xclip -i
|
|
|
162 |
ssh root@$HOST rm -f "/L/dejsem/$(printf %02d $CHAN)/clipboard"
|
|
|
163 |
read -p ">>> on Android perform push clipboard "
|
|
|
164 |
echo
|
|
|
165 |
$P --pull
|
|
|
166 |
$xclip -o >$tmpf/f2
|
|
|
167 |
echo
|
|
|
168 |
diff $tmpf/f1 $tmpf/f2 && return 0 || return 1
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
hist() {
|
|
|
172 |
#----------------------------------------
|
|
|
173 |
# test clipboard history
|
|
|
174 |
#----------------------------------------
|
|
|
175 |
ssh root@$HOST rm -rf "/L/dejsem/$(printf %02d $CHAN)/history"
|
|
|
176 |
etalon 1
|
|
|
177 |
echo 1111 entry 1, $(<$tmpf/etalon) | $xclip -i
|
|
|
178 |
$P --push
|
|
|
179 |
etalon 3
|
|
|
180 |
echo 2222 long entry 2, $(<$tmpf/etalon) >$tmpf/chk/0.entry
|
|
|
181 |
$xclip -i $tmpf/chk/0.entry
|
|
|
182 |
$P --push
|
|
|
183 |
etalon 1
|
|
|
184 |
echo 3333 entry 3, $(<$tmpf/etalon) | $xclip -i
|
|
|
185 |
$P --push
|
|
|
186 |
rm -rf ~/.local/share/dejsem/history
|
|
|
187 |
echo
|
|
|
188 |
read -p ">>> pulling clipboard history to local host - it should contain 3 entries, hit ENTER "
|
|
|
189 |
echo
|
|
|
190 |
$P --pullhist
|
|
|
191 |
echo
|
|
|
192 |
read -p ">>> on Android go to clipboard history and choose \"2222 long entry 2\" "
|
|
|
193 |
echo
|
|
|
194 |
read -p ">>> on Android push clipboard "
|
|
|
195 |
$P --pull
|
|
|
196 |
$xclip -o >$tmpf/chk/1.entry
|
|
|
197 |
echo
|
|
|
198 |
diff $tmpf/chk/0.entry $tmpf/chk/1.entry && return 0 || return 1
|
|
|
199 |
}
|
|
|
200 |
|
|
|
201 |
srv() {
|
|
|
202 |
#----------------------------------------
|
|
|
203 |
# test file exchange with server
|
|
|
204 |
#----------------------------------------
|
|
|
205 |
[[ $1 ]] || help
|
|
|
206 |
if [[ $1 == dir ]]
|
|
|
207 |
then
|
|
|
208 |
etadir
|
|
|
209 |
fp=$tmpd/etalon
|
|
|
210 |
ssh root@$HOST rm -rf "/L/dejsem/$(printf %02d $CHAN)/files/etalon"
|
|
|
211 |
say ">>> uploading directory etalon..."
|
|
|
212 |
$P --pushfile $fp
|
|
|
213 |
echo
|
|
|
214 |
read -p ">>> on Android refresh / on server and download directory etalon "
|
|
|
215 |
echo
|
|
|
216 |
ssh root@$HOST rm -rf "/L/dejsem/$(printf %02d $CHAN)/files/etalon"
|
|
|
217 |
echo
|
|
|
218 |
read -p ">>> on Android upload directory etalon to / on server "
|
|
|
219 |
echo
|
|
|
220 |
rm -rf $tmpd/chk/etalon
|
|
|
221 |
$P --pullfile etalon $tmpd/chk
|
|
|
222 |
echo
|
|
|
223 |
chkdir
|
|
|
224 |
else
|
|
|
225 |
case $1 in
|
|
|
226 |
short ) n=3 ;;
|
|
|
227 |
long ) n=8 ;;
|
|
|
228 |
esac
|
|
|
229 |
etalon $n
|
|
|
230 |
fp=$tmpf/etalon
|
|
|
231 |
ssh root@$HOST rm -rf "/L/dejsem/$(printf %02d $CHAN)/files/etalon"
|
|
|
232 |
say ">>> uploading file etalon: $(set -- $(ls -lh $fp); echo $5) bytes"
|
|
|
233 |
$P --pushfile $fp
|
|
|
234 |
echo
|
|
|
235 |
read -p ">>> refresh Android server-list and dowload file etalon "
|
|
|
236 |
ssh root@$HOST rm -rf "/L/dejsem/$(printf %02d $CHAN)/files/etalon"
|
|
|
237 |
echo
|
|
|
238 |
read -p ">>> on Android upload file etalon "
|
|
|
239 |
echo
|
|
|
240 |
say ">>> downloading file etalon: $(set -- $(ls -lh $fp); echo $5) bytes"
|
|
|
241 |
rm -rf $tmpf/chk/etalon
|
|
|
242 |
$P --pullfile etalon $tmpf/chk
|
|
|
243 |
echo
|
|
|
244 |
chkfile
|
|
|
245 |
fi
|
|
|
246 |
}
|
|
|
247 |
|
|
|
248 |
peer() {
|
|
|
249 |
#----------------------------------------
|
|
|
250 |
# test file exchange with peer
|
|
|
251 |
#----------------------------------------
|
|
|
252 |
[[ $1 ]] || help
|
|
|
253 |
if [[ $1 == dir ]]
|
|
|
254 |
then
|
|
|
255 |
etadir
|
|
|
256 |
fp=$tmpd/etalon
|
|
|
257 |
echo
|
|
|
258 |
read -p ">>> on Android start pull from peer "
|
|
|
259 |
echo
|
|
|
260 |
$P --pushpeer $fp
|
|
|
261 |
say ">>> on Android copy directory etalon to peer (${red}1 minute TIMEOUT!${std})"
|
|
|
262 |
rm -rf $tmpd/chk/etalon
|
|
|
263 |
$P --pullpeer $tmpd/chk
|
|
|
264 |
echo
|
|
|
265 |
chkdir
|
|
|
266 |
else
|
|
|
267 |
case $1 in
|
|
|
268 |
short ) n=3 ;;
|
|
|
269 |
long ) n=13 ;;
|
|
|
270 |
esac
|
|
|
271 |
etalon $n
|
|
|
272 |
read -p ">>> on Android start pull from peer "
|
|
|
273 |
echo
|
|
|
274 |
$P --pushpeer $tmpd/etalon
|
|
|
275 |
echo
|
|
|
276 |
say ">>> on Android copy file etalon to peer (${red}1 minute TIMEOUT${std})"
|
|
|
277 |
rm -rf $tmpf/chk/etalon
|
|
|
278 |
$P --pullpeer $tmpf/chk
|
|
|
279 |
echo
|
|
|
280 |
chkfile
|
|
|
281 |
fi
|
|
|
282 |
}
|
|
|
283 |
|
|
|
284 |
tst() {
|
|
|
285 |
#----------------------------------------
|
|
|
286 |
# run specified test
|
|
|
287 |
#----------------------------------------
|
|
|
288 |
x=y
|
|
|
289 |
while [[ $x == y ]]; do
|
|
|
290 |
echo
|
|
|
291 |
echo "*----------------------------------------"
|
|
|
292 |
echo "* $*"
|
|
|
293 |
echo "*----------------------------------------"
|
|
|
294 |
echo
|
|
|
295 |
$* && say "${green}>>> OK${std}" || say "${red}>>> orig & result don't compare !!!${std}"
|
|
|
296 |
read -p ">>> repaeat the test? y/N " x
|
|
|
297 |
done
|
|
|
298 |
}
|
|
|
299 |
|
|
|
300 |
all() {
|
|
|
301 |
#----------------------------------------
|
|
|
302 |
# run all tests
|
|
|
303 |
#----------------------------------------
|
|
|
304 |
tst clip short
|
|
|
305 |
tst srv dir
|
|
|
306 |
tst clip long
|
|
|
307 |
tst srv short
|
|
|
308 |
tst srv long
|
|
|
309 |
tst peer short
|
|
|
310 |
tst peer long
|
|
|
311 |
tst peer dir
|
|
|
312 |
}
|
|
|
313 |
|
|
|
314 |
trap clean exit
|
|
|
315 |
clean
|
|
|
316 |
mkdir -p $tmp
|
|
|
317 |
|
|
|
318 |
[[ $1 == all ]] && {
|
|
|
319 |
all
|
|
|
320 |
exit
|
|
|
321 |
}
|
|
|
322 |
|
|
|
323 |
(($#)) && {
|
|
|
324 |
[[ $# -lt 1 ]] && help
|
|
|
325 |
tst $*
|
|
|
326 |
exit
|
|
|
327 |
0 }
|
|
|
328 |
|
|
|
329 |
help
|
|
|
330 |
10 |