Skip to content
Permalink
e9b932236f
Go to file
 
 
Cannot retrieve contributors at this time
executable file 97 lines (80 sloc) 2.48 KB
#!/bin/bash
r_pkgs=( DESeq2 genefilter biomaRt ggplot2 gplots RColorBrewer )
pip_pkgs=( biopython )
if [[ $(id -u) -ne 0 ]]; then
echo "Error: run this script as the root user, not EUID $(id -u)."
exit 1
fi
set -e # Make most errors fatal.
ubuntu_update () {
apt-get update
apt-get -y upgrade
}
ubuntu_install_r_cran () {
cat <<EOF > /etc/apt/sources.list.d/cgi-r-cran.list
# Newest R version from CRAN per
# https://cran.r-project.org/bin/linux/ubuntu/
deb https://cran.fhcrc.org/bin/linux/ubuntu $(lsb_release -cs)/
EOF
local key=E084DAB9
grep -q $key <( apt-key list ) ||
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys $key
apt-get update
apt-get -y install r-base-dev
# Dependencies of RCurl:
apt-get -y install libxml2-dev libcurl4-gnutls-dev
}
python_install_packages() {
apt-get -y install python-pip python-dev
pip install --upgrade ${pip_pkgs[@]}
}
r_install_packages() {
local pkgs=$@
pkgs=\"$(printf "\",\"%s" $pkgs)\"
Rscript --vanilla - <<EOF
options(echo = TRUE)
dir.create(Sys.getenv("R_LIBS_USER"), recursive = TRUE)
.libPaths(Sys.getenv("R_LIBS_USER"))
setwd(paste(Sys.getenv("R_HOME")))
source("https://bioconductor.org/biocLite.R")
biocLite(c(${pkgs:3}))
EOF
}
rstudio_url() {
python - <<EOF
import urllib2
from lxml import etree
# Provide a header to avoid HTTP 403 Forbidden.
headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11'}
request = urllib2.Request("https://www.rstudio.com/products/rstudio/download2/", headers=headers)
response = urllib2.urlopen(request)
html = response.read()
root = etree.HTML(html)
urls = root.xpath('.//table[@class="downloads"][1]/tbody/tr/td/a/@href')
url = next(url for url in urls if url.endswith('amd64.deb'))
print(url)
EOF
}
rstudio_install() {
url=$(rstudio_url)
pkg=$(basename $url)
ver_new=$(echo $pkg | awk -vFS=- '{print $2}')
ver_old=$(dpkg-query --showformat='${Version}' --show rstudio) || ver_old=
if [[ ! $ver_new == $ver_old ]]; then
wget -qc $url
dpkg -i $pkg
fi
}
main () {
ubuntu_update
ubuntu_install_r_cran
python_install_packages
# Install R libraries in the user home directory so that updating
# the libraries later on does not triggering the "unwritable
# directory" warning.
export -f r_install_packages
su cgi_user -c "bash -c \"r_install_packages ${r_pkgs[*]}\""
unset r_install_packages
rstudio_install
}
main
You can’t perform that action at this time.