content: FROM ghcr.io/fcp-indi/c-pac/ubuntu:xenial-20200114 AS FreeSurfer
  
  USER root
  
  # install FreeSurfer
  RUN curl -sSL https://surfer.nmr.mgh.harvard.edu/pub/dist/freesurfer/6.0.1/freesurfer-Linux-centos6_x86_64-stable-pub-v6.0.1.tar.gz | tar zxv --no-same-owner -C /opt \
      --exclude='freesurfer/diffusion' \
      --exclude='freesurfer/docs' \
      --exclude='freesurfer/fsfast' \
      --exclude='freesurfer/lib/cuda' \
      --exclude='freesurfer/lib/qt' \
      --exclude='freesurfer/matlab' \
      --exclude='freesurfer/mni/share/man' \
      --exclude='freesurfer/subjects/fsaverage_sym' \
      --exclude='freesurfer/subjects/fsaverage3' \
      --exclude='freesurfer/subjects/fsaverage4' \
      --exclude='freesurfer/subjects/cvs_avg35' \
      --exclude='freesurfer/subjects/cvs_avg35_inMNI152' \
      --exclude='freesurfer/subjects/bert' \
      --exclude='freesurfer/subjects/lh.EC_average' \
      --exclude='freesurfer/subjects/rh.EC_average' \
      --exclude='freesurfer/subjects/sample-*.mgz' \
      --exclude='freesurfer/subjects/V1_average' \
      --exclude='freesurfer/trctrain'
  ENV FSL_DIR="/usr/share/fsl/5.0" \
      OS="Linux" \
      FS_OVERRIDE=0 \
      FIX_VERTEX_AREA="" \
      FSF_OUTPUT_FORMAT="nii.gz" \
      FREESURFER_HOME="/opt/freesurfer"
  ENV SUBJECTS_DIR="$FREESURFER_HOME/subjects" \
      FUNCTIONALS_DIR="$FREESURFER_HOME/sessions" \
      MNI_DIR="$FREESURFER_HOME/mni" \
      LOCAL_DIR="$FREESURFER_HOME/local" \
      MINC_BIN_DIR="$FREESURFER_HOME/mni/bin" \
      MINC_LIB_DIR="$FREESURFER_HOME/mni/lib" \
      MNI_DATAPATH="$FREESURFER_HOME/mni/data"
  ENV PERL5LIB="$MINC_LIB_DIR/perl5/5.8.5" \
      MNI_PERL5LIB="$MINC_LIB_DIR/perl5/5.8.5" \
      PATH="$FREESURFER_HOME/bin:$FSFAST_HOME/bin:$FREESURFER_HOME/tktools:$MINC_BIN_DIR:$PATH"
  
  # Link libraries for Singularity images
  RUN ldconfig
  
  RUN apt-get clean && \
      apt-get autoremove -y && \
      rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
  
  # Just keep what we need
  FROM scratch
  LABEL org.opencontainers.image.description "NOT INTENDED FOR USE OTHER THAN AS A STAGE IMAGE IN A MULTI-STAGE BUILD \
  FreeSurfer 6.0.1 stage"
  LABEL org.opencontainers.image.source https://github.com/FCP-INDI/C-PAC
  COPY --from=FreeSurfer /opt/freesurfer /opt/freesurfer
  
  # set user
  USER c-pac_user
  