-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·73 lines (61 loc) · 1.54 KB
/
deploy.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
#!/bin/bash
# place where the directories of this script created
# safety: don't erase a other directory
DIR="$HOME/shared_filesystem"
# N server machine(s)
N=4
# M client machine(s)
M=0
# P number of ports by machine
P=3
# parameters of config file
CONFIG_FILE_SERVER="server/config.txt"
CONFIG_FILE_CLIENT="client/config.txt"
# free port from 1024 to 65535
NP=1024
### FUNCTION ###
# line format in this file
# config file server
# idServer address buddyPort clientPort serverPort
declare -a client_ports
function create_config_file_server {
for i in $(seq 0 $((N-1))); do
echo -n "$i 127.0.0.1 "
for j in $(seq 0 $((P-1))); do
if [ $j -eq 1 ]; then
client_ports[$i]=$NP;
fi
echo -n "$NP "
((NP++))
done
echo
done
}
# line format in this file
# config file server
# idServer address clientPort
function create_config_file_client {
for i in $(seq 0 $((N-1))); do
echo "$i 127.0.0.1 ${client_ports[$i]}"
done
}
### SCRIPT ###
# create the config files
echo Generating config file...
create_config_file_server > "$CONFIG_FILE_SERVER"
create_config_file_client > "$CONFIG_FILE_CLIENT"
echo Generating config file...DONE
if [ ! -e "$DIR" ]; then
mkdir "$DIR"
fi
echo "$N server(s) to deploy"
echo Deploying servers...
# deploy the server
for i in $(seq 0 $((N-1))); do
DEST="$DIR"/server"$i"
mkdir -p "$DEST"
cp -r server/dist/* "$DEST"/
cp server/config.txt "$DEST"/
done
echo Deploying servers...DONE
exit 0