aboutsummaryrefslogtreecommitdiff
path: root/setup.sh
blob: 689911355c4e523463601d1d9cdcad45ed732c35 (plain)
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
#!/bin/bash
#
# Setup RAPPOR analysis on Ubuntu Trusty (Google Cloud or otherwise).
#
# For the apps/api server, you need 'install-minimal'.  For the regtest, and
# Shiny apps, we need a few more R packages (ggplot2, data.table, etc.).  They
# cause versioning problems, so we keep them separate.
#
# Usage:
#   ./setup.sh [function name]
# If run without specifing any function it will run: install-most 
# which should cover all the packages needed to run the demo.

set -o nounset
set -o pipefail
set -o errexit

native-packages() {
  sudo apt-get update
  # - build-essential for gcc compilers, invoked while installing R packages.
  # - gfortran Fortran compiler needed for glmnet.
  # - libblas-dev needed for limSolve.
  # - python-dev is for building the fastrand extension
  #
  # NOTE: we get R 3.0.2 on Trusty.
  sudo apt-get install build-essential gfortran libblas-dev r-base python-dev graphviz
}

r-packages() {
  # Install as root so you can write to /usr/local/lib/R.

  # glmnet, limSolve: solvers for decode.R
  # RJSONIO, optparse: for decode_dist.R
  # RUnit: for unit tests
  # abind: for decode_test only
  sudo R -e \
    'install.packages(c("glmnet", "optparse", "limSolve", "RUnit", "abind", "RJSONIO"), repos="http://cran.rstudio.com/")'
}

# R 3.0.2 on Trusty is out of date with CRAN, so we need this workaround.
install-plyr-with-friends() {
  mkdir -p _tmp
  wget --directory _tmp \
    http://cran.r-project.org/src/contrib/Archive/Rcpp/Rcpp_0.11.4.tar.gz
  wget --directory _tmp \
    http://cran.r-project.org/src/contrib/Archive/plyr/plyr_1.8.1.tar.gz
  sudo R CMD INSTALL _tmp/Rcpp_0.11.4.tar.gz
  sudo R CMD INSTALL _tmp/plyr_1.8.1.tar.gz 
  sudo R -e \
    'install.packages(c("reshape2", "ggplot2", "data.table"), repos="http://cran.rstudio.com/")'
}

# Keep Shiny separate, since it seems to install a lot of dependencies.
shiny() {
  sudo R -e \
    'install.packages(c("shiny"), repos="http://cran.rstudio.com/")'
}

#
# Batch
#

install-minimal() {
  native-packages
  r-packages
}

# NOTE: hasn't yet been tested on a clean machine.
install-most() {
  install-minimal
  install-plyr-with-friends
}

#
# Shiny Apps / API Server
#

# After running one of the run_app.sh scripts, see if the app returns a page.
shiny-smoke-test() {
  curl http://localhost:6789/
}

# Then set up a "firewall rule" in console.developers.google.com to open up
# "tcp:6789".  Test it from the outside.

if test $# -eq 0 ; then
  install-most
else
  "$@"
fi