|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# This script is shamelessly adapted from https://github.com/saalfeldlab/n5-utils, thanks @axtimwalde & co! |
| 4 | + |
| 5 | +display_usage () { |
| 6 | + echo "Usage: install.sh [options]" |
| 7 | + echo "" |
| 8 | + echo "OPTIONS" |
| 9 | + echo " -h Display this help message" |
| 10 | + echo " -i <install_dir> Install commands into <install_dir>" |
| 11 | + echo " (default: current directory)" |
| 12 | + echo " -r <repository_dir> Download dependencies into <repository_dir>" |
| 13 | + echo " (default: standard maven repository, most" |
| 14 | + echo " likely \$HOME/.m2/repository)" |
| 15 | + exit |
| 16 | +} |
| 17 | + |
| 18 | +VERSION="0.2.0-SNAPSHOT" |
| 19 | + |
| 20 | +while getopts :hi:r: flag |
| 21 | +do |
| 22 | + case "${flag}" in |
| 23 | + h) display_usage;; |
| 24 | + i) INSTALL_DIR=${OPTARG};; |
| 25 | + r) REPO_DIR=${OPTARG};; |
| 26 | + ?) display_usage;; |
| 27 | + esac |
| 28 | +done |
| 29 | +INSTALL_DIR=${INSTALL_DIR:-$(pwd)} |
| 30 | +REPO_DIR=${REPO_DIR:-$(mvn help:evaluate -Dexpression=settings.localRepository -q -DforceStdout)} |
| 31 | + |
| 32 | +echo "" |
| 33 | +echo "Downloading dependencies into ${REPO_DIR}" |
| 34 | +echo "Installing into ${INSTALL_DIR}" |
| 35 | + |
| 36 | +# check for operating system |
| 37 | +if [[ "${OSTYPE}" == "linux-gnu" ]]; then |
| 38 | + echo "Assuming on Linux operating system" |
| 39 | + MEM=$(cat /proc/meminfo | grep MemTotal | sed s/^MemTotal:\\\s*\\\|\\\s\\+[^\\\s]*$//g) |
| 40 | + MEMGB=$((${MEM}/1024/1024)) |
| 41 | +elif [[ "${OSTYPE}" == "darwin"* ]]; then |
| 42 | + echo "Assuming on MacOS X operating system" |
| 43 | + # sysctl returns total hardware memory size in bytes |
| 44 | + MEM=$(sysctl hw.memsize | grep hw.memsize | sed s/hw.memsize://g) |
| 45 | + MEMGB=$((${MEM}/1024/1024/1024)) |
| 46 | +else |
| 47 | + echo "ERROR - Operating system must be either Linux or MacOS X - EXITING" |
| 48 | + echo "(on Windows, please run the Windows specific install script)" |
| 49 | + exit |
| 50 | +fi |
| 51 | + |
| 52 | +MEM_LIMIT=$(((${MEMGB}/5)*4)) |
| 53 | +echo "Available memory:" ${MEMGB} "GB, setting Java memory limit to" ${MEM_LIMIT} "GB" |
| 54 | +echo "" |
| 55 | + |
| 56 | +mvn clean install -Dmaven.repo.local=${REPO_DIR} |
| 57 | +mvn -Dmdep.outputFile=cp.txt -Dmdep.includeScope=runtime -Dmaven.repo.local=${REPO_DIR} dependency:build-classpath |
| 58 | + |
| 59 | +echo "" |
| 60 | + |
| 61 | +# function that installs one command |
| 62 | +# $1 - command name |
| 63 | +# $2 - java class containing the functionality |
| 64 | +install_command () { |
| 65 | + echo "Installing '$1' command into" $INSTALL_DIR |
| 66 | + |
| 67 | + echo '#!/bin/bash' > $1 |
| 68 | + echo '' >> $1 |
| 69 | + echo "JAR=${REPO_DIR}/net/preibisch/imglib2-st/${VERSION}/imglib2-st-${VERSION}.jar" >> $1 |
| 70 | + echo 'java \' >> $1 |
| 71 | + echo " -Xmx${MEM_LIMIT}g \\" >> $1 |
| 72 | + echo -n ' -cp $JAR:' >> $1 |
| 73 | + echo -n $(cat cp.txt) >> $1 |
| 74 | + echo ' \' >> $1 |
| 75 | + echo ' '$2' "$@"' >> $1 |
| 76 | + |
| 77 | + chmod a+x $1 |
| 78 | +} |
| 79 | + |
| 80 | + |
| 81 | +install_command st-explorer "cmd.View" |
| 82 | +install_command st-render "cmd.RenderImage" |
| 83 | +install_command st-bdv-view "cmd.DisplayStackedSlides" |
| 84 | +install_command st-resave "cmd.Resave" |
| 85 | +install_command st-add-slice "cmd.AddSlice" |
| 86 | +install_command st-normalize "cmd.Normalize" |
| 87 | +install_command st-add-annotations "cmd.AddAnnotations" |
| 88 | +install_command st-align-pairs "cmd.PairwiseSectionAligner" |
| 89 | +install_command st-align-pairs-add "cmd.AddPairwiseMatch" |
| 90 | +install_command st-align-pairs-view "cmd.ViewPairwiseAlignment" |
| 91 | +install_command st-align-global "cmd.GlobalOpt" |
| 92 | +install_command st-help "cmd.PrintHelp" |
| 93 | + |
| 94 | +if [ $(pwd) == "${INSTALL_DIR}" ]; then |
| 95 | + echo "Installation directory equals current directory, we are done." |
| 96 | +else |
| 97 | + echo "Creating directory ${INSTALL_DIR} and moving files..." |
| 98 | + mkdir -p ${INSTALL_DIR} |
| 99 | + mv st-explorer ${INSTALL_DIR}/ |
| 100 | + mv st-bdv-view ${INSTALL_DIR}/ |
| 101 | + mv st-render ${INSTALL_DIR}/ |
| 102 | + mv st-resave ${INSTALL_DIR}/ |
| 103 | + mv st-add-slice ${INSTALL_DIR}/ |
| 104 | + mv st-normalize ${INSTALL_DIR}/ |
| 105 | + mv st-add-annotations ${INSTALL_DIR}/ |
| 106 | + mv st-align-pairs ${INSTALL_DIR}/ |
| 107 | + mv st-align-pairs-add ${INSTALL_DIR}/ |
| 108 | + mv st-align-pairs-view ${INSTALL_DIR}/ |
| 109 | + mv st-align-global ${INSTALL_DIR}/ |
| 110 | + mv st-help ${INSTALL_DIR}/ |
| 111 | +fi |
| 112 | + |
| 113 | +rm cp.txt |
| 114 | + |
| 115 | +echo "Installation finished." |
0 commit comments