-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotebook_install_r.sh
executable file
·96 lines (79 loc) · 3.61 KB
/
notebook_install_r.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
#!/bin/bash
# Waits for the system apt daily checks to complete.
# This happens the first time the instance is created/started and certain times per day.
while [[ $(ps aux | grep "root" | grep -i "apt") ]]
do
echo "`date` Waiting for system apt processes to finish..."
sleep 3
done
# Install packages via apt-get.
# Args: package names
# Example: installAptPackages git r-base other-pkg1 other-pkg2
installAptPackages() {
for PACKAGE_NAME in "$@"; do
if ! $(apt -qq list ${PACKAGE_NAME} 2>/dev/null | grep -qE "(installed|upgradeable)"); then
echo ""
echo "==> Installing package: ${PACKAGE_NAME}"
sudo apt-get install -y "${PACKAGE_NAME}"
INSTALL_STATUS=$?
if [ ${INSTALL_STATUS} -ne 0 ]; then
echo "==!> Package install failed. Aborting."
exit 1
fi
fi
done
}
# Install packages via pip.
# Args: pip args.
# Example: installPipPackage csv-schema
installPipPackage() {
echo ""
echo "==> Running: $@"
if ! python -m pip install "$@"; then
echo "==!> Package install failed. Aborting."
exit 1
fi
}
# Execute a command and exit with status 1 if the command fails.
# Args: command to execute
# Example: execOrExit ls -al
execOrExit() {
echo ""
echo "==> Running: $@"
if ! "$@"; then
echo "==!> Command Failed, aborting: $@"
exit 1
fi
}
execOrExit sudo apt-get update
# Install random dependencies for R and R packages etc.
installAptPackages gnupg2 gnupg libfreetype6-dev dirmngr apt-transport-https ca-certificates software-properties-common libxml2-dev libcurl4-openssl-dev libssl-dev cmake
# Install two helper packages we need
execOrExit sudo apt-get install --no-install-recommends software-properties-common dirmngr
# Add the signing key (by Michael Rutter) for these repos
# To verify key, run gpg --show-keys /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
# Fingerprint: 298A3A825C0D65DFD57CBB651716619E084DAB9
wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
# Add the R 4.0 repo from CRAN -- adjust 'focal' to 'groovy' or 'bionic' as needed
execOrExit sudo add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/"
# Upgrade R
execOrExit rm -rf ~/R
installAptPackages r-base
installAptPackages build-essential
execOrExit sudo Rscript -e 'update.packages(ask=FALSE, checkBuilt=TRUE)'
R --version
# Re-Install packages for R 4.x -- TODO: This might not be working completely.
execOrExit sudo Rscript -e 'install.packages("codetools", repos = "https://cloud.r-project.org")'
execOrExit sudo Rscript -e 'install.packages("colorspace", repos = "https://cloud.r-project.org")'
execOrExit sudo Rscript -e 'install.packages("munsell", repos = "https://cloud.r-project.org")'
execOrExit sudo Rscript -e 'install.packages("scales", repos = "https://cloud.r-project.org")'
execOrExit sudo Rscript -e 'install.packages("Rcpp", repos = "https://cloud.r-project.org")'
execOrExit sudo Rscript -e 'install.packages("pkgload", repos = "https://cloud.r-project.org")'
execOrExit sudo Rscript -e 'install.packages("ggplot2", repos = "https://cloud.r-project.org")'
# Install tidyverses
execOrExit sudo Rscript -e 'install.packages("tidyverse", repos = "https://cloud.r-project.org")'
execOrExit sudo Rscript -e 'Sys.setenv(ARROW_S3 ="ON"); install.packages("arrow", repos = "https://cloud.r-project.org")'
# Install synapser R package
execOrExit sudo Rscript -e 'install.packages("synapser", repos=c("http://ran.synapse.org", "http://cran.fhcrc.org"))'
# Install reticulate
execOrExit sudo Rscript -e 'install.packages("reticulate", repos = "https://cloud.r-project.org")'