-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathimagey-starter.sh
executable file
·98 lines (75 loc) · 3.18 KB
/
imagey-starter.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
#!/bin/bash
# should we assume that bash is there? does sh understand basic globbing?
# PYJNIUS_JAR=$HOME/imglyb-jars/pyjnius.jar JAVA_HOME=/usr/lib/jvm/default USE_SYSTEM_PYTHON=1 ./imagey-starter.sh
set -e
PYTHON=python
USER_JAVA_HOME=${JAVA_HOME}
export FIJI_APP_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ -z "${USE_SYSTEM_PYTHON}" ]; then
CONDA_HOME=${CONDA_HOME:-$FIJI_APP_DIR/conda}
FIJI_CONDA_ENVIRONMENT=${FIJI_CONDA_ENVIRONMENT:-fiji}
unset PYTHONPATH
if [ ! -d "${CONDA_HOME}" ]; then
# adjust name but good for now
case "$(uname -s)" in
Linux)
INSTALLER_NAME=Miniconda3-latest-Linux-x86_64.sh
;;
Darwin)
INSTALLER_NAME=Miniconda3-latest-MacOSX-x86_64.sh
;;
*)
echo "Do not understand OS: " $(uname -s) >&2
exit 1
esac
CONDA_INSTALLER="${FIJI_APP_DIR}/${INSTALLER_NAME}"
curl \
https://repo.continuum.io/miniconda/${INSTALLER_NAME} \
-o ${CONDA_INSTALLER}
sh "${CONDA_INSTALLER}" -b -p $CONDA_HOME
rm "${CONDA_INSTALLER}"
fi
export PATH="${CONDA_HOME}/bin:$PATH"
CONDA_CMD="${CONDA_HOME}/bin/conda"
ACTIVATE="${CONDA_HOME}/bin/activate"
DEACTIVATE="${CONDA_HOME}/bin/deactivate"
# how to ignore ~/.conda?
# CONDA_ENVS_PATH='' /home/phil/local/Fiji.app/conda/bin/conda config --show
# does not work
CONDA_ENVS_INFO=$(${CONDA_CMD} info --envs)
INFO_GREP_OPTS="-E '^\${FIJI_CONDA_ENVIRONMENT} +[*/]'"
# { cmd || true; } avoids potential non-zero return code of cmd
ENV_EXIST_STRING=$( echo "$CONDA_ENVS_INFO" | { grep -E "^${FIJI_CONDA_ENVIRONMENT} +[*/]" || true; } )
if [ -z "${ENV_EXIST_STRING}" ]; then
# probably need to specify version for imglyb
CREATE_CMD="${CONDA_CMD} create \
-y \
-n ${FIJI_CONDA_ENVIRONMENT} \
python=3.6"
${CREATE_CMD}
fi
# recommended by conda installation instructions to source activate first:
# https://conda.io/docs/help/silent.html#linux-and-os-x
source "${ACTIVATE}" "${FIJI_CONDA_ENVIRONMENT}"
INSTALLED_PACKAGES="$($CONDA_CMD list | grep -v '^#' | cut -d ' ' -f1)"
if [ -z "$(echo $INSTALLED_PACKAGES | grep imglyb)" ]; then
$CONDA_CMD install -y -c conda-forge -c hanslovsky imglyb
fi
for CONDA_PACKAGE in pyqt qtconsole scikit-image matplotlib; do
if [ -z "$(echo $INSTALLED_PACKAGES | grep $CONDA_PACKAGE)" ]; then
$CONDA_CMD install -y $CONDA_PACKAGE
fi
done
export JAVA_HOME="${USER_JAVA_HOME:-$JAVA_HOME}"
# restart environment to make sure all environment variables are set
source "${DEACTIVATE}" "${FIJI_CONDA_ENVIRONMENT}"
source "${ACTIVATE}" "${FIJI_CONDA_ENVIRONMENT}"
fi
JARS_DIR="${FIJI_APP_DIR}/jars"
PLUGINS_DIR="${FIJI_APP_DIR}/plugins"
BIO_FORMATS_DIR="${JARS_DIR}/bio-formats"
JARS_FMT="${JARS_DIR}/*.jar"
PLUGINS_FMT="${PLUGINS_DIR}/*.jar"
BIO_FORMATS_FMT="${BIO_FORMATS_DIR}/*.jar"
export CLASSPATH=`ls -1 ${JARS_FMT} ${PLUGINS_FMT} ${BIO_FORMATS_FMT} | tr '\n' ':'`:$CLASSPATH
$PYTHON "${FIJI_APP_DIR}/imagey.py" "$@"