-
Notifications
You must be signed in to change notification settings - Fork 0
/
pkg-update
executable file
·111 lines (81 loc) · 1.79 KB
/
pkg-update
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/sh
#
FILENAME="REPOSITORIES"
DEST="dest"
SRCPATH="src/contrib"
LOG=update_repo.log
# this script generates PACKAGES and PACKAGES.gz files
VERSION_SCRIPT="writeLines(paste(version\$major, version\$minor, sep='.'))"
PACKAGES_SCRIPT="setwd('$DEST'); tools:::write_PACKAGES()"
#
function log {
local DATE=$(date -jn "+[%H:%M:%S %D]")
if [ $2 ]
then
echo $DATE "$1" >> $2
else
echo $DATE "$1"
fi
}
# Get R's version number
VERSION=$(echo $VERSION_SCRIPT | /usr/bin/R --vanilla --slave | sed -e "s/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)/\1.\2/g")
echo "Zelig Build started up on $(date)" >> $LOG
echo " * R version $VERSION" >> $LOG
echo " * $(git --version)" >> $LOG
echo >> $LOG
if [ -d TMP ]
then
log "removing TMP directory" $LOG
rm -fr TMP
fi
# git-clone from all watched git repositories
# build them in R
#
while read LINE
do
log "$LINE" $LOG
# git-clone
git clone $LINE TMP
# error-catching for git clone
if [ $? != 0 ]
then
log " * git clone failed" $LOG
log " * not attempting an R build" $LOG
echo >> $LOG
continue
else
log " * git clone succeed" $LOG
fi
echo
# Build with R
R CMD build TMP
# error-catching for R CMD build
if [ $? != 0 ]
then
log " * R Build failed" $LOG
else
log " * R build succeed" $LOG
fi
# clean-up
if [ -d TMP ]
then
log " * removing TMP" $LOG
rm -fr TMP
fi
# aesthetics
echo
echo >> $LOG
done < $FILENAME
# Make destination directory if it doesn't exist
if [ ! -d $DEST ]
then
log "Making destination folder: $DEST" $LOG
mkdir $DEST
fi
# Move files to destination
log "Moving packages to destination folder" $LOG
mv -f *.tar.gz $DEST
# Execute R Script
log "Create \"PACKAGES\" file" $LOG
echo $PACKAGES_SCRIPT | /usr/bin/R --vanilla --slave
echo "\n" >> $LOG