Select Git revision
install.sh 5.70 KiB
#!/usr/bin/env bash
if [ -z "$BIN_DIR" ]; then
BIN_DIR=~/.local/bin
fi
if [ -z "$LARVATAGGER_PATH" ]; then
LARVATAGGER_PATH=~/.local/share/larvatagger
fi
if [ "$1" = "--uninstall" ]; then
if [ -d "$LARVATAGGER_PATH/MaggotUBA" ]; then
env=(cd "$LARVATAGGER_PATH/MaggotUBA" && poetry env info -p)
if [ -d "$env" ]; then
# clear the virtual environments
env=$(dirname "$env")
rm -rf "$env/maggotuba*"
rm -rf "$env/taggingbackends*"
fi
fi
rm -rf "$BIN_DIR/larvatagger"
rm -rf "$LARVATAGGER_PATH"
else
if ! command -v curl 1>/dev/null 2>&1; then
if command -v brew 1>/dev/null 2>&1; then
# macOS users are not given the choice as they usually do not care about freedom
brew install curl
fi
fi
if ! command -v curl 1>/dev/null 2>&1; then
echo "Command curl required; aborting"
else
if [ "`uname`" = "Darwin" ]; then
# macOS
if ! command -v brew 1>/dev/null 2>&1; then
echo "Installing Homebrew; admin rights will be requested"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
fi
if ! command -v realpath 1>/dev/null 2>&1; then
# macOS
if command -v brew 1>/dev/null 2>&1; then
brew install coreutils
fi
fi
if ! command -v julia 1>/dev/null 2>&1; then
if [ -z "$JULIA_INSTALL_ARGS" ]; then
JULIA_INSTALL_ARGS=-y
fi
curl -fsSL https://install.julialang.org | sh -s -- $JULIA_INSTALL_ARGS
if [ -f ~/.bashrc ]; then
source ~/.bashrc
elif [ -f ~/.bash_profile ]; then
source ~/.bash_profile
fi
fi
for arg in "$@"; do
if [ "$arg" = "--with-default-backend" ]; then
WITH_DEFAULT_BACKEND=1
break
fi
done
if [ -n "$WITH_DEFAULT_BACKEND" ]; then
if [ "`uname`" = "Darwin" ]; then
echo "WARNING: the default tagging backend does not work on macOS"
fi
if ! command -v python3.8 1>/dev/null 2>&1; then
if command -v pyenv 1>/dev/null 2>&1; then
pyenv install 3.8
elif command -v brew 1>/dev/null 2>&1; then
brew install python@3.8
else
echo "WARNING: command python3.8 not found"
echo "if under Ubuntu, consider running: sudo apt install python3.8 python3.8-venv"
fi
fi
if ! command -v poetry 1>/dev/null 2>&1; then
if command -v pipx 1>/dev/null 2>&1; then
pipx install poetry
else
curl -fsSL https://install.python-poetry.org | python3 -
fi
fi
fi
mkdir -p "$LARVATAGGER_PATH" && pushd $_
##
if [ -d PlanarLarvae ]; then
echo "PlanarLarvae.jl installation found; skipping"
else
if [ -z "$PLANARLARVAE_BRANCH" ]; then
PLANARLARVAE_BRANCH=main
fi
curl -fsSL https://gitlab.pasteur.fr/nyx/planarlarvae.jl/-/archive/${PLANARLARVAE_BRANCH}/planarlarvae.jl-${PLANARLARVAE_BRANCH}.tar.gz | tar zxv
mv planarlarvae.jl-${PLANARLARVAE_BRANCH} PlanarLarvae
fi
if [ -d LarvaTagger.jl ]; then
echo "LarvaTagger.jl installation found; skipping"
else
if [ -z "$LARVATAGGER_BRANCH" ]; then
LARVATAGGER_BRANCH=dev
fi
curl -fsSL https://gitlab.pasteur.fr/nyx/larvatagger.jl/-/archive/${LARVATAGGER_BRANCH}/larvatagger.jl-${LARVATAGGER_BRANCH}.tar.gz | tar zxv
mv larvatagger.jl-${LARVATAGGER_BRANCH} LarvaTagger.jl
fi
(cd LarvaTagger.jl && julia --project=. -e 'using Pkg; Pkg.instantiate(); Pkg.develop(path="../PlanarLarvae")')
if [ -z "$WITH_DEFAULT_BACKEND" ]; then
cat <<EOF >$BIN_DIR/larvatagger
#!/usr/bin/env bash
"$LARVATAGGER_PATH/LarvaTagger.jl/scripts/larvatagger" \$@
EOF
else
activate() {
poetry env use 3.8
}
if [ -d TaggingBackends ]; then
echo "TaggingBackends installation found; skipping"
else
if [ -z "$TAGGINGBACKENDS_BRANCH" ]; then
TAGGINGBACKENDS_BRANCH=main
fi
curl -fsSL https://gitlab.pasteur.fr/nyx/TaggingBackends/-/archive/${TAGGINGBACKENDS_BRANCH}/TaggingBackends-${TAGGINGBACKENDS_BRANCH}.tar.gz | tar zxv
mv TaggingBackends-${TAGGINGBACKENDS_BRANCH} TaggingBackends
fi
(cd TaggingBackends && julia --project=. -e 'using Pkg; Pkg.instantiate(); Pkg.develop(path="../PlanarLarvae")')
(cd TaggingBackends && activate && poetry install)
if [ -d MaggotUBA-core ]; then
echo "MaggotUBA-core installation found; skipping"
else
if [ -z "$MAGGOTUBA_CORE_BRANCH" ]; then
MAGGOTUBA_CORE_BRANCH=main
fi
curl -fsSL https://gitlab.pasteur.fr/nyx/maggotuba-core/-/archive/${MAGGOTUBA_CORE_BRANCH}/maggotuba-core-${MAGGOTUBA_CORE_BRANCH}.tar.gz | tar zxv
mv maggotuba-core-${MAGGOTUBA_CORE_BRANCH} MaggotUBA-core
fi
if [ -d MaggotUBA ]; then
echo "MaggotUBA installation found; skipping"
else
if [ -z "$MAGGOTUBA_ADAPTER_BRANCH" ]; then
MAGGOTUBA_ADAPTER_BRANCH=main
fi
curl -fsSL https://gitlab.pasteur.fr/nyx/MaggotUBA-adapter/-/archive/${MAGGOTUBA_ADAPTER_BRANCH}/MaggotUBA-adapter-${MAGGOTUBA_ADAPTER_BRANCH}.tar.gz | tar zxv
mv MaggotUBA-adapter-${MAGGOTUBA_ADAPTER_BRANCH} MaggotUBA #-adapter
#ln -s $(realpath MaggotUBA-adapter) MaggotUBA
fi
(cd MaggotUBA && activate && (cat requirements.txt | xargs -I % sh -c 'poetry add "%"') && poetry install -v && poetry remove taggingbackends && poetry add ../TaggingBackends && poetry remove maggotuba-core && poetry add ../MaggotUBA-core)
(cd MaggotUBA && scripts/make_models.jl default)
cat <<EOF >$BIN_DIR/larvatagger
#!/usr/bin/env bash
JULIA_PROJECT="$(realpath "$LARVATAGGER_PATH/TaggingBackends")" BACKENDS_PATH="$LARVATAGGER_PATH" "$LARVATAGGER_PATH/LarvaTagger.jl/scripts/larvatagger" \$@
EOF
fi
chmod a+x "$BIN_DIR/larvatagger"
if ! command -v larvatagger 1>/dev/null 2>&1; then
# ~/.local/bin not in $PATH?
if [ "$SHELL" = "/bin/zsh" ]; then
rcfile=~/.zshrc
elif [ "$SHELL" = "/bin/bash" ]; then
if [ -f ~/.bashrc ]; then
rcfile=~/.bashrc
elif [ -f ~/.bash_profile ]; then
rcfile=~/.bash_profile
fi
fi
cat <<"EOF" >>$rcfile
export PATH=$PATH:~/.local/bin
EOF
export PATH=$PATH:~/.local/bin
fi
##
popd
fi
fi