run the cyclic task at princeton in a safe directory to avoid interferences with...
[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     MODULES_OPTION=""
28 else
29     OUTPUT=~/all-modules
30     LOCK=~/all-modules.run
31     # make sure the cyclic tasks do not interfere with manual usage
32     MODULES_OPTION="-w ${HOME}/all-modules-working-dir"
33 fi
34
35 function do_update() {
36     build_dir=$1; shift
37     if [ -f $build_dir/auto-update.sh ] ; then
38         $build_dir/auto-update.sh
39     else
40         ( cd $build_dir; svn update > .update.log 2>&1 )
41     fi
42 }
43
44 # usage: do_version dir name 
45 function do_version () {
46     build_dir=$1; shift
47     name=$1; shift
48
49     out_dir=$OUTPUT/$name
50     out_file=$out_dir/version.html
51     out_tmp=$out_dir/.version.html
52     
53     mkdir -p $out_dir
54     $build_dir/module-version $MODULES_OPTION --www $name -a --url &> $out_tmp
55     mv -f $out_tmp $out_file
56 }
57
58 # usage: do_version dir name 
59 function do_diff () {
60     build_dir=$1; shift
61     name=$1; shift
62
63     out_dir=$OUTPUT/$name
64     out_file=$out_dir/diff.html
65     out_tmp=$out_dir/.diff.html
66     
67     mkdir -p $out_dir
68     $build_dir/module-diff $MODULES_OPTION --www $name -a &> $out_tmp
69     mv -f $out_tmp $out_file
70
71 }
72
73 function usage () {
74     echo "Usage: $COMMAND [-v] [-f] [-i]"
75 }
76
77 function main () {
78
79     while [[ -n "$@" ]] ; do
80         case "$1" in 
81             -f) rm -f $LOCK ;;
82             -i) ls -l $LOCK ; exit 0 ;;
83             -v) set -x ;;
84             *) usage; exit 1;;
85         esac
86         shift
87     done
88
89     [ -f $LOCK ] && exit 1
90     
91     echo $$ > $LOCK
92
93     do_update  ~/svn-build
94     do_version ~/svn-build     5.0 
95     do_diff    ~/svn-build     5.0
96     do_update  ~/svn-build-4.3
97     do_version ~/svn-build-4.3 4.3 
98     do_diff    ~/svn-build-4.3 4.3
99
100     rm $LOCK
101
102 }
103
104 main "$@"