Skip to content

Commit

Permalink
fix up bootstrap; support both online and offline mode
Browse files Browse the repository at this point in the history
  • Loading branch information
s-u authored and gordonwoodhull committed Nov 3, 2014
1 parent b7e0b60 commit e68cb34
Showing 1 changed file with 82 additions and 21 deletions.
103 changes: 82 additions & 21 deletions scripts/bootstrapR.sh
Original file line number Diff line number Diff line change
@@ -1,38 +1,99 @@
#!/bin/sh

if [ x"$1" = 'x-h' ]; then
echo ''
echo " Usage: $0 [--mk-dist]"
echo ''
echo ' This script must be run from the RCloud root directory and it'
echo ' installs R packages needed by RCloud in the R installation'
echo ''
echo ' Optional environment variables:'
echo ' RBIN - location of the R executable [R]'
echo ' RCREPO - repository of RCloud packages [<RCloud>/packages]'
echo ' DISTREP - distribution repository [<RCloud>/dist-repos]'
echo ''
echo ' If DISTREP exists, it will be used to bootstrap R without using'
echo " remote repositories. If it doesn't exist, packages from RCREPO"
echo ' are used along with dependencies from remote repositories.'
echo " If RCREPO doesn't exist, it is created from the source tree."
echo ''
echo ' DISTREP can be created using --mk-dist in which case it'
echo ' is built from sources and remote repositories'
echo ''
exit 0
fi

WD=`pwd`
if [ ! -e "$WD/../pkg.repos/src/contrib/PACKAGES" ]; then
echo '' 2>&1
if [ -e "$WD/rcloud.support/DESCRIPTION" ]; then
mkdir -p "$WD/packages/src/contrib" 2>/dev/null
echo " -- building RCloud packages repository"
( cd "$WD/packages/src/contrib"; for src in `ls $WD/rcloud.*/DESCRIPTION $WD/rcloud.packages/*/DESCRIPTION $WD/packages/*/DESCRIPTION 2>/dev/null`; do R CMD build `dirname "$src"`; done )
echo "tools:::write_PACKAGES('$WD/packages/src/contrib'); install.packages(unique(gsub('_.*','',basename(Sys.glob('$WD/packages/src/contrib/*.tar.gz')))),repos=c('file://$WD/packages','http://r.research.att.com','http://rforge.net'),type='source')" | R --vanilla --slave --no-save
exit 0
else
echo ' ERROR: you must run this script from the RCloud root directory!' 2>&1
fi
echo '' 2>&1

if [ ! -e "$WD/rcloud.support/DESCRIPTION" ]; then
echo ' ERROR: you must run this script from the RCloud root directory!' 1>&2
exit 1
fi

ok=`echo 'if(R.version$major>=3)cat("OK\n")' | R --slave --vanilla`
: ${RCREPO="$WD/packages"}
: ${DISTREP="$WD/dist-repos"}
: ${RBIN=R}

ok=`echo 'if(R.version$major>=3)cat("OK\n")' | $RBIN --slave --vanilla`
if [ "x$ok" != "xOK" ]; then
echo '' 2>&1
echo ' ERROR: R is not available in the correct version.' 2>&1
echo '' 2>&1
echo '' 1>&2
echo ' ERROR: R is not available in the correct version.' 1>&2
echo '' 1>&2
exit 1
fi

export RCS_SILENCE_LOADCHECK=TRUE
echo 'cat(sprintf("\n Using %s, installing packages...\n", R.version.string)); url="file://'"$WD"'/../pkg.repos/"; a=rownames(available.packages(paste0(url,"/src/contrib"))); install.packages(a,,url,type="source")' | R --slave --vanilla

mkdist=''
if [ x"$1" = "x--mk-dist" ]; then
mkdist=yes
fi
if [ -n "$mkdist" -o x"$1" = "x--clean" ]; then
echo " --- Cleaning existing repositories"
rm -rf "$DISTREP/src/contrib" "$RCREPO/src/contrib"
fi

