|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +## Source of the installation file https://github.com/rocker-org/rocker-versioned2/blob/master/scripts/install_R_source.sh |
| 4 | +## Install R from source. |
| 5 | +## |
| 6 | +## In order of preference, first argument of the script, the R_VERSION variable. |
| 7 | +## ex. latest, devel, patched, 4.0.0 |
| 8 | +## |
| 9 | +## 'devel' means the prerelease development version (Latest daily snapshot of development version). |
| 10 | +## 'patched' means the prerelease patched version (Latest daily snapshot of patched version). |
| 11 | + |
| 12 | +set -e |
| 13 | + |
| 14 | +R_VERSION=${1:-${R_VERSION:-"latest"}} |
| 15 | +PURGE_BUILDDEPS=${PURGE_BUILDDEPS:-"true"} |
| 16 | + |
| 17 | +# shellcheck source=/dev/null |
| 18 | +source /etc/os-release |
| 19 | + |
| 20 | +apt-get update |
| 21 | +apt-get -y install locales |
| 22 | + |
| 23 | +## Configure default locale |
| 24 | +LANG=${LANG:-"en_US.UTF-8"} |
| 25 | +/usr/sbin/locale-gen --lang "${LANG}" |
| 26 | +/usr/sbin/update-locale --reset LANG="${LANG}" |
| 27 | + |
| 28 | +export DEBIAN_FRONTEND=noninteractive |
| 29 | + |
| 30 | +R_HOME=${R_HOME:-"/usr/local/lib/R"} |
| 31 | + |
| 32 | +READLINE_VERSION=8 |
| 33 | +if [ "${UBUNTU_CODENAME}" == "bionic" ]; then |
| 34 | + READLINE_VERSION=7 |
| 35 | +fi |
| 36 | + |
| 37 | +apt-get install -y --no-install-recommends \ |
| 38 | + bash-completion \ |
| 39 | + ca-certificates \ |
| 40 | + file \ |
| 41 | + fonts-texgyre \ |
| 42 | + g++ \ |
| 43 | + gfortran \ |
| 44 | + gsfonts \ |
| 45 | + libblas-dev \ |
| 46 | + libbz2-* \ |
| 47 | + libcurl4 \ |
| 48 | + "libicu[0-9][0-9]" \ |
| 49 | + liblapack-dev \ |
| 50 | + libpcre2* \ |
| 51 | + libjpeg-turbo* \ |
| 52 | + libpangocairo-* \ |
| 53 | + libpng16* \ |
| 54 | + "libreadline${READLINE_VERSION}" \ |
| 55 | + libtiff* \ |
| 56 | + liblzma* \ |
| 57 | + libxt6 \ |
| 58 | + make \ |
| 59 | + tzdata \ |
| 60 | + unzip \ |
| 61 | + zip \ |
| 62 | + zlib1g |
| 63 | + |
| 64 | +BUILDDEPS="curl \ |
| 65 | + default-jdk \ |
| 66 | + devscripts \ |
| 67 | + libbz2-dev \ |
| 68 | + libcairo2-dev \ |
| 69 | + libcurl4-openssl-dev \ |
| 70 | + libpango1.0-dev \ |
| 71 | + libjpeg-dev \ |
| 72 | + libicu-dev \ |
| 73 | + libpcre2-dev \ |
| 74 | + libpng-dev \ |
| 75 | + libreadline-dev \ |
| 76 | + libtiff5-dev \ |
| 77 | + liblzma-dev \ |
| 78 | + libx11-dev \ |
| 79 | + libxt-dev \ |
| 80 | + perl \ |
| 81 | + rsync \ |
| 82 | + subversion \ |
| 83 | + tcl-dev \ |
| 84 | + tk-dev \ |
| 85 | + texinfo \ |
| 86 | + texlive-extra-utils \ |
| 87 | + texlive-fonts-recommended \ |
| 88 | + texlive-fonts-extra \ |
| 89 | + texlive-latex-recommended \ |
| 90 | + texlive-latex-extra \ |
| 91 | + x11proto-core-dev \ |
| 92 | + xauth \ |
| 93 | + xfonts-base \ |
| 94 | + xvfb \ |
| 95 | + wget \ |
| 96 | + zlib1g-dev" |
| 97 | + |
| 98 | +# shellcheck disable=SC2086 |
| 99 | +apt-get install -y --no-install-recommends ${BUILDDEPS} |
| 100 | + |
| 101 | +## Download R from 0-Cloud CRAN mirror or CRAN |
| 102 | +function download_r_src() { |
| 103 | + wget "https://cloud.r-project.org/src/$1" -O "R.tar.gz" || |
| 104 | + wget "https://cran.r-project.org/src/$1" -O "R.tar.gz" |
| 105 | +} |
| 106 | + |
| 107 | +if [ "$R_VERSION" == "devel" ]; then |
| 108 | + download_r_src "base-prerelease/R-devel.tar.gz" |
| 109 | +elif [ "$R_VERSION" == "patched" ]; then |
| 110 | + download_r_src "base-prerelease/R-latest.tar.gz" |
| 111 | +elif [ "$R_VERSION" == "latest" ]; then |
| 112 | + download_r_src "base/R-latest.tar.gz" |
| 113 | +else |
| 114 | + download_r_src "base/R-${R_VERSION%%.*}/R-${R_VERSION}.tar.gz" |
| 115 | +fi |
| 116 | + |
| 117 | +tar xzf "R.tar.gz" |
| 118 | +cd R-*/ |
| 119 | + |
| 120 | +R_PAPERSIZE=letter \ |
| 121 | + R_BATCHSAVE="--no-save --no-restore" \ |
| 122 | + R_BROWSER=xdg-open \ |
| 123 | + PAGER=/usr/bin/pager \ |
| 124 | + PERL=/usr/bin/perl \ |
| 125 | + R_UNZIPCMD=/usr/bin/unzip \ |
| 126 | + R_ZIPCMD=/usr/bin/zip \ |
| 127 | + R_PRINTCMD=/usr/bin/lpr \ |
| 128 | + LIBnn=lib \ |
| 129 | + AWK=/usr/bin/awk \ |
| 130 | + CFLAGS="-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g" \ |
| 131 | + CXXFLAGS="-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g" \ |
| 132 | + ./configure --enable-R-shlib \ |
| 133 | + --enable-memory-profiling \ |
| 134 | + --with-readline \ |
| 135 | + --with-blas \ |
| 136 | + --with-lapack \ |
| 137 | + --with-tcltk \ |
| 138 | + --with-recommended-packages |
| 139 | + |
| 140 | +make |
| 141 | +make install |
| 142 | +make clean |
| 143 | + |
| 144 | +## Add a library directory (for user-installed packages) |
| 145 | +mkdir -p "${R_HOME}/site-library" |
| 146 | +chown root:staff "${R_HOME}/site-library" |
| 147 | +chmod g+ws "${R_HOME}/site-library" |
| 148 | + |
| 149 | +## Fix library path |
| 150 | +echo "R_LIBS=\${R_LIBS-'${R_HOME}/site-library:${R_HOME}/library'}" >>"${R_HOME}/etc/Renviron.site" |
| 151 | + |
| 152 | +## Clean up from R source install |
| 153 | +cd .. |
| 154 | +rm -rf /tmp/* |
| 155 | +rm -rf R-*/ |
| 156 | +rm -rf "R.tar.gz" |
| 157 | + |
| 158 | +## Copy the checkbashisms script to local before remove devscripts package. |
| 159 | +## https://github.com/rocker-org/rocker-versioned2/issues/510 |
| 160 | +cp /usr/bin/checkbashisms /usr/local/bin/checkbashisms |
| 161 | + |
| 162 | +# shellcheck disable=SC2086 |
| 163 | +if [ "${PURGE_BUILDDEPS}" != "false" ]; then |
| 164 | + apt-get remove --purge -y ${BUILDDEPS} |
| 165 | +fi |
| 166 | +apt-get autoremove -y |
| 167 | +apt-get autoclean -y |
| 168 | +rm -rf /var/lib/apt/lists/* |
| 169 | + |
| 170 | +# Check the R info |
| 171 | +echo -e "Check the R info...\n" |
| 172 | + |
| 173 | +R -q -e "sessionInfo()" |
| 174 | + |
| 175 | +echo -e "\nInstall R from source, done!" |
0 commit comments