-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstaller.sh
More file actions
executable file
·403 lines (383 loc) · 11.7 KB
/
installer.sh
File metadata and controls
executable file
·403 lines (383 loc) · 11.7 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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
#!/bin/bash
##H Usage: installer.sh [install_dir|help]
##H
##H For more details please refer to documentation page:
##H https://github.com/CHESSComputing/FOXDEN/blob/main/docs/main.md
#
ME=$(basename $(dirname $0))
ROOT=$(cd $(dirname $0) && pwd)
if [ "$#" -eq 1 ]; then
echo "new root"
ROOT=$1
fi
LOG_DIR=$ROOT/logs
FOXDEN_DIR=$ROOT
HOST=`hostname -s`
mkdir -p $LOG_DIR
mkdir -p $FOXDEN_DIR/configs
mkdir -p $FOXDEN_DIR/databases
echo "FOXDEN root : $FOXDEN_DIR"
echo "FOXDEN configs : $FOXDEN_DIR/configs"
echo "FOXDEN databases: $FOXDEN_DIR/databases"
echo "LOG_DIR : $LOG_DIR"
services="Authz MetaData UserMetaData DataDiscovery DataBookkeeping Frontend SyncService DOIService"
# checks performs checks over used directories and env variables
checks()
{
if ! command -v curl &> /dev/null
then
echo "curl could not be found, please install `curl` command and setup PATH to find it"
exit 1
fi
}
# helper function to download services
download_services()
{
echo
echo "### Download services..."
mkdir -p releases
if [ -f RELEASES.md ]; then
rm -f RELEASES.md
fi
touch RELEASES.md
# loop over services and download latest tar balls
for srv in $services
do
echo "Checking $srv service..."
repo="CHESSComputing/$srv"
tag=$(curl -s "https://api.github.com/repos/$repo/releases/latest" | grep "tag_name" | cut -d '"' -f 4)
dsrv=$(echo "$srv" | tr '[:upper:]' '[:lower:]')
url="https://github.com/$repo/releases/download/$tag/$dsrv.tar.gz"
if [ -z "$tag" ]; then
echo "Unable to determine latest tag for service $srv, skip it..."
continue
fi
printf "%-25s\t%s\n" $srv $tag >> RELEASES.md
if [ -f releases/$srv/$tag/srv ]; then
echo " Service executable releases/$srv/$tag/srv already exists..."
else
echo " Download: $url"
curl -s -L -o $srv.tar.gz $url
mkdir -p releases/$srv/$tag
tar -xf $srv.tar.gz -C releases/$srv/$tag
cd releases/$srv/$tag
make_symlink
cd -
fi
done
}
# helper function to create appropriate symlink based on host architecture
make_symlink()
{
# Detect platform and architecture
OS="$(uname -s)"
ARCH="$(uname -m)"
# Determine the appropriate executable based on the system architecture
case "$OS-$ARCH" in
Linux-x86_64)
TARGET="srv_amd64"
;;
Linux-arm64 | Linux-aarch64)
TARGET="srv_arm64"
;;
Darwin-x86_64)
TARGET="srv_darwin_amd64"
;;
Darwin-arm64)
TARGET="srv_darwin_arm64"
;;
Linux-ppc64 | Linux-ppc64le)
TARGET="srv_power8"
;;
MINGW64_NT-*)
TARGET="srv_amd64.exe"
;;
MINGW32_NT-*)
TARGET="srv_amd64.exe"
;;
*)
echo "Unsupported OS or architecture: $OS-$ARCH"
exit 1
;;
esac
# Create a symlink named 'srv' pointing to the appropriate executable
ln -sf "$TARGET" srv
echo "Symlink created: srv -> $TARGET"
}
# helper function to download configs
download_configs()
{
echo
echo "### Download FOXDEN configs..."
files="ID1A3.json ID3A.json ID4B.json PIP.json service_map_file.json metadata_lexicon.json web_form_sections.json dbs_parameters.json dbs_lexicon.json"
mkdir -p $FOXDEN_DIR/configs
cd $FOXDEN_DIR/configs
for f in $files
do
if [ ! -f $f ]; then
echo "Download: $f"
curl -ksLO https://raw.githubusercontent.com/CHESSComputing/FOXDEN/refs/heads/main/configs/$f
fi
done
cd -
}
# helper function to download scripts
download_scripts()
{
echo
echo "### Download scripts..."
mkdir -p $FOXDEN_DIR/scripts
curl -ksLO https://raw.githubusercontent.com/CHESSComputing/scripts/refs/heads/main/manage
chmod +x manage
# adjust manage script to run only subset of services
sed -i "s/^services=.*$/services=\"$services\"/" manage
mv manage $FOXDEN_DIR/scripts
}
# helper function to create FOXDEN config
make_config()
{
echo
echo "Setup FOXDEN configuration: $FOXDEN_DIR/foxden.yaml"
cat > $FOXDEN_DIR/foxden.yaml << EOF
Services:
FrontendUrl: http://localhost:8344
DiscoveryUrl: http://localhost:8320
DataManagementUrl: http://localhost:8340
DataBookkeepingUrl: http://localhost:8310
MetaDataUrl: http://localhost:8300
AuthzUrl: http://localhost:8380
SpecScansUrl: http://localhost:8390
MLHubUrl: http://localhost:8350
DOIServiceUrl: http://localhost:8377
SyncServiceUrl: http://localhost:8388
CHAPBookUrl: https://chapbook.classe.cornell.edu:8181
Kerberos:
Realm: CLASSE.CORNELL.EDU
Krb5Conf: /etc/krb5.conf
Encryption:
Cipher: aes
Secret: bla
DID:
Attributes: "beamline,btr,cycle,sample"
Separator: "/"
Divider: "="
QL:
ServiceMapFile: $FOXDEN_DIR/configs/service_map_file.json
CHESSMetaData:
LexiconFile: $FOXDEN_DIR/configs/metadata_lexicon.json
SchemaRenewInterval: 3600
SchemaFiles:
- "$FOXDEN_DIR/configs/ID4B.json"
- "$FOXDEN_DIR/configs/ID3A.json"
- "$FOXDEN_DIR/configs/ID1A3.json"
- "$FOXDEN_DIR/configs/PIP.json"
SkipKeys: ["user", "date", "description", "schema_name", "schema_file", "schema", "did", "doi", "doi_url"]
WebSections: $FOXDEN_DIR/configs/web_form_sections.json
OrderedSections: ["User", "Alignment", "DataLocations", "Beam", "Experiment", "Sample"]
MongoDB:
DBUri: mongodb://localhost:27017
DBName: foxden
DBColl: meta
WebServer:
Port: 8300
LogFile: $LOG_DIR/Metadata.log
LogLongFile: true
Authz:
CheckLDAP: true
DBUri: $FOXDEN_DIR/databases/auth.db
ClientId: client_id
ClientSecret: client_secret
WebServer:
Port: 8380
LogFile: $LOG_DIR/Authz.log
LogLongFile: true
DataBookkeeping:
ApiParametersFile: $FOXDEN_DIR/configs/dbs_parameters.json
DBFile: $FOXDEN_DIR/databases/dbs_dbfile
LexiconFile: $FOXDEN_DIR/configs/dbs_lexicon.json
WebServer:
Port: 8310
StaticDir: $FOXDEN/DataBookkeeping/static
LogFile: $LOG_DIR/DataBookkeeping.log
LogLongFile: true
Discovery:
MongoDB:
DBUri: mongodb://localhost:27017
DBName: foxden
DBColl: meta
WebServer:
Port: 8320
LogFile: $LOG_DIR/DataDiscovery.log
LogLongFile: true
Frontend:
CheckBtrs: true
CheckAdmins: true
AllowAllRecords: false
TestMode: false
WebServer:
Port: 8344
StaticDir: $FOXDEN_DIR/Frontend/static
LogFile: $LOG_DIR/Frontend.log
LogLongFile: true
MetaData:
MongoDB:
DBUri: mongodb://localhost:8230
DBName: foxden
DBColl: meta
WebServer:
Port: 8300
LogFile: $LOG_DIR/MetaData.log
LogLongFile: true
DOIService:
WebServer:
Port: 8377
LogFile: $LOG_DIR/DOIService.log
LogLongFile: true
SyncService:
MongoDB:
DBUri: mongodb://localhost:8230
DBName: foxden
DBColl: sync
WebServer:
Port: 8388
LogFile: $LOG_DIR/SyncService.log
LogLongFile: true
EOF
}
# helper function to cleanup
cleanup()
{
echo
echo "### Perform cleanup procedure"
for srv in $services
do
if [ -f $srv.tar.gz ]; then
rm -f $srv.tar.gz
fi
dsrv=$(echo "$srv" | tr '[:upper:]' '[:lower:]')
if [ -f $dsrv.tar.gz ]; then
rm -f $dsrv.tar.gz
fi
done
}
# Function to determine the Linux distribution
get_linux_flavor() {
if [ -f /etc/os-release ]; then
. /etc/os-release
echo "${ID}${VERSION_ID}" # Prints a result like "debian12", "rhel8", etc.
elif [ -f /etc/redhat-release ]; then
# Specific handling for RedHat-based systems
awk '{print tolower($1) $3}' /etc/redhat-release
elif [ -f /etc/lsb-release ]; then
# For older Debian/Ubuntu systems
. /etc/lsb-release
echo "${DISTRIB_ID,,}${DISTRIB_RELEASE}"
else
echo "Unknown Linux flavor"
fi
}
# helper function to setup databases
setup_databases()
{
curl -ksL -o $FOXDEN_DIR/databases/auth-sqlite-schema.sql \
https://raw.githubusercontent.com/CHESSComputing/Authz/refs/heads/main/static/schema/sqlite-schema.sql
curl -ksL -o $FOXDEN_DIR/databases/dbs-sqlite-schema.sql \
https://raw.githubusercontent.com/CHESSComputing/DataBookkeeping/refs/heads/main/static/schema/sqlite.sql
# download schemas
cat > $FOXDEN_DIR/databases/dbs_dbfile << EOF
sqlite3 $FOXDEN_DIR/databases/dbs.db sqlite
EOF
# initialize databases
sqlite3 $FOXDEN_DIR/databases/auth.db < $FOXDEN_DIR/databases/auth-sqlite-schema.sql
sqlite3 $FOXDEN_DIR/databases/dbs.db < $FOXDEN_DIR/databases/dbs-sqlite-schema.sql
}
download_databases()
{
# Detect platform and architecture
OS="$(uname -s)"
ARCH="$(uname -m)"
echo
echo "### setup databases..."
if ! command -v sqlite3 &> /dev/null
then
echo
echo " download SQliteDB..."
case "$OS" in
Linux)
curl -ksLO https://www.sqlite.org/2024/sqlite-tools-linux-x64-3470000.zip
;;
Darwin)
curl -ksLO https://www.sqlite.org/2024/sqlite-tools-osx-x64-3470000.zip
;;
MINGW64_NT | MINGW32_NT )
curl -ksLO https://www.sqlite.org/2024/sqlite-tools-win-x64-3470000.zip
;;
*)
echo "Unsupported OS: $OS"
exit 1
;;
esac
fi
echo
echo " download MongoDB..."
# Determine the appropriate executable based on the system architecture
case "$OS-$ARCH" in
Linux-x86_64)
linux_flavor=$(get_linux_flavor)
case "$linux_flagor" in
debian12)
curl -ksLO https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian12-8.0.3.tgz
;;
rhel8)
curl -ksLO https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel8-8.0.3.tgz
;;
rhel93)
curl -ksLO https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel93-8.0.3.tgz
;;
suse15)
curl -ksLO https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-suse15-8.0.3.tgz
;;
ubuntu2004)
curl -ksLO https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2004-8.0.3.tgz
;;
esac
;;
Linux-arm64 | Linux-aarch64)
https://fastdl.mongodb.org/linux/mongodb-linux-aarch64-rhel8-8.0.3.tgz
https://fastdl.mongodb.org/linux/mongodb-linux-aarch64-rhel93-8.0.3.tgz
https://fastdl.mongodb.org/linux/mongodb-linux-aarch64-ubuntu2004-8.0.3.tgz
;;
Darwin-x86_64)
TARGET="srv_darwin_amd64"
curl -ksLO https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-8.0.3.tgz
;;
Darwin-arm64)
curl -ksLO https://fastdl.mongodb.org/osx/mongodb-macos-arm64-8.0.3.tgz
;;
MINGW64_NT-* | MINGW32_NT-*)
TARGET="srv_amd64.exe"
curl -ksLO https://fastdl.mongodb.org/windows/mongodb-windows-x86_64-8.0.3.zip
;;
*)
echo "Unsupported OS or architecture: $OS-$ARCH"
exit 1
;;
esac
}
foxden_usage()
{
echo
echo "### FOXDEN services are ready..."
echo " Configuration file: $FOXDEN_DIR/foxden.yaml"
echo " To start services : $FOXDEN_DIR/scripts/manage start"
echo " To stop services : $FOXDEN_DIR/scripts/manage stop"
echo " To check status : $FOXDEN_DIR/scripts/manage status"
}
checks
download_services
download_configs
download_scripts
make_config
setup_databases
cleanup
foxden_usage