if [ ! -e "$DISTREP/src/contrib/PACKAGES" -o -n "$mkdist" ]; then
## we need RCREPO populated in any case
if [ ! -e "$RCREPO/src/contrib/PACKAGES" -o -n "$mkdist" ]; then
echo " --- Creating RCloud repository $RCREPO"
echo '' 1>&2
if ! mkdir -p "$RCREPO/src/contrib"; then
echo "ERROR: cannot create src/contrib in $RCREPO, please set RCREPO if other location is desired" 1>&2
exit 1
fi
echo " Builds RCloud packages"
( cd "$RCREPO/src/contrib"; for src in `ls $WD/rcloud.*/DESCRIPTION $WD/rcloud.packages/*/DESCRIPTION $WD/packages/*/DESCRIPTION 2>/dev/null`; do "$RBIN" CMD build `dirname "$src"`; done )
echo "tools:::write_PACKAGES('$RCREPO/src/contrib')" | "$RBIN" --vanilla --slave --no-save || exit 1
fi

if [ -z "$mkdist" ]; then
## regular boostrap from clean sources - install deps
echo " --- Installing RCloud packages and dependencies in R"
echo "install.packages(unique(gsub('_.*','',basename(Sys.glob('$RCREPO/src/contrib/*.tar.gz')))),repos=c('file://$RCREPO','http://r.research.att.com','http://rforge.net'),type='source')" | "$RBIN" --vanilla --slave --no-save || exit 1
else
## mkdist
if ! mkdir -p "$DISTREP/src/contrib"; then
echo " ERROR: cannot create src/contrib in $DISTREP. please set DISTREP if other location is desired" 1>&2
exit 1
fi
cp -p "$RCREPO/src/contrib/"*.tar.gz "$DISTREP/src/contrib/"
echo "options(warn=2);pkg<-unique(gsub('_.*','',basename(Sys.glob('$RCREPO/src/contrib/*.tar.gz'))));cran=available.packages(contrib.url(c('http://r.research.att.com/','http://rforge.net'),type='source'),type='source');local=available.packages(contrib.url('file://$RCREPO',type='source'),type='source');stage1=unique(unlist(tools:::package_dependencies(pkg,local,'all')));print(stage1);stage2=unique(c(stage1,unlist(tools:::package_dependencies(stage1,rbind(cran,local),,TRUE))));rec=rownames(installed.packages(,'high'));stage2=stage2[!(stage2 %in% rec)];print(stage2);download.packages(stage2,'$DISTREP/src/contrib',,c('http://rforge.net','http://r.research.att.com','file://$RCREPO'),type='source');tools:::write_PACKAGES('$DISTREP/src/contrib')" | "$RBIN" --vanilla --slave || exit 1
echo ''
echo " Distributon packages created in $DISTREP"
exit 0
fi
else
## Installation from a distribution
echo 'cat(sprintf("\n Using %s, installing packages...\n", R.version.string)); url="file://'"$DISTREP/"'"; a=rownames(available.packages(paste0(url,"/src/contrib"))); install.packages(a,,url,type="source")' | "$RBIN" --slave --vanilla
fi

ok=`echo 'library(rcloud.support);library(rcloud.client);library(Cairo);library(rjson);cat("OK\n")' | R --slave --vanilla`
if [ "x$ok" != "xOK" ]; then
echo '' 2>&1
echo ' ERROR: one or more packages could not be installed.' 2>&1
echo ' Please check that you have all necessary dependencies installed' 2>&1
echo '' 2>&1
echo '' 1>&2
echo ' ERROR: one or more packages could not be installed.' 1>&2
echo ' Please check that you have all necessary dependencies installed' 1>&2
echo '' 1>&2
exit 1
fi

Expand Down

0 comments on commit e68cb34

Please sign in to comment.