-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathrun-teaclave-services.sh
executable file
·223 lines (206 loc) · 5.65 KB
/
run-teaclave-services.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
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
220
221
222
223
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
SGX_DEV_SEL="none"
AESM_SEL="none"
function sgx_dev_detect() {
local ISGX_DEV=/dev/isgx
local ISGX_DEV_EXIST=false
if [ -c "$ISGX_DEV" ]; then
echo "$ISGX_DEV device detected."
ISGX_DEV_EXIST=true
fi
local ENCL_DEV=/dev/sgx/enclave
local ENCL_DEV_EXIST=false
if [ -L "$ENCL_DEV" ] && [ -c $(realpath $ENCL_DEV) ]; then
echo "$ENCL_DEV device detected."
ENCL_DEV_EXIST=true
fi
local PROV_DEV=/dev/sgx/provision
local PROV_DEV_EXIST=false
if [ -L "$PROV_DEV" ] && [ -c $(realpath $PROV_DEV) ]; then
echo "$PROV_DEV device detected."
PROV_DEV_EXIST=true
fi
if ($ISGX_DEV_EXIST && $ENCL_DEV_EXIST && $PROV_DEV_EXIST); then
PS3='Please enter your choice: '
options=("ISGX device" "DCAP device" "Quit")
select opt in "${options[@]}"
do
case $opt in
"ISGX device")
echo "you chose $opt"
SGX_DEV_SEL="isgx"
break
;;
"DCAP device")
echo "you chose $opt"
SGX_DEV_SEL="dcap"
break
;;
"Quit")
exit 1
;;
*) echo "invalid option $REPLY" ;;
esac
done
else
if $ISGX_DEV_EXIST; then
SGX_DEV_SEL="isgx"
fi
if ($ENCL_DEV_EXIST && $PROV_DEV_EXIST); then
SGX_DEV_SEL="dcap"
fi
fi
}
function aesm_detect() {
local AESM_SOCK=/var/run/aesmd/aesm.socket
local AESM_SOCK_EXIST=false
if [ -S "$AESM_SOCK" ]; then
echo "$AESM_SOCK socket detected."
AESM_SOCK_EXIST=true
fi
local AESM_VOL=aesmd-socket
local AESM_VOL_EXIST=false
if docker volume inspect $AESM_VOL > /dev/null 2>&1; then
echo "$AESM_VOL volume detected."
AESM_VOL_EXIST=true
fi
if ($AESM_SOCK_EXIST && $AESM_VOL_EXIST); then
PS3='Please enter your choice: '
options=("$AESM_SOCK socket" "$AESM_VOL volume" "Quit")
select opt in "${options[@]}"
do
case $opt in
"$AESM_SOCK socket")
echo "you chose $opt"
AESM_SEL="sock"
break
;;
"$AESM_VOL volume")
echo "you chose $opt"
AESM_SEL="vol"
break
;;
"Quit")
exit 1
;;
*) echo "invalid option $REPLY" ;;
esac
done
else
if $AESM_SOCK_EXIST; then
AESM_SEL="sock"
fi
if $AESM_VOL_EXIST; then
AESM_SEL="vol"
fi
fi
}
function usage {
echo "Usage: $(basename $0) [-hdbm:]" 2>&1
echo ' -h shows usage'
echo ' -m run mode (default: sgx)'
echo ' -d detached mode'
echo ' -b build or rebuild services'
echo 'Available run modes: sim, sgx'
exit 1
}
RUN_MODE="sgx"
DETACH_ARG=""
optstring="hdbm:"
while getopts ${optstring} arg; do
case ${arg} in
h)
echo "showing usage!"
usage
;;
d)
DETACH_ARG="-d"
;;
b)
BUILD_ARG="--build"
;;
m)
RUN_MODE=$OPTARG
;;
esac
done
shift $((OPTIND-1))
case $RUN_MODE in
"sgx")
sgx_dev_detect
aesm_detect
;;
"sim")
;;
*)
echo "The specified run mode: $RUN_MODE is not recognized."
usage
;;
esac
OV_PREFIX="docker-compose-"
OV_SUFFIX=".override.yml"
SGX_DEV_OV_FILE=""
AESM_OV_FILE=""
case $SGX_DEV_SEL in
"isgx")
SGX_DEV_OV_FILE="isgx-dev"
;;
"dcap")
SGX_DEV_OV_FILE="dcap-dev"
;;
"none")
;;
*)
echo "Invalid SGX device."
exit 2
;;
esac
SGX_DEV_OV_FILE="${OV_PREFIX}${SGX_DEV_OV_FILE}${OV_SUFFIX}"
case $AESM_SEL in
"sock")
AESM_OV_FILE="aesm-socket"
;;
"vol")
AESM_OV_FILE="aesm-vol"
;;
"none")
;;
*)
echo "Invalid AESM service."
exit 2
;;
esac
AESM_OV_FILE="${OV_PREFIX}${AESM_OV_FILE}${OV_SUFFIX}"
DOCKER_COMPOSE_FILE="docker-compose-ubuntu-1804.yml"
DC_ARGS=""
if [ "$RUN_MODE" == "sgx" ]; then
if [ "$SGX_DEV_SEL" == "none" ]; then
echo "Cannot find a valid sgx device."
exit 3
fi
if [ "$AESM_SEL" == "none" ]; then
echo "Cannot find a valid aesm service."
exit 6
fi
DC_ARGS="-f $DOCKER_COMPOSE_FILE -f $SGX_DEV_OV_FILE -f $AESM_OV_FILE"
else
DC_ARGS="-f $DOCKER_COMPOSE_FILE"
fi
echo COMMAND: docker-compose ${DC_ARGS} up ${DETACH_ARG} ${BUILD_ARG}
docker-compose ${DC_ARGS} up ${DETACH_ARG} ${BUILD_ARG}