[med-svn] r3333 - trunk/packages/imagej/trunk/debian
Andreas Tille
tille at alioth.debian.org
Wed Apr 29 08:59:15 UTC 2009
Author: tille
Date: 2009-04-29 08:59:15 +0000 (Wed, 29 Apr 2009)
New Revision: 3333
Modified:
trunk/packages/imagej/trunk/debian/imagej.sh
Log:
Commit a patch by Johan Henriksson <mahogny at maia.areta.org> which he describes as follows:
it allows dependent packages to add JNI-paths. this is a
critical update as an important package (micromanager-ij) depends on it. if you can't get it in very
soon, let me know so I can opt for alternative solutions.
Modified: trunk/packages/imagej/trunk/debian/imagej.sh
===================================================================
--- trunk/packages/imagej/trunk/debian/imagej.sh 2009-04-28 06:08:10 UTC (rev 3332)
+++ trunk/packages/imagej/trunk/debian/imagej.sh 2009-04-29 08:59:15 UTC (rev 3333)
@@ -4,7 +4,7 @@
# Copyright © 2008 Paolo Ariano
# Authors: Paolo Ariano (paolo dot ariano at unito dot it)
-# Last modified date: 19 Sept 2008
+# Last modified date: 04 March 2008
# This is a not so simple wrapper script used to run ImageJ in Unix but
# optimized for Debian GNU/Linux, this is a merge between my original script
@@ -23,13 +23,13 @@
set +u # don't give error for unset variables (matters for environment variables)
shopt -s extglob # allow extended pattern matching
-##################### DEFINE JAVA_HOME .DEB #####################
+##################### DEFINE JAVA_HOME #####################
if [ -z "$JAVA_HOME" ] ; then
- JAVA_HOME=$(dirname $(dirname $(readlink -e /usr/bin/java)))
+ JAVA_HOME=$(/usr/sbin/update-java-alternatives -l | head -1 | cut -d' ' -f 3)
fi
-##################### CREATE THE RIGHT ENVIRONMENT .DEB #####################
+##################### CREATE THE RIGHT ENVIRONMENT #####################
# ImageJ path
ij_path=/usr/share/java
@@ -37,11 +37,14 @@
#ImageJ user path
ij_user_path=$HOME/.imagej
+# report errors to this user
+ijadmin='paolo.ariano at unito.it'
+
# Documentation URL
doc_url='http://rsb.info.nih.gov/ij/'
# temp folder
-ij_tmp='/tmp/imagej'
+ij_tmp=$HOME/.imagej/tmp
# default behaviour when an ImageJ window is already open
newwindow='true'
@@ -53,35 +56,12 @@
# use macro functions: args=getArgument(); argArray=split(args, ':');
# to recover macro arguments
-# create plugins,macro,tmp dirs
-mkdir -p $ij_user_path/plugins
-mkdir -p $ij_user_path/macros
-mkdir -p $ij_user_path/luts
+declare -i mem
+declare -i default_mem=500
+declare -i min_mem=16
+declare -i max_mem
+declare -i free_mem
-# makes symbolik links from shared plugins, macros and luts
-
-ls /usr/share/imagej/plugins | while read p ; do
- if [ ! -e "$ij_user_path/plugins/$p" ] ; then
- ln -s /usr/share/imagej/plugins/$p $ij_user_path/plugins/$p
- fi
-done
-
-ls /usr/share/imagej/macros | while read p; do
- if [ ! -e "$ij_user_path/macros/$p" ] ; then
- ln -s "/usr/share/imagej/macros/$p" "$ij_user_path/macros/$p"
- fi
-done
-
-ls /usr/share/imagej/luts | while read p ; do
- if [ ! -e "$ij_user_path/luts/$p" ] ; then
- ln -s /usr/share/imagej/luts/$p $ij_user_path/luts/$p
- fi
-done
-
-
-# report errors to this user
-# ijadmin='paolo.ariano at unito.it'
-
# other variables
dir=`pwd`
user=`whoami`
@@ -103,49 +83,76 @@
macrocmd=''
macroargs=''
-############ DEFAULT MEMORY SETTINGS #########################
-
-declare -i default_mem=768
-declare -i min_mem=32
-declare -i max_32bit=1800 # empirical
-declare -i max_64bit=17000000000 # conservative
-
-############ MEMORY ALLOCATION #########################
-
-OS=$(uname)
-processor=$(uname -m) # -p doesn't work on debian/ubuntu
-declare -i mem
-declare -i max_mem
-declare -i free_mem
-
-java_home="${java_home:-$JAVA_HOME}"
-
-if [[ "$OS" == 'SunOS' ]] ; then
- java_arch='-d64'
- JAVA_HOME="${java_home_SunOS:-$java_home}"
- max_mem=`vmstat | awk 'BEGIN{maxMem='$max_64bit'} NR == 3 {fmem=int($5 / 1024); if (fmem < maxMem) {print fmem} else {print maxMem}}'`
+# max memory allocation is 1800MB on 32bit java and 4000 on 64bit java
+if [[ `uname` == 'SunOS' ]] ; then
+ arch='-d64'
+ java_path="${ij_path}/jre64/bin/java"
+ max_mem=`vmstat | awk 'NR == 3 {fmem=int($5 / 1024); if (fmem < 4000) {print fmem} else {print 4000}}'`
free_mem="max_mem"
- mem=${free_mem}/2
+ mem=${free_mem}/2*3
if (( $mem > $default_mem || $mem < $min_mem )) ; then mem=$default_mem ; fi
-elif [[ "$OS" == 'Linux' ]] ; then
- if [[ "$processor" == 'x86_64' ]] ; then
- java_arch='-d64'
- JAVA_HOME="${java_home_Linux_x86_64:-$java_home}"
- max_mem=`free | awk -v maxMem=$max_64bit 'NR == 2 {fmem=int($2 / 1024); if (fmem < maxMem) {print fmem} else {print maxMem}}'`
- free_mem=`free | awk -v maxMem=$max_64bit 'NR == 3 {fmem=int($4 / 1024); if (fmem < maxMem) {print fmem} else {print maxMem}}'`
+elif [[ `uname` == 'Linux' ]] ; then
+ if [[ `uname -m` == 'x86_64' ]] ; then
+ arch='-d64'
+ java_path="${ij_path}/jre64/bin/java"
+ max_mem=`free | awk 'NR == 2 {fmem=int($2 / 1024); if (fmem < 4000) {print fmem} else {print 4000}}'`
+ free_mem=`free | awk 'NR == 3 {fmem=int($4 / 1024); if (fmem < 4000) {print fmem} else {print 4000}}'`
mem=${free_mem}/3*2
if (( $mem > $default_mem || $mem < $min_mem )) ; then mem=$default_mem ; fi
else
- java_arch='-d32'
- JAVA_HOME="${java_home_Linux:-$java_home}"
- max_mem=`free | awk -v maxMem=$max_32bit 'NR == 2 {fmem=int($2 / 1024); if (fmem < maxMem) {print fmem} else {print maxMem}}'`
- free_mem=`free | awk -v maxMem=$max_32bit 'NR == 3 {fmem=int($4 / 1024); if (fmem < maxMem) {print fmem} else {print maxMem}}'`
+ arch='-d32'
+ java_path="${ij_path}/jre/bin/java"
+ free_mem=`free | awk 'NR == 2 {fmem=int($2 / 1024); if (fmem < 1800) {print fmem} else {print 1800}}'`
+ free_mem=`free | awk 'NR == 3 {fmem=int($4 / 1024); if (fmem < 1800) {print fmem} else {print 1800}}'`
mem=${free_mem}/3*2
if (( $mem > $default_mem || $mem < $min_mem )) ; then mem=$default_mem ; fi
fi
fi
+# create plugins,macro,tmp dirs
+mkdir -p $ij_user_path/plugins
+mkdir -p $ij_user_path/macros
+mkdir -p $ij_user_path/luts
+# create imagej socket-lock directory if non existant
+if [[ ! -d "$ij_tmp" ]] ; then
+ mkdir -p "$ij_tmp"
+ #chmod 777 "$ij_user_path/tmp"
+fi
+
+# Warning on syntax change
+# for var in "$@" ; do
+ #if [[ "$var" == @(-batch|-eval|-macro|-mem|-new|-port|-run|-verbose) ]] ; then
+# if [ $var == @(-batch|-eval|-macro|-mem|-new|-port|-run|-verbose) ] ; then
+# echo "ImageJ command line options have changed!" 1>&2
+# echo "$var is no longer a valid option, type 'imagej -h'" 1>&2
+# echo "for full usage" 1>&2
+# exit 1
+# fi
+# done
+
+# makes symbolik links from shared plugins, macros and luts
+
+ls /usr/share/imagej/plugins | while read p ; do
+ if [ ! -e "$ij_user_path/plugins/$p" ] ; then
+ ln -s /usr/share/imagej/plugins/$p $ij_user_path/plugins/$p
+ fi
+done
+
+ls /usr/share/imagej/macros | while read p; do
+ if [ ! -e "$ij_user_path/macros/$p" ] ; then
+ ln -s "/usr/share/imagej/macros/$p" "$ij_user_path/macros/$p"
+ fi
+done
+
+ls /usr/share/imagej/luts | while read p ; do
+ if [ ! -e "$ij_user_path/luts/$p" ] ; then
+ ln -s /usr/share/imagej/luts/$p $ij_user_path/luts/$p
+ fi
+done
+
+
+
##################### USAGE DESCRIPTION #####################
function usage {
@@ -203,66 +210,11 @@
exit 1
}
-function getFullPath {
- # Return full path to file
- # treats multiple arguments as a single file with spaces
- if (( $# == 0 )) ; then
- echo "error getting full path for '${*}'" 1>&2
- fi
- pwd_getFullPath="$PWD"
- \cd $(dirname "${*}") > /dev/null
- dir_getFullPath="$PWD"
- \cd "$pwd_getFullPath" > /dev/null
- echo "$dir_getFullPath"/$(basename "${*}")
-}
-function derefln {
- # Returns the full path of file to which link points
- # following multiple levels of symbolic links.
- # NOTE: if you use this function in a script, don't use any
- # of the variable names used here
- if (( $# == 0 )) ; then
- return
- fi
- local the_link="$1"
- local link_dir
- local current_dir="$PWD"
- while file "$the_link" | grep symbolic > /dev/null ; do # resolve links until target is regular file
- if [[ "$the_link" == */* ]] ; then # path contains /
- \cd $(dirname "${the_link}") > /dev/null
- the_link=$(basename "$the_link")
- fi
- link_dir="$PWD"
- # some versions of 'file' surround the path in `' quotes, hence the tr to remove them
- the_link=$(file "${the_link}" | awk '/symbolic link/ {print $NF}' | tr -d "\140\047" )
- if [[ "$the_link" != /* ]] ; then # path is not absolute path - make it one
- the_link="$link_dir/$the_link"
- fi
- \cd "$current_dir" > /dev/null
- done
- echo $the_link
-}
-
-
# The best way to install .jar libraries required by plugins is to copy them
-# to the imagej plugins/jars directory
-# Alternatively, either copy them to ${ij_path}/jre/lib/ext/ or add the .jar
+# to the imagej ij_path=/usr/share/java alternatively or add the .jar
# filepath to the modules line below. Paths are separated by a colon
-# Classpath must follow command line arguments, as ij_path is dependent on the -d option
-
-# Resolving ij.jar path. If ij.jar is a symbolic link to ij_<version>.jar
-# this allows updating ij.jar without crashing running sessions
-ij_jar_path=$(derefln ${ij_path}/ij.jar)
-
-for mod_jar in ${ij_path}/lib/*jar ; do
- modules="${modules:-}${modules+:}$mod_jar"
-done
-modules="-cp ${ij_jar_path}:${modules+:}${modules:-}"
-#${ij_path}/plugins/jars/dcmie.jar
-
-export LD_LIBRARY_PATH="${ij_path}/lib/${OS}_$processor"
-if (( $verbosity > 0 )) ; then
- echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
-fi
+# modules="-cp ${ij_path}/ij.jar:${ij_path}/plugins/jars/dcmie.jar"
+modules="-cp ${ij_path}/ij.jar"
# enable plugins to be compiled in imagej
tools="$JAVA_HOME/lib/tools.jar"
@@ -270,16 +222,14 @@
##################### ARGUMENTS PARSING #####################
-while getopts b:cde:hi:m:nop:r:vx: options
+while getopts b:ce:hi:m:op:r:vx: options
do
case $options in
b) if [[ -n "$macrocmd" ]] ; then macroCmdError ; fi
macrocmd="-batch ${OPTARG}"
;;
- c) modules="${modules:-}${modules+:}${tools}"
+ c) modules="${modules}:${tools}"
;;
- d) ij_path="$ij_path_dev"
- ;;
e) if [[ -n "$macrocmd" ]] ; then macroCmdError ; fi
macrocmd='-eval'
macroargs="'${OPTARG}'"
@@ -292,8 +242,6 @@
m) if [[ -n "$macrocmd" ]] ; then macroCmdError ; fi
macrocmd="-macro ${OPTARG}"
;;
- n) newwindow='true'
- ;;
o) newwindow='false'
;;
p) newwindow='false'
@@ -312,7 +260,6 @@
if (( $verbosity == 3 )) ; then set -v ; fi
;;
x) mem="${OPTARG}"
- newwindow='true'
if (( $mem < $min_mem || $mem > $max_mem )) ; then
echo "${OPTARG} is not a permissible value for memory (-x)" 1>&2
echo "min=${min_mem}, max=${max_mem}" 1>&2
@@ -325,7 +272,6 @@
esac
done
-
declare -i i=1
while (( i < $OPTIND )) ; do
shift
@@ -351,46 +297,26 @@
macroargs="'$macroargs'"
fi
-# PROTECT POSSIBLE SPACES IN IMAGE FILENAMES
+# protect possible spaces in image filenames
if (( "$#" > 0 )) ; then
while (( "$#" > 0 )) ; do
- filearg="${1}"
- # full file path required when sending images to running ImageJ panel
- if [[ "${newwindow}" == 'false' && -f "${filearg}" ]] && ! expr "${filearg}" : '/.*' > /dev/null; then
- filearg="$(getFullPath ${filearg})"
- fi
- images="${images}'$filearg' "
+ images="${images}'${1}' "
shift
done
-fi
+fi
##################### USING PORT #####################
-# CREATE IMAGEJ SOCKET-LOCK DIRECTORY IF NON EXISTANT
-if [[ ! -d "$ij_tmp" ]] ; then
- mkdir "$ij_tmp"
- chmod 777 "$ij_tmp"
-fi
-
-# CREATE IMAGEJ LOG FILE IF NON EXISTANT
-if [[ -n "$ij_log" && ! -f "$ij_log" ]] ; then
- touch "$ij_log"
- chmod 666 "$ij_log"
-fi
-
-# CREATES A TEMP FILE INDICATING A PORT IS IN USE BY IMAGEJ
-cd "$ij_tmp"
+# Creates a temp file indicating a port is in use by imagej
+pushd "$ij_tmp" > /dev/null
declare -i count=1
portopen='false'
lockFileCreated='false'
declare -a locklist=(`ls | grep '[0-9][0-9]-.*'`)
-[[ -n "$ij_log" ]] && echo -e "$$\t$(date)\tNew Window = $newwindow" >> "$ij_log" 2> /dev/null
-[[ -n "$ij_log" ]] && echo -e "$$\t$(date)\tPort = $port" >> "$ij_log" 2> /dev/null
-[[ -n "$ij_log" ]] && echo -e "$$\t$(date)\tlocklist: \n ${locklist[*]}" >> "$ij_log" 2> /dev/null
if (( $verbosity > 0 )) ; then echo -e "locklist: \n ${locklist[*]}" ; fi
-# PORT SPECIFIED BY USER
+# port specified by user
if (( $port > 0 )) ; then
# look for a lock on the port specified
for lockname in ${locklist[*]} ; do
@@ -401,7 +327,7 @@
if (( $verbosity > 0 )) ; then echo "Using socket lock: $lockname" ; fi
count=$port
break
- elif [[ "$lockname" == ${prefix}-* ]] ; then
+ elif ("$lockname" =~ ${prefix}-* ) ; then
echo "Port $port is in use by some other user or a different host" 1>&2
if (( $verbosity > 0 )) ; then echo "Port lock: $lockname" ; fi
exit 1
@@ -410,7 +336,7 @@
# specified port not in use
count=$port
-# IF EXISTING WINDOW IS REQUESTED, LOOK FOR LISTENING PORT
+# If existing window is requested, look for listening port
elif [[ "$newwindow" == 'false' && ${#locklist} != 0 ]] ; then
# look for a lock on the current display for this user
for lockname in ${locklist[*]} ; do
@@ -425,7 +351,7 @@
done
fi
-# IF A NEW PORT IS TO BE USED
+# if a new port is to be used
if [[ "$portopen" == 'false' ]] ; then
# new window requested or no matching port found
# if port is not specified, look for first free port
@@ -450,14 +376,12 @@
done
fi
fi
- # CREATING A NEW PORT LOCK
+ # creating a new port lock
prefix=`printf '%02u' $count`
lockname=${prefix}-${user}-${host}-${display}
-
- [[ -n "$ij_log" ]] && echo -e "$$\t$(date)\tCreating lock\t$lockname" >> "$ij_log" 2> /dev/null
if (( $verbosity > 0 )) ; then echo -n "creating lock $lockname ... " ; fi
touch $lockname
- trap '\rm -f ${ij_tmp}/$lockname >/dev/null ; echo -e "$$\t$(date)\tReleasing lock\t$lockname" >> "$ij_log" 2> /dev/null' EXIT TERM KILL
+ trap '\rm -f ${ij_tmp}/$lockname >/dev/null ; exit 1' EXIT TERM
# Quitting ImageJ sends EXIT, as does a kill/kill -9
# CTRL+C in terminal sends INT + EXIT
# System shutdown sends TERM (+EXIT??)
@@ -465,25 +389,31 @@
if (( $verbosity > 0 )) ; then echo 'done' ; fi
lockFileCreated='true'
- if [[ -z "$macrocmd" ]] ; then
- echo 'Open other images in this ImageJ panel as follows:'
- echo " imagej -p $count <image1> [<image2> ... <imageN>]"
- fi
- [[ -n "$ij_log" ]] && echo -e "$$\t$(date)\tSocket lock:\t$lockname" >> "$ij_log" 2> /dev/null
+ echo 'Open other images in this ImageJ panel as follows:'
+ echo " imagej -p $count <image1> [<image2> ... <imageN>]"
if (( $verbosity > 0 )) ; then echo "Socket lock: $lockname" ; fi
echo
fi
+# Report number of port locks - more than 50 may indicate error in this script
+if [[ $count -gt 50 && $port == 0 && "$ijadmin" != '' ]] ; then
+mail -s "ImageJ ports on $host" $ijadmin << EOF
+Port locks on $host reached $count
+EOF
+fi
+
##################### FINALLY RUN IMAGEJ #####################
-#popd > /dev/null
+popd > /dev/null
+jni=-Djava.library.path=$(cat /usr/share/imagej/jni/* | tr '\n' ':')
+
if [ "$JAVA_HOME" ] ; then
if (( $verbosity > 0 )) ; then
echo ${modules}
- echo $JAVA_HOME/bin/java ${java_arch} -mx${mem}m ${modules} ij.ImageJ -ijpath ${ij_user_path} -port${count} ${images} ${macrocmd} ${macroargs}
+ echo $JAVA_HOME/bin/java ${arch} -mx${mem}m ${jni} ${modules} ij.ImageJ -ijpath ${ij_user_path} -port${count} ${images} ${macrocmd} ${macroargs}
else
- eval $JAVA_HOME/bin/java ${java_arch} -mx${mem}m ${modules} ij.ImageJ -ijpath ${ij_user_path} -port${count} ${images} ${macrocmd} ${macroargs}
+ eval $JAVA_HOME/bin/java ${arch} -mx${mem}m ${jni} ${modules} ij.ImageJ -ijpath ${ij_user_path} -port${count} ${images} ${macrocmd} ${macroargs}
fi
else
echo "No JVM found to run ImageJ"
More information about the debian-med-commit
mailing list