#!/usr/bin/env bash # This script will update freeview to the current dev version. FREESURFER_HOME must be set. # For ease (but definitely not efficiency), the whole dev release is downloaded to a # temporary dir, and the necessary files are copied to the target distribution. # # NOTE: this script should NOT be installed in the freesurfer release since, by design, it will # always be outdated. Instead, it should be copied to: # # https://surfer.nmr.mgh.harvard.edu/pub/dist/freesurfer/installers/fv # # where users will always be able to access and run the most up-to-date installer via: # # bash <(curl -s https://surfer.nmr.mgh.harvard.edu/pub/dist/freesurfer/installers/fv) # set -e # utility functions function cleanup { if [ -e "$tmpdir" ]; then rm -rf $tmpdir; fi } function errexit { cleanup; echo "ERROR: $1"; exit 1; } function replace { for path in "$@"; do rm -rf $FREESURFER_HOME/$path; mv freesurfer/$path $FREESURFER_HOME/$path; done } # parse arguments for arg in "$@"; do case $arg in -f|--force) force=true ;; -h|--help) echo "Updates freeview. Use the -f flag to force the installation."; exit ;; *) errexit "unknown option $arg" ;; esac done # cleanup temporary directory upon exit/kill trap cleanup EXIT SIGINT SIGTERM # check the FS install if [ -z "$FREESURFER_HOME" ]; then errexit "FREESURFER_HOME has not been defined"; fi if [ ! -e "$FREESURFER_HOME/lib" ]; then errexit "directory $FREESURFER_HOME/lib does not exist - does FREESURFER_HOME point to a valid FreeSurfer install?"; fi if [ ! -e "$FREESURFER_HOME/bin" ]; then errexit "directory $FREESURFER_HOME/bin does not exist - does FREESURFER_HOME point to a valid FreeSurfer install?"; fi # ask before installing if [ ! "$force" = true ]; then echo "This will update the freeview version installed in $FREESURFER_HOME" read -p "Are you sure you want to continue? [Y/n] " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit; fi fi # operating system system="$(uname -s)" # OS independent way to create a temporary directory tmpdir="$(mktemp -d 2>/dev/null || mktemp -d -t 'fstmpdir')" cd $tmpdir # download link for given OS if [ "$system" == "Linux" ]; then link="https://surfer.nmr.mgh.harvard.edu/pub/dist/freesurfer/dev/freesurfer-linux-centos6_x86_64-dev.tar.gz" elif [ "$system" == "Darwin" ]; then link="https://surfer.nmr.mgh.harvard.edu/pub/dist/freesurfer/dev/freesurfer-darwin-OSX-ElCapitan-dev.tar.gz" else errexit "OS $system is not supported" fi echo "Downloading FreeSurfer..." curl -# $link -o freesurfer.tar.gz echo "Uncompressing the download (this might take a while)..." tar -xzf freesurfer.tar.gz echo "Updating..." if [ "$system" == "Linux" ]; then replace bin/freeview bin/qt.conf lib/qt rm -f $FREESURFER_HOME/bin/freeview.bin # old, unnecessary file elif [ "$system" == "Darwin" ]; then replace bin/freeview Freeview.app fi echo "Freeview update complete!"