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