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
|
APXS <- commandArgs(trailingOnly=TRUE)[1]
HTTPD <- commandArgs(trailingOnly=TRUE)[2]
options(warn=-1)
NextAvailablePort <- function(){
start <- 8181
while(TRUE){
if (start >= 65536) return(0)
con <- try(socketConnection(port=start),silent=TRUE)
if (inherits(con,'try-error')){
return(start)
}
close(con)
start <- start + 1
}
}
#
# Variables that will get replaced in httpd.conf.in
#
DOCROOT <- paste(getwd(),'/test',sep='')
PORT <- NextAvailablePort()
BREWINSTALLED <- 'brew' %in% .packages(all.available=TRUE)
unlink('test/httpd.conf')
con <- file('test/httpd.conf',open='w+')
lines <- readLines('test/httpd.conf.in')
if (BREWINSTALLED){
lines <- append(lines,c(
'<Directory @DOCROOT@/brew>\n',
' SetHandler r-script\n',
' RHandler brew::brew\n',
'</Directory>\n') )
}
lines <- gsub('@PORT@',PORT,lines)
lines <- gsub('@DOCROOT@',DOCROOT,lines)
writeLines(lines,con)
close(con)
unlink('test/confs/load_modules')
# Test if dir module is compiled into httpd
if (length(grep('dir',readLines(pipe(paste(HTTPD,'-l')))))==0){
# No, we need to add it. grab LIBEXECDIR
con <- file('test/confs/load_modules',open='a')
libexecdir <- readLines(pipe(paste(APXS,'-q LIBEXECDIR')))[1]
cat('LoadModule dir_module ',libexecdir,'/mod_dir.so\n',sep='',file=con)
close(con)
} else {
print('mod_dir built in')
}
# Test if log_config module is compiled into httpd
if (length(grep('log_config',readLines(pipe(paste(HTTPD,'-l')))))==0){
# No, we need to add it. grab LIBEXECDIR
con <- file('test/confs/load_modules',open='a')
libexecdir <- readLines(pipe(paste(APXS,'-q LIBEXECDIR')))[1]
cat('LoadModule log_config_module ',libexecdir,'/mod_log_config.so\n',sep='',file=con)
close(con)
} else {
print('mod_log_config built in')
}
# Test if mime module is compiled into httpd
if (length(grep('mime',readLines(pipe(paste(HTTPD,'-l')))))==0){
# No, we need to add it. grab LIBEXECDIR
con <- file('test/confs/load_modules',open='a')
libexecdir <- readLines(pipe(paste(APXS,'-q LIBEXECDIR')))[1]
cat('LoadModule mime_module ',libexecdir,'/mod_mime.so\n',sep='',file=con)
close(con)
} else {
print('mod_mime built in')
}
|