forked from mercure-imaging/mercure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·650 lines (590 loc) · 20.3 KB
/
install.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
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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
#!/bin/bash
set -euo pipefail
error() {
local parent_lineno="$1"
local code="${3:-1}"
echo "Error on or near line ${parent_lineno}"
exit "${code}"
}
trap 'error ${LINENO}' ERR
UBUNTU_VERSION=$(lsb_release -rs)
if [ $UBUNTU_VERSION != "20.04" ] && [ $UBUNTU_VERSION != "22.04" ] && [ $UBUNTU_VERSION != "24.04" ]; then
echo "Invalid operating system!"
echo "This mercure version requires Ubuntu 20.04 LTS, 22.04 LTS, or Ubuntu 24.04 LTS"
echo "Detected operating system = $UBUNTU_VERSION"
exit 1
fi
if [ ! -f "app/VERSION" ]; then
echo "Error: VERSION file missing. Unable to proceed."
exit 1
fi
VERSION=`cat app/VERSION`
IMAGE_TAG=":${MERCURE_TAG:-$VERSION}"
VER_LENGTH=${#VERSION}+28
echo ""
echo "mercure Installer - Version $VERSION"
for ((i=1;i<=VER_LENGTH;i++)); do
echo -n "="
done
echo ""
echo ""
OWNER=$USER
if [ $OWNER = "root" ]
then
OWNER=$(logname)
echo "Running as root, but setting $OWNER as owner."
fi
SECRET="${MERCURE_SECRET:-unset}"
if [ "$SECRET" = "unset" ]
then
SECRET=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1 || true)
fi
BOOKKEEPER_SECRET=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1 || true)
DB_PWD="${MERCURE_PASSWORD:-unset}"
if [ "$DB_PWD" = "unset" ]
then
DB_PWD=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1 || true)
fi
MERCURE_BASE=/opt/mercure
DATA_PATH=$MERCURE_BASE/data
CONFIG_PATH=$MERCURE_BASE/config
DB_PATH=$MERCURE_BASE/db
MERCURE_SRC=$(readlink -f .)
if [ -f "$CONFIG_PATH"/db.env ]; then
sudo chown $USER "$CONFIG_PATH"/db.env
source "$CONFIG_PATH"/db.env # Don't accidentally generate a new database password
sudo chown $OWNER "$CONFIG_PATH"/db.env
DB_PWD=$POSTGRES_PASSWORD
fi
echo "mercure installation folder: $MERCURE_BASE"
echo "Data folder: $DATA_PATH"
echo "Config folder: $CONFIG_PATH"
echo "Database folder: $DB_PATH"
echo "mercure source directory: $MERCURE_SRC"
echo ""
create_user () {
id -u mercure &>/dev/null || sudo useradd -ms /bin/bash mercure
OWNER=mercure
}
create_folder () {
for folder in "$@"; do
if [[ ! -e "$folder" ]]; then
echo "## Creating $folder"
sudo mkdir -p "$folder"
sudo chown "$OWNER:$OWNER" "$folder"
sudo chmod a+x "$folder"
else
echo "## $folder already exists."
fi
done
}
create_folders () {
create_folder $MERCURE_BASE $CONFIG_PATH
if [ $INSTALL_TYPE != "systemd" ]; then
create_folder $DB_PATH
fi
if [[ ! -e $DATA_PATH ]]; then
echo "## Creating $DATA_PATH..."
create_folder "$DATA_PATH"
local paths=("incoming" "studies" "outgoing" "success" "error" "discard" "jobs" "processing")
for path in "${paths[@]}"; do
create_folder "$DATA_PATH"/$path
done
sudo chown -R $OWNER:$OWNER $DATA_PATH
sudo chmod a+x $DATA_PATH
else
echo "## $DATA_PATH already exists."
fi
}
install_configuration () {
if [ ! -f "$CONFIG_PATH"/mercure.json ]; then
echo "## Copying configuration files..."
sudo chown $USER "$CONFIG_PATH"
cp "$MERCURE_SRC"/configuration/default_bookkeeper.env "$CONFIG_PATH"/bookkeeper.env
cp "$MERCURE_SRC"/configuration/default_mercure.json "$CONFIG_PATH"/mercure.json
cp "$MERCURE_SRC"/configuration/default_services.json "$CONFIG_PATH"/services.json
cp "$MERCURE_SRC"/configuration/default_webgui.env "$CONFIG_PATH"/webgui.env
echo "POSTGRES_PASSWORD=$DB_PWD" > "$CONFIG_PATH"/db.env
if [ $INSTALL_TYPE = "systemd" ]; then
sed -i -e "s/mercure:ChangePasswordHere@localhost/mercure:$DB_PWD@localhost/" "$CONFIG_PATH"/bookkeeper.env
elif [ $INSTALL_TYPE = "docker" ]; then
sed -i -e "s/mercure:ChangePasswordHere@localhost/mercure:$DB_PWD@db/" "$CONFIG_PATH"/bookkeeper.env
sed -i -e "s/0.0.0.0:8080/bookkeeper:8080/" "$CONFIG_PATH"/mercure.json
fi
sed -i -e "s/BOOKKEEPER_TOKEN_PLACEHOLDER/$BOOKKEEPER_SECRET/" "$CONFIG_PATH"/mercure.json
sed -i -e "s/PutSomethingRandomHere/$SECRET/" "$CONFIG_PATH"/webgui.env
sudo chown -R $OWNER:$OWNER "$CONFIG_PATH"
sudo chmod -R o-r "$CONFIG_PATH"
sudo chmod a+xr "$CONFIG_PATH"
fi
}
install_nomad () {
echo "Installing Nomad..."
NOMAD_VERSION=1.2.0
if [ ! -x "$(command -v unzip)" ]; then
sudo apt-get install -y unzip
fi
if [ ! -x "$(command -v nomad)" ]; then
curl -sSL https://releases.hashicorp.com/nomad/${NOMAD_VERSION}/nomad_${NOMAD_VERSION}_linux_amd64.zip -o /tmp/nomad.zip
unzip -o /tmp/nomad.zip -d /tmp
sudo install /tmp/nomad /usr/bin/nomad
nomad -autocomplete-install
fi
if [ ! -d /etc/nomad.d ]; then
sudo mkdir -p /etc/nomad.d
sudo chmod a+w /etc/nomad.d
fi
if [ ! -f "/etc/systemd/system/nomad.service" ]; then
(
cat <<-EOFB
[Unit]
Description=nomad
Requires=network-online.target
After=network-online.target
[Service]
Restart=on-failure
ExecStart=/usr/bin/nomad agent -bind 0.0.0.0 -log-level INFO -config /etc/nomad.d/
ExecReload=/bin/kill -HUP \$MAINPID
[Install]
WantedBy=multi-user.target
EOFB
) | sudo tee /etc/systemd/system/nomad.service
sudo systemctl enable nomad.service
sudo systemctl restart nomad.service
fi
if [ ! -x "$(command -v consul)" ]; then
echo "Installing Consul..."
CONSUL_VERSION=1.9.0
curl -sSL https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip -o /tmp/consul.zip
unzip -o /tmp/consul.zip -d /tmp
sudo install /tmp/consul /usr/bin/consul
fi
if [ ! -f "/etc/systemd/system/consul.service" ]; then
(
cat <<-EOFA
[Unit]
Description=consul agent
Requires=network-online.target
After=network-online.target
[Service]
Restart=on-failure
ExecStart=/usr/bin/consul agent -dev
ExecReload=/bin/kill -HUP \$MAINPID
[Install]
WantedBy=multi-user.target
EOFA
) | sudo tee /etc/systemd/system/consul.service
sudo systemctl enable consul.service
sudo systemctl restart consul
fi
sudo systemctl daemon-reload
for bin in cfssl cfssl-certinfo cfssljson
do
if [ ! -x "$(command -v $bin)" ]; then
echo "Installing $bin..."
curl -sSL https://pkg.cfssl.org/R1.2/${bin}_linux-amd64 -o /tmp/${bin}
sudo install /tmp/${bin} /usr/local/bin/${bin}
fi
done
if [ ! -d /opt/cni/bin ]; then
curl -L -o /tmp/cni-plugins.tgz https://github.com/containernetworking/plugins/releases/download/v0.9.1/cni-plugins-linux-amd64-v0.9.1.tgz
sudo mkdir -p /opt/cni/bin
sudo tar -C /opt/cni/bin -xzf /tmp/cni-plugins.tgz
fi
}
setup_nomad_keys() {
if [ ! -f "$MERCURE_BASE"/processor-keys/id_rsa ]; then
sudo mkdir "$MERCURE_BASE"/processor-keys/
echo "Generating SSH key..."
sudo ssh-keygen -t rsa -N '' -f /opt/mercure/processor-keys/id_rsa
sudo chown -R $OWNER:$OWNER "$MERCURE_BASE/processor-keys"
fi
}
setup_nomad() {
setup_nomad_keys
if [ ! -f "$MERCURE_BASE"/mercure.nomad ]; then
echo "## Copying mercure.nomad..."
sudo cp $MERCURE_SRC/nomad/mercure.nomad $MERCURE_BASE
sudo cp $MERCURE_SRC/nomad/mercure-ui.nomad $MERCURE_BASE
sudo cp $MERCURE_SRC/nomad/policies/anonymous-strict.policy.hcl $MERCURE_BASE
sudo sed -i "s#SSHPUBKEY#$(cat /opt/mercure/processor-keys/id_rsa.pub)#g" $MERCURE_BASE/mercure.nomad
sudo sed -i "s/\\\${IMAGE_TAG}/$IMAGE_TAG/g" $MERCURE_BASE/mercure.nomad
sudo sed -i "s/\\\${IMAGE_TAG}/$IMAGE_TAG/g" $MERCURE_BASE/mercure-ui.nomad
if [ ! -d $MERCURE_BASE/db ]; then
sudo mkdir $MERCURE_BASE/db
fi
sudo chown $OWNER:$OWNER "$MERCURE_BASE"/*
fi
sudo cp $MERCURE_SRC/nomad/server.hcl /etc/nomad.d
sudo cp $MERCURE_SRC/nomad/client.hcl /etc/nomad.d
sudo systemctl start nomad
echo "Waiting for Nomad to start..."
until [[ $(curl -q http://localhost:4646) ]];
do
echo -n "."
sleep 1s;
done;
if [ -z "${NOMAD_TOKEN:-}" ]; then
if [ ! -x "$(command -v jq)" ]; then
sudo apt-get install -y jq
fi
echo "NOMAD_TOKEN not set. Attempting to bootstrap Nomad ACL."
BOOTSTRAP_RESULT="$(nomad acl bootstrap -json || echo failed )"
if [[ "$BOOTSTRAP_RESULT" = "failed" ]]; then
echo "Warning: NOMAD_TOKEN is unset, and bootstrapping the ACL failed. Registering the jobs will likely fail."
else
new_secret_id="$(echo $BOOTSTRAP_RESULT | jq -r .SecretID)"
new_accessor_id="$(echo $BOOTSTRAP_RESULT | jq -r .AccessorID)"
echo NOMAD_TOKEN=$new_secret_id
export NOMAD_TOKEN=$new_secret_id
fi
fi
nomad acl policy apply -description "Mercure anonymous policy" anonymous $MERCURE_BASE/anonymous-strict.policy.hcl
nomad run -detach $MERCURE_BASE/mercure.nomad
nomad run -detach $MERCURE_BASE/mercure-ui.nomad
if [ ! -z "${BOOTSTRAP_RESULT:-}" ]; then
echo "Nomad ACL has been bootstrapped. Your managment key information follows. Keep this safe!"
echo $BOOTSTRAP_RESULT | jq
fi
}
install_docker () {
if [ ! -x "$(command -v docker)" ]; then
echo "## Installing Docker..."
sudo apt-get update
sudo apt-get remove docker docker-engine docker.io || true
echo '* libraries/restart-without-asking boolean true' | sudo debconf-set-selections
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common -y
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt-get update
sudo apt-get install -y docker-ce
# Restart docker to make sure we get the latest version of the daemon if there is an upgrade
sudo service docker restart
# Make sure we can actually use docker as the vagrant user
sudo usermod -a -G docker $OWNER
sudo docker --version
fi
if [ ! -x "$(command -v docker-compose)" ]; then
echo "## Installing Docker-Compose..."
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo docker-compose --version
fi
}
setup_docker () {
local overwrite=${1:-false}
if [ "$overwrite" = true ] || [ ! -f "$MERCURE_BASE"/docker-compose.yml ]; then
echo "## Copying docker-compose.yml..."
sudo cp $MERCURE_SRC/docker/docker-compose.yml $MERCURE_BASE
sudo sed -i -e "s/\\\${DOCKER_GID}/$(getent group docker | cut -d: -f3)/g" $MERCURE_BASE/docker-compose.yml
sudo sed -i -e "s/\\\${UID}/$(getent passwd mercure | cut -d: -f3)/g" $MERCURE_BASE/docker-compose.yml
sudo sed -i -e "s/\\\${GID}/$(getent passwd mercure | cut -d: -f4)/g" $MERCURE_BASE/docker-compose.yml
if [[ -v MERCURE_TAG ]]; then # a custom tag was provided
sudo sed -i "s/\\\${IMAGE_TAG}/\:$MERCURE_TAG/g" $MERCURE_BASE/docker-compose.yml
else
sudo sed -i "s/\\\${IMAGE_TAG}/$IMAGE_TAG/g" $MERCURE_BASE/docker-compose.yml
fi
sudo chown $OWNER:$OWNER "$MERCURE_BASE"/docker-compose.yml
fi
}
setup_docker_dev () {
if [ ! -f "$MERCURE_BASE"/docker-compose.override.yml ]; then
echo "## Copying docker-compose.override.yml..."
sudo cp $MERCURE_SRC/docker/docker-compose.override.yml $MERCURE_BASE
sudo sed -i -e "s;MERCURE_SRC;$(readlink -f $MERCURE_SRC)/app;" "$MERCURE_BASE"/docker-compose.override.yml
if [[ -v MERCURE_TAG ]]; then # a custom tag was provided
sudo sed -i "s/\\\${IMAGE_TAG}/\:$MERCURE_TAG/g" $MERCURE_BASE/docker-compose.override.yml
else # no custom tag was provided, use latest
sudo sed -i "s/\\\${IMAGE_TAG}/\:latest/g" $MERCURE_BASE/docker-compose.override.yml
fi
sudo chown $OWNER:$OWNER "$MERCURE_BASE"/docker-compose.override.yml
fi
}
build_docker () {
echo "## Building mercure docker containers..."
sudo $MERCURE_SRC/build-docker.sh -y
}
start_docker () {
echo "## Starting docker compose..."
pushd $MERCURE_BASE
sudo docker-compose up -d
popd
}
link_binaries() {
sudo find "$MERCURE_BASE/app/bin/ubuntu$UBUNTU_VERSION" -type f -exec ln -f -s {} "$MERCURE_BASE/app/bin" \;
}
install_app_files() {
local overwrite=${1:-false}
if [ $DO_DEV_INSTALL = true ]; then
if [ -e "$MERCURE_BASE"/app ]; then # app already exists
if [ -L "$MERCURE_BASE"/app ]; then # it's already linked somewhere
sudo unlink "$MERCURE_BASE"/app
else
read -p "App directory $MERCURE_BASE/app already exists. Delete and link to $MERCURE_SRC/app? " ANS
if [ "$ANS" != "y" ]; then
echo "Update aborted."
exit 1
fi
sudo rm -rf "$MERCURE_BASE"/app
fi
fi
echo "## Linking app files..."
sudo ln -s "$MERCURE_SRC/app" "$MERCURE_BASE"
sudo chown -h $OWNER:$OWNER ./app
link_binaries
sudo chmod g+w "$MERCURE_SRC/app"
# the mercure user and running user will be in each other's groups
sudo usermod -aG $OWNER $(logname)
sudo usermod -aG $(logname) $OWNER
return
fi
if [ "$overwrite" = true ] || [ ! -e "$MERCURE_BASE"/app ]; then
echo "## Installing app files..."
[ "$overwrite" = true ] || sudo mkdir "$MERCURE_BASE"/app
if [ ! "$MERCURE_SRC" -ef "$MERCURE_BASE"/app ]; then
sudo cp -R "$MERCURE_SRC/app" "$MERCURE_BASE"
fi
link_binaries
sudo chown -R $OWNER:$OWNER "$MERCURE_BASE/app"
fi
}
install_packages() {
echo "## Installing Linux packages..."
sudo apt-get update
sudo apt-get install -y build-essential wget git dcmtk jq inetutils-ping sshpass rsync postgresql postgresql-contrib libpq-dev git-lfs python3-wheel python3-dev python3 python3-venv sendmail libqt5core5a redis
if [ $UBUNTU_VERSION == "24.04" ]; then
sudo apt-get install -y libqt6core6t64
else
sudo apt-get install -y libqt5core5a
fi
}
install_dependencies() {
echo "## Installing Python runtime environment..."
if [ ! -e "$MERCURE_BASE/env" ]; then
sudo mkdir "$MERCURE_BASE/env" && sudo chown $USER "$MERCURE_BASE/env"
python3 -m venv "$MERCURE_BASE/env"
fi
echo "## Installing required Python packages..."
sudo chown -R $OWNER:$OWNER "$MERCURE_BASE/env"
sudo su $OWNER -c "$MERCURE_BASE/env/bin/pip install --isolated wheel~=0.37.1"
sudo su $OWNER -c "$MERCURE_BASE/env/bin/pip install --isolated -r \"$MERCURE_BASE/app/requirements.txt\""
}
install_postgres() {
echo "## Setting up postgres..."
sudo -u postgres -s <<- EOM
cd ~
createuser mercure
createdb mercure -O mercure
psql -c "ALTER USER mercure WITH PASSWORD '$DB_PWD';"
EOM
}
install_services() {
echo "## Installing services..."
sudo cp -n "$MERCURE_SRC"/installation/*.service /etc/systemd/system
sudo systemctl daemon-reload
sudo systemctl enable mercure_bookkeeper.service mercure_cleaner.service mercure_dispatcher.service mercure_receiver.service mercure_router.service mercure_ui.service mercure_processor.service
sudo systemctl restart mercure_bookkeeper.service mercure_cleaner.service mercure_dispatcher.service mercure_receiver.service mercure_router.service mercure_ui.service mercure_processor.service
}
systemd_install () {
echo "## Performing systemd-type mercure installation..."
create_user
create_folders
install_configuration
sudo cp -n "$MERCURE_SRC"/installation/sudoers/* /etc/sudoers.d/
install_packages
install_docker
install_app_files
install_dependencies
install_postgres
sudo chown -R mercure:mercure "$MERCURE_BASE"
install_services
}
docker_install () {
echo "## Performing docker-type mercure installation..."
create_user
create_folders
install_configuration
install_docker
if [ $DOCKER_BUILD = true ]; then
build_docker
fi
setup_docker
if [ $DO_DEV_INSTALL = true ]; then
setup_docker_dev
fi
start_docker
}
nomad_install () {
create_folders
install_app_files
install_configuration
install_docker
install_nomad
setup_nomad
}
systemd_update () {
if [ ! -d $MERCURE_BASE/app ]; then
echo "ERROR: $MERCURE_BASE/app does not exist; is Mercure installed?"
exit 1
fi
local OLD_VERSION=`cat $MERCURE_BASE/app/VERSION`
if [ $FORCE_INSTALL != "y" ]; then
echo "Update mercure from $OLD_VERSION to $VERSION (y/n)?"
read -p "WARNING: Server may require manual fixes after update. Taking backups beforehand is recommended. " ANS
if [ "$ANS" != "y" ]; then
echo "Update aborted."
exit 0
fi
fi
echo "Updating mercure..."
local services=("ui" "receiver" "bookkeeper" "dispatcher" "cleaner" "bookkeeper" )
for service in "${services[@]}"; do
if systemctl is-active --quiet mercure_$service.service; then
echo "ERROR: mercure_$service.service is running. Stop mercure first."
exit 1
fi
done
create_folders
install_app_files true
sudo cp -n "$MERCURE_SRC"/installation/sudoers/* /etc/sudoers.d/
install_packages
install_dependencies
install_services
echo "Update complete."
}
docker_update () {
if [ ! -f $MERCURE_BASE/docker-compose.yml ]; then
echo "ERROR: $MERCURE_BASE/docker-compose.yml does not exist; is Mercure installed?"
exit 1
fi
if [ -f $MERCURE_BASE/docker-compose.override.yml ]; then
echo "ERROR: $MERCURE_BASE/docker-compose.override.yml exists. Updating a dev install is not supported."
exit 1
fi
if [ $FORCE_INSTALL != "y" ]; then
echo "Update mercure to ${MERCURE_TAG:-VERSION} (y/n)?"
read -p "WARNING: Server may require manual fixes after update. Taking backups beforehand is recommended. " ANS
if [ "$ANS" != "y" ]; then
echo "Update aborted."
exit 0
fi
fi
# sudo sed -E "s/(image\: mercureimaging.*?\:).*/\1foo/g" docker-compose.yml
pushd $MERCURE_BASE
sudo docker-compose down || true
popd
setup_docker true
start_docker
}
FORCE_INSTALL="n"
while getopts ":hy" opt; do
case ${opt} in
h )
echo "Usage:"
echo " install.sh -h Display this help message."
echo " install.sh [-y] docker [-dbu] Install with docker-compose."
echo " install.sh [-y] systemd [-d] Install as systemd service."
echo " install.sh [-y] nomad Install as nomad job."
echo " Options: "
echo " -d Development mode"
echo " systemd:"
echo " -u Update"
echo " docker:"
echo " -b Build containers"
exit 0
;;
y )
FORCE_INSTALL="y"
;;
\? )
echo "Invalid Option: -$OPTARG" 1>&2
exit 1
;;
: )
echo "Invalid Option: -$OPTARG requires an argument" 1>&2
exit 1
;;
esac
done
shift $((OPTIND -1))
OPTIND=1
INSTALL_TYPE="${1:-docker}"
if [[ $# > 0 ]]; then shift; fi
DO_DEV_INSTALL=false
DOCKER_BUILD=false
DO_OPERATION="install"
INSTALL_ORTHANC=false
while getopts ":dbuo" opt; do
case ${opt} in
o )
INSTALL_ORTHANC=true
;;
u )
DO_OPERATION="update"
;;
d )
DO_DEV_INSTALL=true
;;
b )
if [ $INSTALL_TYPE != "docker" ]; then
echo "Invalid option for \"$INSTALL_TYPE\": -b" 1>&2
fi
DOCKER_BUILD=true
;;
\? )
echo "Invalid Option for \"$INSTALL_TYPE\": -$OPTARG" 1>&2
exit 1
;;
esac
done
if [ $DO_DEV_INSTALL == true ] && [ $DO_OPERATION == "update" ]; then
echo "Invalid option: cannot update a dev installation" 1>&2
exit 1
fi
if [ $INSTALL_TYPE == "systemd" ] && [ $DO_OPERATION == "update" ]; then
systemd_update
exit 0
elif [ $INSTALL_TYPE == "docker" ] && [ $DO_OPERATION == "update" ]; then
docker_update
exit 0
fi
if [ $FORCE_INSTALL = "y" ]; then
echo "Forcing installation"
else
read -p "Install with $INSTALL_TYPE (y/n)? " ANS
if [ "$ANS" = "y" ]; then
echo "Installing mercure..."
else
echo "Installation aborted."
exit 0
fi
fi
case "$INSTALL_TYPE" in
systemd )
systemd_install
;;
docker )
docker_install
;;
nomad )
nomad_install
;;
* )
echo "Error: unrecognized option $INSTALL_TYPE"
exit 1
;;
esac
if [ $INSTALL_ORTHANC == true ]; then
echo "Installing Orthanc..."
pushd addons/orthanc
sudo docker network create mercure_default || true
sudo docker-compose up -d
popd
fi
echo "Installation complete"