Skip to content

Instantly share code, notes, and snippets.

@dengemann
Created October 21, 2013 16:42
Show Gist options
  • Save dengemann/7086909 to your computer and use it in GitHub Desktop.
Save dengemann/7086909 to your computer and use it in GitHub Desktop.
#!/bin/sh -ef
#
# Setup script for MNE software
#
#
# Copyright 2009
#
# Nick Schmansky
# Athinoula A. Martinos Center for Biomedical Imaging
# Massachusetts General Hospital
# Charlestown, MA, USA
#
# $Id: mne_setup_mne 2902 2009-10-31 23:00:23Z nicks $
#
OS=`uname -s`
PROC=`uname -p`
#
# check for MNE_ROOT and MATLAB_ROOT and exit if not found
#
if [ ! "$MNE_ROOT" ] ; then
echo "ERROR: The environment variable MNE_ROOT is not defined!"
echo " Set MNE_ROOT to the directory where MNE is installed."
return 1
fi
if [ ! -e "$MNE_ROOT" ] ; then
echo "ERROR: $MNE_ROOT "
echo " does not exist. Check that this value is correct.";
return 1
fi
if [ "$MATLAB_ROOT" ] ; then
if [ ! -e "$MATLAB_ROOT" ] ; then
echo "ERROR: $MATLAB_ROOT "
echo " does not exist. Check that this value is correct.";
return 1
fi
fi
echo ""
echo "MNE software location set to: $MNE_ROOT"
if [ "$MATLAB_ROOT" ] ; then
echo "MATLAB software location set to: $MATLAB_ROOT"
else
echo "MATLAB software not available"
fi
echo ""
#
# add MNE_ROOT/bin to path
#
MNE_BIN_PATH=$MNE_ROOT/bin
export MNE_BIN_PATH
echo $PATH | grep $MNE_BIN_PATH > /dev/null
if [ $? == 0 ] ; then
echo "$MNE_BIN_PATH already in PATH"
else
PATH="$MNE_BIN_PATH":$PATH
export PATH
echo "$MNE_BIN_PATH added to PATH"
fi
#
# add MNE_ROOT/lib to (DY)LD_LIBRARY_PATH
#
command_exists () {
type "$1" &> /dev/null ;
}
MNE_LIB_PATH=$MNE_ROOT/lib
export MNE_LIB_PATH
if [ "x$OS" == "xLinux" ] ; then
if [ ! "$LD_LIBRARY_PATH" ] ; then
LD_LIBRARY_PATH=$MNE_LIB_PATH
else
LD_LIBRARY_PATH="$MNE_LIB_PATH":"$LD_LIBRARY_PATH"
fi
export LD_LIBRARY_PATH
echo "${MNE_LIB_PATH} added to LD_LIBRARY_PATH"
elif [ "x$OS" == "xDarwin" ] ; then
set_dyld_path=0
if command_exists brew ; then
brew_loc=$(command -v brew)
echo Brew install detected at: ${brew_loc}
if ! brew list | grep libquicktime &> /dev/null; then
echo '... please consider installing libquicktime';
set_dyld_path=1
fi
if ! brew list | grep gfortran &> /dev/null; then
echo '... please consider installing gfortran';
set_dyld_path=1
fi
else
set_dyld_path=1
fi
if [[ set_dyld_path == 1 ]]; then
echo falling back to shipped libraries
if [ ! "$DYLD_LIBRARY_PATH" ] ; then
DYLD_LIBRARY_PATH=$MNE_LIB_PATH
else
DYLD_LIBRARY_PATH="$MNE_LIB_PATH":"$DYLD_LIBRARY_PATH"
fi
export DYLD_LIBRARY_PATH
echo "${MNE_LIB_PATH} added to DYLD_LIBRARY_PATH"
else
echo using librarries from brew
fi
fi
#
# add XUSERFILESEARCHPATH so that mne_analyze and mne_browse_raw
# can find their defaults files (MneAnalyze and MneBrowse)
#
APPDEF="${MNE_ROOT}/share/app-defaults/%N"
if [ ! "$XUSERFILESEARCHPATH" ] ; then
XUSERFILESEARCHPATH="${APPDEF}"
else
XUSERFILESEARCHPATH="${XUSERFILESEARCHPATH}":"${APPDEF}"
fi
export XUSERFILESEARCHPATH
echo "${APPDEF} added to XUSERFILESEARCHPATH"
#
# note: setup of matlab lib dir to (DY)LD_LIBRARY_PATH is performed
# independently by wrapper scripts where needed to avoid polluting the
# environment with (DY)LD_LIBRARY_PATH paths (eg. libtiff problems)
#
if [ "$MATLAB_ROOT" ] ; then
#
# add matlab files to matlab search path
#
SUF=$HOME/matlab/startup.m
if [ ! -e $SUF ] ; then
echo "INFO: $SUF does not exist ... creating"
mkdir -p ~/matlab
touch $SUF
echo "%---------------------- MNE --------------------------%" >> $SUF
echo "mnehome = getenv('MNE_ROOT');" >> $SUF
echo "mnematlab = sprintf('%s/share/matlab',mnehome);" >> $SUF
echo "if (exist(mnematlab) == 7)" >> $SUF
echo " path(path,mnematlab);" >> $SUF
echo "end" >> $SUF
echo "clear mnehome mnematlab;" >> $SUF
echo "%-----------------------------------------------------%" >> $SUF
echo "" >> $SUF
fi
tmp1=`grep MNE_ROOT $SUF | wc -l`;
if [ $tmp1 == 0 ] ; then
echo ""
echo "WARNING: The $SUF file does not appear to be";
echo " configured correctly. You may not be able"
echo " to access the MNE Matlab toolbox.";
echo "Try adding the following lines to $SUF"
echo "%---------------------- MNE --------------------------%"
echo "mnehome = getenv('MNE_ROOT');"
echo "mnematlab = sprintf('%s/share/matlab',mnehome);"
echo "if (exist(mnematlab) == 7)"
echo " path(path,mnematlab);"
echo "end"
echo "clear mnehome mnematlab;"
echo "%-----------------------------------------------------%"
echo ""
fi
fi
#
# Just a friendly reminder
#
echo ""
echo "Note: Remember to set SUBJECTS_DIR and SUBJECT environment variables correctly."
echo "Note: FreeSurfer environment is needed to access tkmedit from mne_analyze."
echo ""
return 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment