-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathp2p.sh
57 lines (51 loc) · 1.62 KB
/
p2p.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
#!/bin/bash
print_options()
{
echo ""
echo "Usage: $0 [Options] <server ip address> <server port> <your username or public key> <other peer's username / public key>"
echo ""
echo "Options inlcude: "
echo " -e: p2p Messaging without encryption. Use your username and other peer's username"
echo " -m: p2p Messaging with encrpytion. Provide path to your public key and peer's public key"
echo " -f: p2p file sharing (send). Provide path to your public key and peer's public key and path to file to share (up to 7mb)"
echo " -r: p2p file sharing (receive). Provide path to your public key and peer's public key"
echo ""
exit 0
}
# Check before hand whether all args were provided
run_script()
{
if [ -z "$2" ] || [ -z "$3" ] || [ -z "$4" ] || [ -z "$5" ]
then
echo "There are missing arguments. Please refer to the options below";
print_options
fi
if [ $1 = "-f" ]
then
if [ -z $6 ]
then
echo "Please include the path of file to share with peer";
print_options
fi
fi
case $1 in
"-e") "${P2P_EXE_PATH}" $2 $3 $4 $5;;
"-m") "${P2P_EXE_PATH}" $2 $3 "0" $4 $5;;
"-f") "${P2P_EXE_PATH}" $2 $3 "0" $4 $5 $6;;
"-r") "${P2P_EXE_PATH}" $2 $3 "0" $4 $5 "-r";;
esac
exit 0
}
while getopts "e:m:f:r:" opt
do
case "$opt" in
e ) run_script "-e" $2 $3 $4 $5;;
m ) run_script "-m" $2 $3 $4 $5;;
f ) run_script "-f" $2 $3 $4 $5 $6;;
r ) run_script "-r" $2 $3 $4 $5;;
h ) print_options;;
? ) print_options;;
esac
done
# In case no option was given
print_options;