1#!/bin/bash 2# 3# Setup RAPPOR analysis on Ubuntu Trusty (Google Cloud or otherwise). 4# 5# For the apps/api server, you need 'install-minimal'. For the regtest, and 6# Shiny apps, we need a few more R packages (ggplot2, data.table, etc.). They 7# cause versioning problems, so we keep them separate. 8# 9# Usage: 10# ./setup.sh [function name] 11# If run without specifing any function it will run: install-most 12# which should cover all the packages needed to run the demo. 13 14set -o nounset 15set -o pipefail 16set -o errexit 17 18native-packages() { 19 sudo apt-get update 20 # - build-essential for gcc compilers, invoked while installing R packages. 21 # - gfortran Fortran compiler needed for glmnet. 22 # - libblas-dev needed for limSolve. 23 # - python-dev is for building the fastrand extension 24 # 25 # NOTE: we get R 3.0.2 on Trusty. 26 sudo apt-get install build-essential gfortran libblas-dev r-base python-dev graphviz 27} 28 29r-packages() { 30 # Install as root so you can write to /usr/local/lib/R. 31 32 # glmnet, limSolve: solvers for decode.R 33 # RJSONIO, optparse: for decode_dist.R 34 # RUnit: for unit tests 35 # abind: for decode_test only 36 sudo R -e \ 37 'install.packages(c("glmnet", "optparse", "limSolve", "RUnit", "abind", "RJSONIO"), repos="http://cran.rstudio.com/")' 38} 39 40# R 3.0.2 on Trusty is out of date with CRAN, so we need this workaround. 41install-plyr-with-friends() { 42 mkdir -p _tmp 43 wget --directory _tmp \ 44 http://cran.r-project.org/src/contrib/Archive/Rcpp/Rcpp_0.11.4.tar.gz 45 wget --directory _tmp \ 46 http://cran.r-project.org/src/contrib/Archive/plyr/plyr_1.8.1.tar.gz 47 sudo R CMD INSTALL _tmp/Rcpp_0.11.4.tar.gz 48 sudo R CMD INSTALL _tmp/plyr_1.8.1.tar.gz 49 sudo R -e \ 50 'install.packages(c("reshape2", "ggplot2", "data.table"), repos="http://cran.rstudio.com/")' 51} 52 53# Keep Shiny separate, since it seems to install a lot of dependencies. 54shiny() { 55 sudo R -e \ 56 'install.packages(c("shiny"), repos="http://cran.rstudio.com/")' 57} 58 59# 60# Batch 61# 62 63install-minimal() { 64 native-packages 65 r-packages 66} 67 68# NOTE: hasn't yet been tested on a clean machine. 69install-most() { 70 install-minimal 71 install-plyr-with-friends 72} 73 74# 75# Shiny Apps / API Server 76# 77 78# After running one of the run_app.sh scripts, see if the app returns a page. 79shiny-smoke-test() { 80 curl http://localhost:6789/ 81} 82 83# Then set up a "firewall rule" in console.developers.google.com to open up 84# "tcp:6789". Test it from the outside. 85 86if test $# -eq 0 ; then 87 install-most 88else 89 "$@" 90fi 91