a89881eaa922bd5b4cee4b56fc88e31fe24ce8e0
[infrastructure.git] / scripts / all-modules.sh
1 #!/bin/bash
2
3 # NOTE
4 # as the svn diff operations from a remote location are so sssssslllllllooooooooowwwwww...
5 # what we do:
6 # maintain codebase in onelab.eu for historical reasons
7 # (1) push scripts on princeton (manually run all-modules-update.sh)
8 # (2) run the scripts cyclically over there through cron
9 # and push the results on build.onelab.eu with all-modules.push.sh (as part of the cron job)
10 #
11 # this script is a wrapper around the module-tools (version and diff)
12 # it is invoked cyclically
13 # prior to that, the following directories will have been svn updated :
14 # ~/svn-build
15 # ~/root/svn-build-4.2
16
17 # avoid running several instances of this script
18 # when the svn server has problems, this can very well last quite a while
19
20 COMMAND=$(basename $0)
21
22 # make sure the cyclic tasks do not interfere with manual usage
23 #WORKDIR_SVN=${HOME}/all-modules-svn
24 WORKDIR_GIT=${HOME}/all-modules-git
25
26 # make the command usable as non-root user at Princeton for more efficiency
27 if [ "$(id -u)" == "0" ] ; then
28     OUTPUT=/build/modules/slow
29     LOCK=/var/run/all-modules.pid
30 else
31     OUTPUT=~/all-modules
32     LOCK=~/all-modules.run
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     elif [ -d $build_dir/.git ] ; then
40         ( cd $build_dir; git pull > .update.log 2>&1 )
41     else
42         ( cd $build_dir; svn update > .update.log 2>&1 )
43     fi
44 }
45
46 # usage: do_version dir workdir wwwname 
47 function do_version () {
48     build_dir=$1; shift
49     workdir=$1; shift
50     wwwname=$1; shift
51
52     out_dir=$OUTPUT/$wwwname
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_version dir workdir wwwname 
62 function do_diff () {
63     build_dir=$1; shift
64     workdir=$1; shift
65     wwwname=$1; shift
66
67     out_dir=$OUTPUT/$wwwname
68     out_file=$out_dir/diff.html
69     out_tmp=$out_dir/.diff.html
70     
71     mkdir -p $out_dir
72     $build_dir/module-diff $VERBOSE -w $workdir --www $wwwname -a &> $out_tmp
73     mv -f $out_tmp $out_file
74
75 }
76
77 function usage () {
78     echo "Usage: $COMMAND [-v] [-f] [-i]"
79 }
80
81 function main () {
82
83     while [[ -n "$@" ]] ; do
84         case "$1" in 
85             -f) rm -f $LOCK ;;
86             -i) ls -l $LOCK ; exit 0 ;;
87             -v) set -x ; VERBOSE=-v ;;
88             *) usage; exit 1;;
89         esac
90         shift
91     done
92
93     [ -f $LOCK ] && exit 1
94     
95     echo $$ > $LOCK
96
97 # the 5.0 flavour now comes with a non-compatible flavour of the module-tools
98 # and we need 2 distinc workdirs
99     do_update  ~/git-build
100     do_version ~/git-build     $WORKDIR_GIT 5.0 
101     do_diff    ~/git-build     $WORKDIR_GIT 5.0
102 ### dropped the 4.3 branxh while moving to git...
103 #    do_update  ~/svn-build-4.3
104 #    do_version ~/svn-build-4.3 $WORKDIR_SVN 4.3 
105 #    do_diff    ~/svn-build-4.3 $WORKDIR_SVN 4.3
106
107     rm $LOCK
108
109 }
110
111 main "$@"