f37 -> f39
[infrastructure.git] / scripts / all-modules.sh
1 #!/bin/bash
2
3 # feb 2013 - mainline is now known as 5.2, remove that step in the output
4 # meaning results are now in merely
5 # http://build.onelab.eu/modules/version.html
6 #
7 # reviewed in dec. 2010
8 # moving back to running on the EU side
9
10 # this script is a wrapper around the module-tools (version and diff)
11 # it is invoked cyclically
12 # prior to that, the following directories will have been svn updated :
13 # ~/git-build
14
15 # avoid running several instances of this script
16 # when the svn server has problems, this can very well last quite a while
17
18 COMMAND=$(basename $0)
19
20 # running as root on liquid
21 OUTPUT=/build/modules
22 WWWNAME=mainline
23 LOCK=~/all-modules.run
24 # make sure the cyclic tasks do not interfere with manual usage
25 # (i.e. do not use ~/modules)
26 WORKDIR_GIT=${HOME}/all-modules-git
27 ########## sample config running on liquid
28 #svnpath=http://svn.planet-lab.org/svn/
29 #gitserver=git.onelab.eu
30 #gituser=root
31 #build=build
32 #username=not-needed-as-we-dont-write
33 #email=not-needed-as-we-dont-write
34 ##########
35
36 function do_update() {
37     build_dir=$1; shift
38     if [ -f $build_dir/auto-update.sh ] ; then
39         $build_dir/auto-update.sh
40     elif [ -d $build_dir/.git ] ; then
41         ( cd $build_dir; git pull > .update.log 2>&1 )
42     else
43         ( cd $build_dir; svn update > .update.log 2>&1 )
44     fi
45 }
46
47 # usage: do_version dir workdir 
48 function do_version () {
49     build_dir=$1; shift
50     workdir=$1; shift
51
52     out_dir=$OUTPUT
53     out_file=$out_dir/version.html
54     out_tmp=$out_dir/.version.html
55     
56     mkdir -p $out_dir
57     $build_dir/module-version $VERBOSE -w $workdir --www $WWWNAME -a &> $out_tmp
58     mv -f $out_tmp $out_file
59 }
60
61 # usage: do_diff dir workdir
62 function do_diff () {
63     build_dir=$1; shift
64     workdir=$1; shift
65
66     out_dir=$OUTPUT
67     out_file=$out_dir/diff.html
68     out_tmp=$out_dir/.diff.html
69     
70     mkdir -p $out_dir
71     $build_dir/module-diff $VERBOSE -w $workdir --www $WWWNAME -a &> $out_tmp
72     mv -f $out_tmp $out_file
73
74 }
75
76 function usage () {
77     echo "Usage: $COMMAND [-v] [-f] [-i]"
78 }
79
80 function main () {
81
82     while [[ -n "$@" ]] ; do
83         case "$1" in 
84             -f) rm -f $LOCK ;;
85             -i) ls -l $LOCK ; exit 0 ;;
86             -v) set -x ; VERBOSE=-v ;;
87             *) usage; exit 1;;
88         esac
89         shift
90     done
91
92     # is the stamp older than 2 hours ? 
93     # in minutes
94     GRACE=120
95     is_old=$(find $LOCK -mmin +$GRACE 2> /dev/null)
96     if [ -n "$is_old" ] ; then
97         echo "$LOCK is older than $GRACE minutes - removing"
98         rm -f $LOCK
99     fi
100
101     [ -f $LOCK ] && exit 1
102     
103     echo $$ > $LOCK
104
105     do_update  ~/git-build
106     do_version ~/git-build     $WORKDIR_GIT 
107     do_diff    ~/git-build     $WORKDIR_GIT 
108
109     rm $LOCK
110
111 }
112
113 main "$@"
114
115 ########################################
116 # this applied to the older version that was running at princeton
117 # NOTE
118 # as the svn diff operations from a remote location are so sssssslllllllooooooooowwwwww...
119 # what we do:
120 # maintain codebase in onelab.eu for historical reasons
121 # (1) push scripts on princeton (manually run all-modules-update.sh)
122 # (2) run the scripts cyclically over there through cron
123 # and push the results on build.onelab.eu with all-modules.push.sh (as part of the cron job)
124 #