d408c733d6e0e4e7c3212fe598b13db21cb77b66
[infrastructure.git] / scripts / all-modules.sh
1 #!/bin/bash
2 # $Id$
3 #
4 # NOTE
5 # as the svn diff operations from a remote location are so sssssslllllllooooooooowwwwww...
6 # what we do:
7 # maintain codebase in onelab.eu for historical reasons
8 # (1) push scripts on princeton (manually run all-modules-update.sh)
9 # (2) run the scripts cyclically over there through cron
10 # and push the results on build.onelab.eu with all-modules.push.sh (as part of the cron job)
11 #
12 # this script is a wrapper around the module-tools (version and diff)
13 # it is invoked cyclically
14 # prior to that, the following directories will have been svn updated :
15 # ~/svn-build
16 # ~/root/svn-build-4.2
17
18 # avoid running several instances of this script
19 # when the svn server has problems, this can very well last quite a while
20
21 COMMAND=$(basename $0)
22
23 # make the command usable as non-root user at Princeton for more efficiency
24 if [ "$(id -u)" == "0" ] ; then
25     OUTPUT=/build/modules/slow
26     LOCK=/var/run/all-modules.pid
27 else
28     OUTPUT=~/all-modules
29     LOCK=~/all-modules.run
30 fi
31
32 function do_update() {
33     build_dir=$1; shift
34     if [ -f $build_dir/auto-update.sh ] ; then
35         $build_dir/auto-update.sh
36     else
37         ( cd $build_dir; svn update > .update.log 2>&1 )
38     fi
39 }
40
41 # usage: do_version dir name 
42 function do_version () {
43     build_dir=$1; shift
44     name=$1; shift
45
46     out_dir=$OUTPUT/$name
47     out_file=$out_dir/version.html
48     out_tmp=$out_dir/.version.html
49     
50     mkdir -p $out_dir
51     $build_dir/module-version --www $name -a --url &> $out_tmp
52     mv -f $out_tmp $out_file
53 }
54
55 # usage: do_version dir name 
56 function do_diff () {
57     build_dir=$1; shift
58     name=$1; shift
59
60     out_dir=$OUTPUT/$name
61     out_file=$out_dir/diff.html
62     out_tmp=$out_dir/.diff.html
63     
64     mkdir -p $out_dir
65     $build_dir/module-diff --www $name -a &> $out_tmp
66     mv -f $out_tmp $out_file
67
68 }
69
70 function usage () {
71     echo "Usage: $COMMAND [-v] [-f] [-i]"
72 }
73
74 function main () {
75
76     while [[ -n "$@" ]] ; do
77         case "$1" in 
78             -f) rm -f $LOCK ;;
79             -i) ls -l $LOCK ; exit 0 ;;
80             -v) set -x ;;
81             *) usage; exit 1;;
82         esac
83         shift
84     done
85
86     [ -f $LOCK ] && exit 1
87     
88     echo $$ > $LOCK
89
90     do_update  ~/svn-build
91     do_version ~/svn-build     5.0 
92     do_diff    ~/svn-build     5.0
93     do_update  ~/svn-build-4.3
94     do_version ~/svn-build-4.3 4.3 
95     do_diff    ~/svn-build-4.3 4.3
96
97     rm $LOCK
98
99 }
100
101 main "$@"