Skip to content

Commit 73e7d4c

Browse files
authored
Merge pull request #3 from PreibischLab/refactor/install-scripts
Refactor install scripts
2 parents f83a151 + 40eb8e1 commit 73e7d4c

3 files changed

Lines changed: 155 additions & 105 deletions

File tree

install

Lines changed: 0 additions & 89 deletions
This file was deleted.

install.sh

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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."

install_windows.bat

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,46 @@ setlocal EnableExtensions
55
:: is adapted from https://github.com/saalfeldlab/n5-utils, by @axtimwalde & co
66
set "VERSION=0.2.0-SNAPSHOT"
77

8-
if "%~1"=="" (
9-
set "INSTALL_DIR=%CD%"
10-
) else (
11-
set "INSTALL_DIR=%~1"
12-
)
8+
:: default for installation dir = current directory
9+
set "INSTALL_DIR=%CD%"
10+
11+
:: default for repository dir = standard maven repository
12+
set "REPO_DIR=%USERPROFILE%\.m2\repository"
13+
14+
:: parse arguments one by one
15+
:parse
16+
if "%~1"=="" goto :doneparsing
17+
18+
if /i "%~1"=="/h" call :usage & goto :EOF
19+
if /i "%~1"=="/i" set "INSTALL_DIR=%~2" & shift & shift & goto :parse
20+
if /i "%~1"=="/r" set "REPO_DIR=%~2" & shift & shift & goto :parse
21+
22+
:: argument doesn't match any of the above
23+
echo Unknown option "%~1"
24+
call :usage & goto :EOF
25+
:doneparsing
26+
27+
echo.
28+
echo Downloading dependencies into %REPO_DIR%
29+
echo Installing into %INSTALL_DIR%
1330

1431
:: read out total memory of system
1532
for /F "skip=1" %%A in ('wmic ComputerSystem get TotalPhysicalMemory') do (
1633
set MEM=%%A
17-
goto :done
34+
goto :donemem
1835
)
19-
:done
36+
:donemem
2037

2138
:: batch can only handle integers below 2^31
2239
:: -> cut last six digits of number in bytes (~MB) and divide by 1024 (~GB)
2340
set /A "MEMGB=%MEM:~,-6%/1024"
24-
set /A "MEM=(3*MEMGB)/4"
41+
set /A "MEM_LIMIT=(4*MEMGB)/5"
2542

26-
echo Available memory: %MEMGB%GB, setting Java memory limit to %MEM%GB
43+
echo Available memory: %MEMGB%GB, setting Java memory limit to %MEM_LIMIT%GB
2744

2845
:: Skip tests for now, since they don't work on windows.
29-
call mvn clean install -DskipTests
30-
call mvn -Dmdep.outputFile=cp.txt -Dmdep.includeScope=runtime dependency:build-classpath
46+
call mvn clean install -DskipTests -Dmaven.repo.local="%REPO_DIR%"
47+
call mvn -Dmdep.outputFile=cp.txt -Dmdep.includeScope=runtime -Dmaven.repo.local="%REPO_DIR%" dependency:build-classpath
3148

3249
call :install_command st-explorer.bat cmd.View
3350
call :install_command st-render.bat cmd.RenderImage
@@ -73,15 +90,22 @@ goto :EOF
7390
echo @echo off
7491
echo.
7592
echo java^^
76-
echo -Xmx%MEM%g^^
77-
echo -cp %USERPROFILE%\.m2\repository\net\preibisch\imglib2-st\%VERSION%\imglib2-st-%VERSION%.jar;^^
93+
echo -Xmx%MEM_LIMIT%g^^
94+
echo -cp %REPO_DIR%\net\preibisch\imglib2-st\%VERSION%\imglib2-st-%VERSION%.jar;^^
7895
type cp.txt
7996
echo ^^
8097
echo %2 %%*
8198
) > %1
8299
goto :EOF
83100

84-
endlocal
85-
86-
101+
:usage
102+
echo USAGE: install_windows.bat [options]
103+
echo.
104+
echo. OPTIONS
105+
echo. /h Display this help message
106+
echo. /i [install_dir] Install commands into [install_dir]
107+
echo. (default: current directory)
108+
echo. /r [repository_dir] Download dependencies into [repository_dir]
109+
echo. (default: %%USERPROFILE%%\.m2\repository)
87110

111+
endlocal

0 commit comments

Comments
 (0)