-
Notifications
You must be signed in to change notification settings - Fork 0
/
dst.sh
executable file
·104 lines (86 loc) · 2.49 KB
/
dst.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
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
#!/bin/bash
# Distributo shell wrapper
# This wrapper is mainly built for use in the CS labs at St Andrews University; if you don't have a very similar setup
# this might not be useful.
#
USAGE="Usage: dst <file> <logpath> <client>+"
TTY=$(tty)
GROUP="232.1.1.232"
CONTROL_PORT="9511"
GROUP_PORT="9512"
SHARE="/cs/scratch/${USER}/"
#get the file to transfer
if [ -z $1 ]; then
echo "$USAGE"
exit 1
fi
FILE="$1"
shift
#get the location to write log output to
if [ -z $1 ]; then
echo "expected log path"
echo "$USAGE"
exit 1
fi
LOG="$1"
shift
#get the list of clients to connect to
if [ -z $1 ]; then
echo "expected list of clients to copy file to"
echo "$USAGE"
exit 1
fi
CLIENTS=()
while [ ! -z $1 ]; do
CLIENTS+=( $1 )
shift
done
#for client in "${CLIENTS[@]}"; do
# echo "$client"
#done
#might be useful if necessary
#get a list of key-value pairs: the client address paired with the place
#declare -A CLIENTS
#while [ ! -z $1 ]; do
# CLIENTS[$1]="$2"
# shift 2
#done
#for key in ${!CLIENTS[@]}; do
# echo ${key} ${CLIENTS[${key}]}
#done
# find the latest distributo version
if [ -d target ]; then
JARS=$(ls target | grep ^distributo | sort -r --version-sort)
if [ -z "${JARS}" ]; then
echo "no distributo jar found - has it been built?"
exit 1
fi
JAR=$(echo "${JARS}" | awk 'NR==1 {print;exit}')
if [ -z "${JARS}" ]; then
echo "no distributo jar found - has it been built?"
exit 1
fi
else
echo "no distributo jar found - has it been built?"
exit 1
fi
DST="java -jar target/${JAR}"
#start all clients
function clientStart {
#setup all our clients to receive the file
for client in "${CLIENTS[@]}"; do
#run the ssh in the background, sending log output to the logfile, and error output to the sender's terminal
nohup ssh -oStrictHostKeyChecking=no "${client}" "cd $(pwd) && ${DST} receive -s ${SHARE} -g ${GROUP} -gp ${GROUP_PORT} -c $(hostname) -cp ${CONTROL_PORT}" > "${LOG}/${client}.log" 2> "${TTY}" < /dev/null &
done
}
echo "===================DISTRIBUTO====================="
echo "sharing ${FILE} to ${#CLIENTS[@]} clients:"
for client in "${CLIENTS[@]}"; do
echo "- ${client}"
done
echo "at ${SHARE}"
echo "sending receiver log output to ${LOG}"
echo "=================================================="
#start listening for clients, and start the clients
clientStart &
${DST} send -f "${FILE}" -g "${GROUP}" -t "${#CLIENTS[@]}" -cp "${CONTROL_PORT}" -gp "${GROUP_PORT}"