#!/usr/bin/env bash # script to facilitate easy installation of the matlab runtime package set -e # check arguments if [ "$#" -ne 1 ]; then echo "ERROR: must specify MCR version as argument" echo "EXAMPLE: fs_install_mcr R2014b" exit 1 fi MCR_VER="$1" # check FS directory if [[ -z "$FREESURFER_HOME" ]]; then echo "ERROR: must set FREESURFER_HOME before installing" echo "INFO: if you're using sudo, make sure to pass the FS home variable with" echo "INFO: sudo FREESURFER_HOME=\$FREESURFER_HOME fs_install_mcr $@" exit 1 fi # operate in tmp directory TMP_DIR=$(mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir') cd $TMP_DIR # cleanup tmp directory at exit function cleanup { cd $FREESURFER_HOME rm -rf $TMP_DIR } trap cleanup EXIT if [ "$(uname -s)" == "Linux" ]; then OS_TAG=glnxa64 else OS_TAG=maci64 fi # download the os-specific installer if [[ "$MCR_VER" =~ R2012a|R2012b|R2013a ]]; then curl --location https://ssd.mathworks.com/supportfiles/MCR_Runtime/$MCR_VER/MCR_${MCR_VER}_${OS_TAG}_installer.zip -o installer.zip else curl --location https://ssd.mathworks.com/supportfiles/downloads/$MCR_VER/deployment_files/$MCR_VER/installers/$OS_TAG/MCR_${MCR_VER}_${OS_TAG}_installer.zip -o installer.zip fi unzip installer.zip # run non-interactive installation TMP_DEST_DIR=$TMP_DIR/install-target ./install -mode silent -agreeToLicense yes -destinationFolder $TMP_DEST_DIR # move mcr install to freesurfer directory MCR_DIR="$(ls -d $TMP_DEST_DIR/v*)" MCR_NAME="$(basename $MCR_DIR)" MCR_TARGET_DIR=$FREESURFER_HOME/MCR$MCR_NAME if [ -d "$MCR_TARGET_DIR" ]; then # MCR already installed echo "MCR $MCR_NAME ($MCR_VER) already exists in $FREESURFER_HOME" read -p "do you want to reinstall? [y/n] " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then echo "exiting without install" exit 0 fi rm -rf $MCR_TARGET_DIR fi mv $MCR_DIR $MCR_TARGET_DIR echo "$MCR_VER installed successfully in $MCR_TARGET_DIR"