-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathinstall_sct
executable file
·705 lines (626 loc) · 22.8 KB
/
install_sct
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
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
#!/usr/bin/env bash
#
# This is the spinalcord toolbox (SCT) installer
# It downloads the Conda (http://conda.pydata.org/) version
# of python and installs the SCT requirements over it
#
# The SCT can be installed in the location where you download it. If you choose to do so,
# do not delete the source code or you will delete the installation too!
#
# If you run the installer as super user, the default install is /opt,
# if you choose this option or any other directory other than the
# source location, you can get rid of the source code after the
# installation is successful.
#
# USAGE
# ./install_sct [-h] [-i] [-y] [-d] [-b] [-v]
#
# OPTIONS
# -h Show this help
# -i Install in-place; this is the default when working from git.
# -y Install without interruption with 'yes' as default answer
# -d Prevent the (re)-installation of the data/ directory
# -b Prevent the (re)-installation of the SCT binaries files
# -v Full verbose
#
#
# Copyright (c) 2019 Polytechnique Montreal <www.neuro.polymtl.ca>
# Authors: PO Quirion, J Cohen-Adad, J Carretero
# License: see the file LICENSE.TXT
# stricter shell mode
# https://sipb.mit.edu/doc/safe-shell/
set -eo pipefail # exit if non-zero error is encountered (even in a pipeline)
set -u # exit if unset variables used
shopt -s failglob # error if a glob doesn't find any files, instead of remaining unexpanded
# set -v # v: verbose
# Where tmp file are stored
TMP_DIR="$(mktemp -d 2>/dev/null || mktemp -d -t 'TMP_DIR')"
# Start Directory So we go back there at the end of the Script
SCT_SOURCE="$PWD"
DATA_DIR="data"
PYTHON_DIR="python"
BIN_DIR="bin"
MACOSSUPPORTED="13" # Minimum version of macOS 10 supported
# CLI options
SCT_INSTALL_TYPE=""
NONINTERACTIVE=""
NO_DATA_INSTALL=""
NO_SCT_BIN_INSTALL=""
# ======================================================================================================================
# FUNCTIONS
# ======================================================================================================================
# Print with color
# @input1: {info, code, error}: type of text
# rest of inputs: text to print
function print() {
type=$1; shift
case "$type" in
# Display useful info (green)
info)
echo -e "\n\033[0;32m${*}\033[0m\n"
;;
# To interact with user (no carriage return) (light green)
question)
echo -e -n "\n\033[0;92m${*}\033[0m"
;;
# To display code that is being run in the Terminal (blue)
code)
echo -e "\n\033[0;34m${*}\033[0m\n"
;;
# Warning message (yellow)
warning)
echo -e "\n\033[0;93m${*}\033[0m\n"
;;
# Error message (red)
error)
echo -e "\n\033[0;31m${*}\033[0m\n"
;;
esac
}
# Elegant exit with colored message
function die() {
print error "$1"
exit 1
}
# Run a command and display it in color. Exit if error.
# @input: string: command to run
function run() {
( # this subshell means the 'die' only kills this function and not the whole script;
# the caller can decide what to do instead (but with set -e that usually means terminating the whole script)
print code "$@"
if ! "$@" ; then
die "ERROR: Command failed."
fi
)
}
# Force a clean exit
function finish() {
# Catch the last return code
value="$?"
# Get back to starting point
cd "$SCT_SOURCE"
if [[ "$value" -eq 0 ]]; then
print info "Installation finished successfully!"
elif [[ "$value" -eq 99 ]]; then
# Showing usage with -h
echo ""
else
print error "Installation failed!\n
Please copy the output of this Terminal (starting with the command install_sct) and upload it as a .txt attachment in a new topic on SCT's forum:\n
--> http://forum.spinalcordmri.org/c/sct"
fi
# clean tmp_dir
rm -rf "$TMP_DIR"
exit "$value"
}
# reenable tty echo when user presses keyboard interrupt and output non-zero status for finish() function
detectKeyboardInterrupt() {
# reenable tty echo
print error "Installation aborted by the user."
stty icanon echo echok
exit 1
}
# Fetches the OS type
# @output: OS var is modified with the appropriate OS
function fetch_os_type() {
print info "Checking OS type and version..."
OSver="unknown" # default value
uname_output="$(uname -a)"
echo "$uname_output"
# macOS
if echo "$uname_output" | grep -i darwin >/dev/null 2>&1; then
# Fetch macOS version
sw_vers_output="$(sw_vers | grep -e ProductVersion)"
echo "$sw_vers_output"
OSver="$(echo "$sw_vers_output" | cut -c 17-)"
macOSmajor="$(echo "$OSver" | cut -f 1 -d '.')"
macOSminor="$(echo "$OSver" | cut -f 2 -d '.')"
# Make sure OSver is supported
if [[ "${macOSmajor}" = 10 ]] && [[ "${macOSminor}" < "${MACOSSUPPORTED}" ]]; then
die "Sorry, this version of macOS (10.$macOSminor) is not supported. The minimum version is 10.$MACOSSUPPORTED."
fi
# Fix for non-English Unicode systems on MAC
if [[ -z "${LC_ALL:-}" ]]; then
export LC_ALL=en_US.UTF-8
fi
if [[ -z "${LANG:-}" ]]; then
export LANG=en_US.UTF-8
fi
OS="osx"
# make sure bashrc is loaded when starting a new Terminal
force_bashrc_loading
# Linux
elif echo "$uname_output" | grep -i linux >/dev/null 2>&1; then
OS="linux"
else
die "Sorry, the installer only supports Linux and macOS, quitting installer"
fi
}
# Checks if the necessary tools for SCT are installed on the machine
function check_requirements() {
print info "Checking requirements..."
# check curl
if [[ ! ( $(command -v curl) || $(command -v wget) ) ]]; then
die "ERROR: neither \"curl\" nor \"wget\" is installed. Please install either of them and restart SCT installation."
fi
# check gcc
if ! gcc --version > /dev/null 2>&1; then
print warning "WARNING: \"gcc\" is not installed."
if [[ "$OS" == "osx" ]]; then
while [[ ! "$GCC_INSTALL" =~ ^([Yy](es)?|[Nn]o?)$ ]]; do
GCC_INSTALL="no"
if [ -z "$NONINTERACTIVE" ]; then
print question "Do you want to install it now? (accepting to install \"gcc\" will also install \"brew\" in case it is not installed already)? [y]es/[n]o: "
read -r GCC_INSTALL
fi
done
if [[ "$GCC_INSTALL" =~ [Yy](es)? ]]; then
if [[ ! $(command -v brew) ]]; then
# NB: this is a different NONINTERACTIVE than ours above; it's for the brew installer
(NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)")
fi
brew install -f gcc
# check if gcc install ran properly
if ! gcc --version > /dev/null 2>&1; then
die "ERROR: Installation of \"gcc\" failed. Please contact SCT team for assistance."
fi
else
die "Please install \"gcc\" and restart SCT installation."
fi
else
die "Please install \"gcc\" and restart SCT installation. On Debian/Ubuntu, run: \"apt install gcc\". On CentOS/RedHat, run: \"yum -y install gcc\"."
fi
fi
print info "OK!"
}
# Gets the shell rc file path based on the default shell.
# @output: THE_RC and RC_FILE_PATH vars are modified
function get_shell_rc_path() {
if [[ "$SHELL" == *"bash"* ]]; then
THE_RC="bash"
RC_FILE_PATH="$HOME/.bashrc"
elif [[ "$SHELL" == *"/sh"* ]]; then
THE_RC="bash"
RC_FILE_PATH="$HOME/.bashrc"
elif [[ "$SHELL" == *"zsh"* ]]; then
THE_RC="bash"
RC_FILE_PATH="$HOME/.zshrc"
elif [[ "$SHELL" == *"csh"* ]]; then
THE_RC="csh"
RC_FILE_PATH="$HOME/.cshrc"
else
find ~/.* -maxdepth 0 -type f
die "ERROR: Shell was not recognized: $SHELL"
fi
}
# Force bashrc loading
function force_bashrc_loading() {
sourceblock="
if [[ -n \"\$BASH_VERSION\" ]]; then
# include .bashrc if it exists
if [[ -f \"\$HOME/.bashrc\" ]]; then
. \"\$HOME/.bashrc\"
fi
fi"
bidon=""
for profile in ~/.bash_profile ~/.bash_login ~/.profile; do
if [[ -a "$profile" ]]; then
if ! grep -E "(\.|source) .*bashrc" "$profile" >/dev/null 2>&1; then
echo "$sourceblock" >>"$profile"
fi
bidon="done"
break
fi
done
if [[ -z "$bidon" ]]; then
echo "$sourceblock" >>~/.bash_profile
fi
}
# Installation text to insert in shell config file
function edit_shellrc() {
# Write text common to all shells
(
echo
echo ""
echo "# SPINALCORDTOOLBOX (installed on $(date +%Y-%m-%d\ %H:%M:%S))"
echo "$DISPLAY_UPDATE_PATH"
# Switch between shell
if [[ "$THE_RC" == "bash" ]]; then
echo "export SCT_DIR=$SCT_DIR"
echo "export MPLBACKEND=Agg"
elif [[ "$THE_RC" == "csh" ]]; then
echo "setenv SCT_DIR $SCT_DIR"
echo "setenv MPLBACKEND Agg"
fi
# add line
echo ""
) >> "$RC_FILE_PATH"
}
# Download from URL using curl/wget
function download() {
( (command -v wget >/dev/null) && run wget -O "$1" "$2" ) ||
( (command -v curl >/dev/null) && run curl -o "$1" -L "$2" ) ||
die "The download of $2 failed
Please check that you have wget or curl installed, and
your internet connection before relaunching the installer"
}
# Usage of this script
function usage() {
# extract the usage block from our own header
awk '
BEGIN {
printing=0
blanks=0
}
# filter for block-comments
$0 !~ /^#/ { next }
# but strip any leading "# "
{ sub("^#[[:space:]]?","") }
# count consecutive blank lines
# so we can detect the section break
/^$/ { blanks++ }
$0 !~ /^$/ { blanks=0 }
# detect usage section
/USAGE/ { printing=1 }
printing==1 { print }
(printing==1 && blanks>=2) { exit }
' "$0"
}
if [ "$(uname)" = "Darwin" ]; then
# macOS polyfills
# Linux has `realpath` and `readlink -f`.
# BSD has `readlink -f`.
# macOS has neither: https://izziswift.com/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac/
# even though it *has* the function in its libc: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/realpath.3.html
# Someone even wrote a whole C program just for this: https://github.com/harto/realpath-osx/.
# https://stackoverflow.com/a/3572105 suggests some bash trickery but it
# seems pretty fragile and that it probably doesn't actually expand symlinks.
# So here, solve it with python. It's not great either, but since much of
# this script already is just calling python at least it's reliable.
(command -v realpath >/dev/null) || realpath() {
python3 -c 'import sys, os; [print(os.path.realpath(f)) for f in sys.argv[1:]]' "$@"
}
fi
# ======================================================================================================================
# SCRIPT STARTS HERE
# ======================================================================================================================
# ----------------------------------------------------------------------------------------------------------------------
# CLI parser
# ----------------------------------------------------------------------------------------------------------------------
# Transform long option "--long" into short option "-l"
for arg in "$@"; do
shift
case "$arg" in
*) set -- "$@" "$arg"
esac
done
while getopts ":iydbvh" opt; do
case $opt in
i)
SCT_INSTALL_TYPE="in-place"
;;
y)
echo " non-interactive mode"
NONINTERACTIVE="yes"
;;
d)
echo " data directory will not be (re)-installed"
NO_DATA_INSTALL="yes"
;;
b)
echo " SCT binaries will not be (re)-installed "
NO_SCT_BIN_INSTALL="yes"
;;
v)
echo " Full verbose!"
set -x
;;
h)
usage
exit 0
;;
*)
usage
exit 99
;;
esac
done
# ----------------------------------------------------------------------------------------------------------------------
# Prepare installation
# ----------------------------------------------------------------------------------------------------------------------
# This trap specifically catches keyboardInterrupt and output a non-zero status before running finish()
trap detectKeyboardInterrupt INT
# Set a trap which, on shell error or shell exit, runs finish()
trap finish EXIT
print info "
*******************************
* Welcome to SCT installation *
*******************************
"
fetch_os_type
check_requirements
# Catch SCT version
if [[ -e "spinalcordtoolbox/version.txt" ]]; then
SCT_VERSION="$(cat spinalcordtoolbox/version.txt)"
else
die "ERROR: version.txt not found. \n
The install_sct script must be executed from the source directory"
fi
# Get installation type (from git or from package) if not already specified
if [[ -z "$SCT_INSTALL_TYPE" ]]; then
if [[ -d ".git" ]]; then
# folder .git exist, therefore it is a git installation
SCT_INSTALL_TYPE="in-place"
else
SCT_INSTALL_TYPE="package"
fi
fi
# Define sh files
get_shell_rc_path
# Display install info
echo -e "\nSCT version ......... $SCT_VERSION"
echo -e "Installation type ... $SCT_INSTALL_TYPE"
echo -e "Operating system .... $OS ($OSver)"
echo -e "Shell config ........ $RC_FILE_PATH"
REPORT_STATS="no"
if [ -z "$NONINTERACTIVE" ]; then
# Send crash statistic and error logs to developers, that is the question:
print question "To improve user experience and fix bugs, the SCT development team is using a
report system to automatically receive crash reports and errors from users.
These reports are anonymous.
Do you agree to help us improve SCT? [y]es/[n]o: "
read -r REPORT_STATS
fi
if [[ "$REPORT_STATS" =~ [Yy](es)? ]]; then
echo -ne '# Auto-generated by install_sct\nimport os\nSENTRY_DSN=os.environ.get("SCT_SENTRY_DSN", "https://5202d7c96ad84f17a24bd2653f1c4f9e:[email protected]/415369")\n' >spinalcordtoolbox/sentry_dsn.py
print info "--> Crash reports will be sent to the SCT development team. Thank you!"
else
print info "--> Crash reports will not be sent."
fi
# if installing from git folder, then becomes default installation folder
if [[ "$SCT_INSTALL_TYPE" == "in-place" ]]; then
SCT_DIR="$SCT_SOURCE"
else
SCT_DIR="$HOME/sct_$SCT_VERSION"
fi
# Set install dir
while true; do
keep_default_path=""
while [[ ! "$keep_default_path" =~ ^([Yy](es)?|[Nn]o?)$ ]]; do
print info "SCT will be installed here: [$SCT_DIR]"
keep_default_path="yes"
if [ -z "$NONINTERACTIVE" ]; then
print question "
Do you agree? [y]es/[n]o: "
read -r keep_default_path
fi
done
if [[ "$keep_default_path" =~ ^[Yy] ]]; then
# user accepts default path --> exit loop
break
fi
# ASSUMPTION: the rest of these are not guarded by $NONINTERACTIVE because this loop should have been broken already in that case.
print question "Choose install directory. Warning! Give full path (e.g. /usr/django/sct_v3.0): \n"
# user enters new path
read -r new_install
# Expand ~/
new_install="${new_install/#\~\//$HOME\/}"
# Remove trailing /
new_install="${new_install%/}"
# Avoid horrible bug, like removing /bin if SCT_DIR "/" or $HOME/bin
if [[ "$new_install" == "/" ]] || [[ "$HOME" == "${new_install%/}" ]]; then
print info "Cannot be installed directly in $new_install"
print info "Please pick a full path"
continue
elif [[ -d "$new_install" ]]; then
# directory exists --> update SCT_DIR and exit loop
print warning "WARNING: Directory already exists. Files will be overwritten."
SCT_DIR="$new_install"
break
elif [[ ! "$new_install" ]]; then
# If no input, asking again, and again, and again
continue
else
SCT_DIR="$new_install"
break
fi
done
# update PATH environment?
add_to_path=""
while [[ ! "$add_to_path" =~ ^([Yy](es)?|[Nn]o?)$ ]]; do
add_to_path="yes"
if [ -z "$NONINTERACTIVE" ]; then
print question "Do you want to add the sct_* scripts to your PATH environment? [y]es/[n]o: "
read -r add_to_path
fi
done
# Create directory
mkdir -p "$SCT_DIR"
# check if directory was created
if [[ -d "$SCT_DIR" ]]; then
# check write permission
if [[ ! -w "$SCT_DIR" ]]; then
die "ERROR: $SCT_DIR exists but does not have write permission."
fi
else
die "ERROR: $SCT_DIR cannot be created. Make sure you have write permission."
fi
# Update PATH variables based on Shell type
if [[ $THE_RC == "bash" ]]; then
DISPLAY_UPDATE_PATH="export PATH=\"$SCT_DIR/$BIN_DIR:\$PATH\""
elif [[ $THE_RC == "csh" ]]; then
DISPLAY_UPDATE_PATH="setenv PATH \"$SCT_DIR/$BIN_DIR:\$PATH\""
else
die "This variable is not recognized: THE_RC=$THE_RC"
fi
# Update MPLBACKEND on headless system. See: https://github.com/neuropoly/spinalcordtoolbox/issues/2137
if [[ -z "${MLBACKEND:-}" ]]; then
export MPLBACKEND=Agg
fi
# Copy files to destination directory
if [[ "$SCT_DIR" != "$SCT_SOURCE" ]]; then
print info "Copying source files from $SCT_SOURCE to $SCT_DIR"
cp -vR "$SCT_SOURCE/"* "$SCT_DIR/" | while read -r; do echo -n "."; done
else
print info "Skipping copy of source files (source and destination folders are the same)"
fi
# Clean old install setup in bin/ if existing
if [[ -x "$SCT_DIR/$BIN_DIR" ]]; then
print info "Removing sct and isct softlink from $SCT_DIR/$BIN_DIR"
find "$SCT_DIR/$BIN_DIR" -type l -name 'sct_*' -exec rm {} \;
find "$SCT_DIR/$BIN_DIR" -type l -name 'isct_*' -exec rm {} \;
fi
# Go to installation folder
cd "$SCT_DIR"
# Make sure we are in SCT folder (to avoid deleting folder from user)
if [[ ! -f "spinalcordtoolbox/version.txt" ]]; then
die "ERROR: Cannot cd into SCT folder. SCT_DIR=$SCT_DIR"
fi
# ----------------------------------------------------------------------------------------------------------------------
# Install Python
# ----------------------------------------------------------------------------------------------------------------------
# We make sure that there is no conflict with local python install by unsetting PYTHONPATH and forcing PYTHONNOUSERSITE
unset PYTHONPATH
export PYTHONNOUSERSITE=1
# Remove old python folder
print info "Installing conda..."
run rm -rf "$SCT_DIR/$PYTHON_DIR"
run mkdir -p "$SCT_DIR/$PYTHON_DIR"
# Download miniconda
case $OS in
linux*)
download "$TMP_DIR/"miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
;;
osx)
download "$TMP_DIR/"miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
;;
esac
# Run conda installer
run bash "$TMP_DIR/miniconda.sh" -p "$SCT_DIR/$PYTHON_DIR" -b -f
# create py3.6 venv (for Keras/TF compatibility with Centos7, see issue #2270)
python/bin/conda create -y -n venv_sct python=3.6
# activate miniconda
# shellcheck disable=SC1091
source python/etc/profile.d/conda.sh
set +u #disable safeties, for conda is not written to their standard.
conda activate venv_sct
set -u # reactivate safeties
# double-check conda activated (it can be glitchy): https://github.com/neuropoly/spinalcordtoolbox/issues/3029
EXPECTED_PYTHON="$(realpath "$(command -v python/envs/venv_sct/bin/python)")"
ACTUAL_PYTHON="$(realpath "$(command -v python)")"
if [ "$ACTUAL_PYTHON" != "$EXPECTED_PYTHON" ]; then
echo "Error: Activating venv_sct failed to switch Python interpreter to Miniconda. (Incorrect interpreter loaded: $ACTUAL_PYTHON)" >&2
exit 1
fi
## Install the spinalcordtoolbox into the Conda venv
print info "Installing Python dependencies..."
# Check if a frozen version of the requirements exist (for release only)
if [[ -f "requirements-freeze.txt" ]]; then
print info "Using requirements-freeze.txt (release installation)"
REQUIREMENTS_FILE="requirements-freeze.txt"
else
# Not a package
print info "Using requirements.txt (git installation)"
REQUIREMENTS_FILE="requirements.txt"
fi
(
pip install -r "$REQUIREMENTS_FILE" &&
# `tensorflow-tensorboard` is installed by `tensorflow==1.5.0` but is not needed,
# and conflicts with the other installation of `tensorboard`. So, we uninstall here.
# This is hacky, and should be removed as soon as we stop using `tensorflow==1.5.0`.
# See https://github.com/neuropoly/spinalcordtoolbox/issues/3035 for more info.
pip uninstall -y tensorflow-tensorboard &&
pip uninstall -y tensorboard &&
pip install tensorboard &&
# install sct itself
print info "Installing spinalcordtoolbox..." &&
pip install -e .
) ||
die "Failed running pip install: $?"
## Create launchers for Python scripts
print info "Creating launchers for Python scripts..."
mkdir -p "$SCT_DIR/$BIN_DIR"
for file in "$SCT_DIR"/python/envs/venv_sct/bin/*sct*; do
cp "$file" "$SCT_DIR/$BIN_DIR/" || die "Problem creating launchers!"
done
# Activate the launchers, particularly sct_download_data and sct_check_requirements
export PATH="$SCT_DIR/$BIN_DIR:$PATH"
# ----------------------------------------------------------------------------------------------------------------------
# Download binaries and data
# ----------------------------------------------------------------------------------------------------------------------
# Install binaries
if [[ -n "$NO_SCT_BIN_INSTALL" ]]; then
print warning "WARNING: SCT binaries will not be (re)-installed"
else
print info "Installing binaries..."
run sct_download_data -d "binaries_${OS}" -o "${SCT_DIR}/${BIN_DIR}" -k
fi
print info "All requirements installed!"
# Install data
if [[ -n "$NO_DATA_INSTALL" ]]; then
print warning "WARNING: data/ will not be (re)-install"
else
# Download data
print info "Installing data..."
run rm -rf "$SCT_DIR/$DATA_DIR"
run mkdir -p "$SCT_DIR/$DATA_DIR"
for data in PAM50 gm_model optic_models pmj_models deepseg_sc_models deepseg_gm_models deepseg_lesion_models c2c3_disc_models; do
run sct_download_data -d "$data" -o "$SCT_DIR/$DATA_DIR/$data"
done
fi
# Install deep learning models
python -c 'import spinalcordtoolbox.deepseg.models; spinalcordtoolbox.deepseg.models.install_default_models()'
# ----------------------------------------------------------------------------------------------------------------------
# Validate installation
# ----------------------------------------------------------------------------------------------------------------------
# conda is only for a sandbox; users don't use it,
# so neither should our post-install tests
conda deactivate >/dev/null 2>&1
# In case of previous SCT installation (4.0.0-beta.1 or before), remove sct_env declaration in bashrc
if [[ -e "$RC_FILE_PATH" ]]; then
if grep "sct_env" "$RC_FILE_PATH"; then
print info "In case an old version SCT is already installed (4.0.0-beta.1 or before), remove 'sct_env' declaration in RC file"
sed -ie '/sct_env/ s/^#*/#/' "$RC_FILE_PATH"
fi
fi
if [[ "$add_to_path" =~ ^[Yy] ]]; then
edit_shellrc
else
print info "Not adding $SCT_DIR to \$PATH.
You can always add it later or call SCT functions with full path $SCT_DIR/$BIN_DIR/sct_xxx"
fi
# run sct_check_dependencies
print info "Validate installation..."
# We run the sct_check_dependencies in the TMP_DIR so the tmp.XXX output
# it creates is cleaned properly
if sct_check_dependencies; then
if [[ "$add_to_path" =~ ^[Nn] ]]; then
print info "To use SCT, please update your environment by running:
$DISPLAY_UPDATE_PATH"
else
print info "Open a new Terminal window to load environment variables, or run:
source $RC_FILE_PATH"
fi
else
die "Installation validation Failed!"
fi