-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.sh
executable file
·76 lines (70 loc) · 1.44 KB
/
client.sh
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
#!/bin/bash
# client.sh
# passes requests to the server and returns the output
client="$1"
request="$2"
full_request="$@"
if [ "$#" -lt 2 ]; then
echo "Error: This script requires at least two arguments"
echo "usage: $0 clientid req [*args]"
exit 1
elif [ ! -e "server.pipe" ]; then
echo "Error: Server is not started"
exit 2
fi
case "$request" in
create)
if [ ! "$#" -eq 3 ]; then
echo "Error: This request requires one argument"
echo "usage: $0 clientid $request user"
exit 1
fi
;;
add)
if [ ! "$#" -eq 4 ]; then
echo "Error: This request requires two arguments"
echo "usage: $0 clientid $request user friend"
exit 1
fi
;;
post)
if [ "$#" -lt 4 ]; then
echo "Error: This request requires three arguments"
echo "usage: $0 clientid $request recevier sender message"
exit 1
fi
;;
show)
if [ ! "$#" -eq 3 ]; then
echo "Error: This request requires one argument"
echo "usage: $0 clientid $request user"
exit 1
fi
;;
shutdown)
if [ ! "$#" -eq 2 ]; then
echo "Error: This request requires 0 arguments"
echo "usage: $0 clientid $request"
exit 1
fi
;;
*)
echo "Error: bad request"
exit 1
;;
esac
./P.sh "$client"
if [ -e "$client.pipe" ]; then
echo "Error: Client $client in use"
./V.sh "$client"
exit 2
else
mkfifo "$client.pipe"
fi
./V.sh "$client"
echo "$full_request" >> server.pipe
while read -r input; do
echo "$input"
done < "$client.pipe"
rm "$client.pipe"
exit 0