Last active
July 31, 2017 13:39
-
-
Save kaczmarj/8e3792ae1af70b03788163c44f453b43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
set +x | |
# This bash script: | |
# 1. adds the CRAN repository | |
# 2. installs R | |
# 3. installs R packages for AFNI | |
# | |
# Should work on most Debian-based Linux distributions. | |
# Based heavily on | |
# https://github.com/Shotgunosine/afni_add_rcran_ubuntu/blob/master/%40add_rcran_ubuntu.tcsh | |
echo "++ Attempting to install R ..." | |
apt-get update -qq | |
apt-get install -yq --no-install-recommends curl dirmngr gnupg | |
source /etc/os-release | |
# Get OS name (e.g., 'debian', 'ubuntu'). | |
OS_NAME="$(echo $NAME | sed 's/ .*//' | tr '[:upper:]' '[:lower:]')" | |
echo "++ OS name is ${OS_NAME}" | |
# Get codename and remove non-alpha characters (but keep spaces). | |
OS_CODENAME="$(echo $VERSION | sed 's/[^A-Z a-z]//g')" | |
# Remove everything except first word, and make lowercase. | |
OS_CODENAME="$(echo $OS_CODENAME | sed 's/ .*//' | tr '[:upper:]' '[:lower:]')" | |
echo "++ OS codename is ${OS_CODENAME}" | |
# Get key. The gpg keys are fetched from DropBox and then updated from the | |
# keyservers. The keyservers can be unreliable for some reason. | |
echo "++ Adding key for CRAN repository ..." | |
if [ "$OS_NAME" == "debian" ]; then | |
CRAN_SUBDIR="${OS_CODENAME}-cran34" | |
apt-key adv --fetch-keys https://dl.dropbox.com/s/28b2hl1mds4ggqx/r-cran-debian.gpg | |
# Syntax from https://github.com/poldracklab/fmriprep/blob/master/Dockerfile#L21 | |
(apt-key adv --refresh-keys --keyserver hkp://pool.sks-keyservers.net E19F5F87128899B192B1A2C2AD5F960A256A04AF || true) | |
elif [ "$OS_NAME" == "ubuntu" ]; then | |
CRAN_SUBDIR="${OS_CODENAME}" | |
apt-key adv --fetch-keys https://dl.dropbox.com/s/i1psi8vbhvvmj97/r-cran-ubuntu.gpg | |
(apt-key adv --refresh-keys --keyserver keyserver.ubuntu.com E084DAB9 || true) | |
fi | |
# Add CRAN sources to sources.list. | |
echo "deb http://cloud.r-project.org/bin/linux/${OS_NAME}/ ${CRAN_SUBDIR}/" | tee --append /etc/apt/sources.list | |
apt-get update -qq | |
echo "++ Removing previously installed R ..." | |
apt-get remove -y r-base r-base-core r-base-dev | |
echo "++ Installing R ..." | |
apt-get install -yq --no-install-recommends r-base-dev | |
# r-cran-rmpi is not available (yet?) on debian stretch. | |
# https://packages.debian.org/jessie/r-cran-rmpi | |
echo "++ Installing the R package Rmpi ..." | |
{ | |
apt-get install -yq --no-install-recommends r-cran-rmpi | |
} || { | |
echo "++ r-cran-rmpi could not be installed with apt-get. Trying a different installation method ..." | |
apt-get install -yq --no-install-recommends mpi-default-bin && | |
curl -sSL -o /tmp/rcranrmpi.deb http://ftp.us.debian.org/debian/pool/main/r/rmpi/r-cran-rmpi_0.6-6-4_amd64.deb && | |
dpkg -i /tmp/rcranrmpi.deb && | |
rm -f /tmp/rcranrmpi.deb | |
} | |
apt-get clean | |
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* | |
echo "++ Finished installing R." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment