-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlauncher-mac.sh
executable file
·75 lines (54 loc) · 1.78 KB
/
launcher-mac.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
#!/usr/bin/env bash
# Change this to your netid
netid=kxp210004
# Root directory of your project
PROJECT_DIR=/home/013/k/kx/kxp210004/LeaderElection
# Directory where the config file is located on your local system
CONFIG_LOCAL=$HOME/Desktop/LeaderElection/config.txt
# Directory your java classes are in
BINARY_DIR=$PROJECT_DIR/bin
# Your main project class
PROGRAM=Main
i=0
declare -A uidHostMap
cat $CONFIG_LOCAL | sed -e "s/#.*//" | sed -e "/^\s*$/d" |
(
mapfile -t configFile
totalNodes=${configFile[0]}
counter=1
while [[ $counter -le $totalNodes ]]
do
line=(${configFile[$((counter))]})
uid="${line[0]}"
host="${line[1]}"
port="${line[2]}"
uidHostMap[$uid]="$uid,$host,$port"
counter=$((counter + 1))
done
# Uncomment to debug the values in the uidHostMap hashmap.
# for key in ${!uidHostMap[@]}; do
# echo ${key} ${uidHostMap[${key}]}
# done
i=1
while [[ $i -le $totalNodes ]]
do
line=(${configFile[$((i))]})
uid="${line[0]}"
host="${line[1]}"
port="${line[2]}"
echo $uid $host $port
neighborsArray=(${configFile[$i + totalNodes]})
neighCounter=0
for neighborUID in ${neighborsArray[@]}; do
neighborsArray[$neighCounter]=${uidHostMap[${neighborUID}]}
neighCounter=$(( neighCounter+1 ))
done
neighbors=$(printf "_%s" "${neighborsArray[@]}")
echo "Neighbors ${neighbors}"
osascript -e '
tell app "Terminal"
do script "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no '$netid@$host' java -cp '$BINARY_DIR' '$PROGRAM' '$uid' '$host' '$port' '$neighbors'"
end tell'
i=$(( i + 1 ))
done
)