Skip to content
Permalink
Newer
Older
100755 97 lines (80 sloc) 2.48 KB
Aug 15, 2016
1
#!/bin/bash
2
3
r_pkgs=( DESeq2 genefilter biomaRt ggplot2 gplots RColorBrewer )
Aug 15, 2016
4
pip_pkgs=( biopython )
5
6
if [[ $(id -u) -ne 0 ]]; then
7
echo "Error: run this script as the root user, not EUID $(id -u)."
8
exit 1
9
fi
10
11
set -e # Make most errors fatal.
12
13
ubuntu_update () {
14
apt-get update
15
apt-get -y upgrade
16
}
17
18
ubuntu_install_r_cran () {
19
cat <<EOF > /etc/apt/sources.list.d/cgi-r-cran.list
20
# Newest R version from CRAN per
21
# https://cran.r-project.org/bin/linux/ubuntu/
22
deb https://cran.fhcrc.org/bin/linux/ubuntu $(lsb_release -cs)/
23
EOF
24
local key=E084DAB9
25
grep -q $key <( apt-key list ) ||
26
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys $key
Aug 15, 2016
27
apt-get update
28
apt-get -y install r-base-dev
29
# Dependencies of RCurl:
30
apt-get -y install libxml2-dev libcurl4-gnutls-dev
Aug 15, 2016
31
}
32
33
python_install_packages() {
34
apt-get -y install python-pip python-dev
Aug 15, 2016
35
pip install --upgrade ${pip_pkgs[@]}
36
}
37
38
r_install_packages() {
39
local pkgs=$@
40
pkgs=\"$(printf "\",\"%s" $pkgs)\"
41
Rscript --vanilla - <<EOF
42
options(echo = TRUE)
43
dir.create(Sys.getenv("R_LIBS_USER"), recursive = TRUE)
44
.libPaths(Sys.getenv("R_LIBS_USER"))
45
setwd(paste(Sys.getenv("R_HOME")))
Aug 15, 2016
46
source("https://bioconductor.org/biocLite.R")
47
biocLite(c(${pkgs:3}))
Aug 15, 2016
48
EOF
49
}
50
Aug 15, 2016
51
rstudio_url() {
52
python - <<EOF
53
import urllib2
54
55
from lxml import etree
56
57
# Provide a header to avoid HTTP 403 Forbidden.
58
headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11'}
59
request = urllib2.Request("https://www.rstudio.com/products/rstudio/download2/", headers=headers)
60
response = urllib2.urlopen(request)
61
html = response.read()
62
63
root = etree.HTML(html)
64
urls = root.xpath('.//table[@class="downloads"][1]/tbody/tr/td/a/@href')
65
url = next(url for url in urls if url.endswith('amd64.deb'))
66
print(url)
67
EOF
68
}
69
70
rstudio_install() {
71
url=$(rstudio_url)
72
pkg=$(basename $url)
73
ver_new=$(echo $pkg | awk -vFS=- '{print $2}')
74
ver_old=$(dpkg-query --showformat='${Version}' --show rstudio) || ver_old=
75
if [[ ! $ver_new == $ver_old ]]; then
76
wget -qc $url
77
dpkg -i $pkg
78
fi
79
}
80
Aug 15, 2016
81
main () {
82
ubuntu_update
83
ubuntu_install_r_cran
84
85
python_install_packages
86
87
# Install R libraries in the user home directory so that updating
88
# the libraries later on does not triggering the "unwritable
89
# directory" warning.
90
export -f r_install_packages
91
su cgi_user -c "bash -c \"r_install_packages ${r_pkgs[*]}\""
92
unset r_install_packages
Aug 15, 2016
93
94
rstudio_install
Aug 15, 2016
95
}
96
97
main
You can’t perform that action at this time.