-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure.sh
More file actions
executable file
·219 lines (187 loc) · 5.13 KB
/
configure.sh
File metadata and controls
executable file
·219 lines (187 loc) · 5.13 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!/bin/bash
# Function to configure docker files
configure_docker() {
# Owner
cat docker/Dockerfile-base.txt > docker/Dockerfile.owner
cat <<EOL >> docker/Dockerfile.owner
ENTRYPOINT ["java", "-cp", "/app/resources/ntru-1.2.jar:/app/resources/ntrureencrypt-1.0.1.jar:/app/osre-1.0.1.jar", "nics.crypto.osre.MainOSREOwner", "$N", "$P", "$C", "$T", "172.28.0.2"]
EOL
# Device
cat docker/Dockerfile-base.txt > docker/Dockerfile.device
cat <<EOL >> docker/Dockerfile.device
ENTRYPOINT ["java", "-cp", "/app/resources/ntru-1.2.jar:/app/resources/ntrureencrypt-1.0.1.jar:/app/osre-1.0.1.jar", "nics.crypto.osre.MainOSREDevice", "$N", "$P", "$C", "$T", "172.28.0.3"]
EOL
# Proxy
cat docker/Dockerfile-base.txt > docker/Dockerfile.proxy
cat <<EOL >> docker/Dockerfile.proxy
ENTRYPOINT ["java", "-cp", "/app/resources/ntru-1.2.jar:/app/resources/ntrureencrypt-1.0.1.jar:/app/osre-1.0.1.jar", "nics.crypto.osre.MainOSREProxy", "$N", "$P", "$C", "$T", "172.28.0.4"]
EOL
# Holder
cat docker/Dockerfile-base.txt > docker/Dockerfile.holder
cat <<EOL >> docker/Dockerfile.holder
ENTRYPOINT ["java", "-cp", "/app/resources/ntru-1.2.jar:/app/resources/ntrureencrypt-1.0.1.jar:/app/osre-1.0.1.jar", "nics.crypto.osre.MainOSREHolder", "$N", "$P", "$C", "$T"]
CMD [""]
EOL
echo Dockerfiles correctly generated.
}
# Function to configure docker-compose file
configure_compose() {
REPLICAS=$N
PORT=$P
# Validate the number of replicas is a positive integer
if ! [[ "$REPLICAS" =~ ^[0-9]+$ ]] || [ "$REPLICAS" -le 0 ]; then
echo "The number of replicas must be a positive integer."
exit 1
fi
# Start the docker-compose.yml content
cat <<EOL > ./docker/docker-compose.yml
version: '3.8'
services:
osre-owner:
image: osre-owner
build:
context: ..
dockerfile: docker/Dockerfile.owner
networks:
osre_network:
ipv4_address: 172.28.0.2
ports:
- "$PORT"
volumes:
- log-data:/logs
depends_on:
- osre-device
osre-device:
image: osre-device
build:
context: ..
dockerfile: docker/Dockerfile.device
networks:
osre_network:
ipv4_address: 172.28.0.3
ports:
- "$PORT"
volumes:
- log-data:/logs
depends_on:
- osre-proxy
osre-proxy:
image: osre-proxy
build:
context: ..
dockerfile: docker/Dockerfile.proxy
networks:
osre_network:
ipv4_address: 172.28.0.4
ports:
- "$PORT"
volumes:
- log-data:/logs
depends_on:
EOL
for ((i=1; i<=REPLICAS; i++))
do
cat <<EOL >> ./docker/docker-compose.yml
- osre-holder_$i
EOL
done
# Loop to create each service
for ((i=1; i<=REPLICAS; i++))
do
IP_TAIL=$((10 + i))
IP="172.28.0.$IP_TAIL"
cat <<EOL >> ./docker/docker-compose.yml
osre-holder_$i:
image: osre-holder
container_name: osre-holder_$i
build:
context: ..
dockerfile: docker/Dockerfile.holder
networks:
osre_network:
ipv4_address: $IP
ports:
- "$PORT"
volumes:
- log-data:/logs
command: ["$IP"]
EOL
done
# Add the network definition
cat <<EOL >> ./docker/docker-compose.yml
networks:
osre_network:
driver: bridge
ipam:
config:
- subnet: 172.28.0.0/24
#name: osre_network
#external: true
volumes:
log-data:
external: true
EOL
echo "docker-compose.yml generated successfully with $REPLICAS replicas."
}
# Function to clear containers
clear_containers() {
echo "Clearing containers..."
docker rm -vf $(docker ps -aq)
docker rmi -f $(docker images -aq)
}
# Function to configure files
configure_files() {
echo "Configuring files..."
configure_docker
configure_compose
}
# Function to build files
build_files() {
echo "Building files..."
docker build -f ./docker/Dockerfile.owner -t osre-owner .
docker build -f ./docker/Dockerfile.device -t osre-device .
docker build -f ./docker/Dockerfile.proxy -t osre-proxy .
docker build -f ./docker/Dockerfile.holder -t osre-holder .
}
# Function to execute containers
execute_containers() {
echo "Executing containers with N=$1..."
docker compose -f docker/docker-compose.yml up --build
}
# Check if the correct number of arguments are provided
if [ "$#" -lt 5 ]; then
echo "Usage: $0 <number_of_replicas> <port> <number_of_ciphertexts> <threads> <options>"
echo "Options: -c (clear), -f (configure), -b (build), -e (execute)"
exit 1
fi
# Assign the first argument to N
N=$1
P=$2
C=$3
T=$4
# Shift the arguments to parse options
shift 4
# Loop through options and execute the corresponding tasks in the specified order
while getopts "cfbe" opt; do
case $opt in
c)
clear_containers
;;
f)
configure_files
;;
b)
build_files
;;
e)
execute_containers $N
;;
*)
echo "Invalid option: -$OPTARG" >&4
echo "Usage: $0 <number_of_replicas> <port> <number_of_ciphertexts> <threads> <options>"
echo "Options: -c (clear), -f (configure), -b (build), -e (execute)"
exit 1
;;
esac
done
echo "Tasks completed."