no 4.2 anymore
[infrastructure.git] / scripts / all-modules.sh
1 #!/bin/bash
2 # $Id$
3 # this script is a wrapper around the module-tools (version and diff)
4 # it is invoked every 30 minutes on onelab build box
5 # prior to that, the following directories will have been svn updated :
6 # /root/svn-build
7 # /root/svn-build-4.2
8
9 # avoid running several instances of this script
10 # when the svn server has problems, this can very well last quite a while
11
12 COMMAND=$(basename $0)
13 OUTPUT=/build/modules
14 LOCK=/var/run/all-modules.pid
15
16 function do_update() {
17     build_dir=$1; shift
18     if [ -f $build_dir/auto-update.sh ] ; then
19         $build_dir/auto-update.sh
20     else
21         pushd $build_dir; svn update > .update.log 2>&1 ; popd
22     fi
23 }
24
25 # usage: do_version dir name 
26 function do_version () {
27     build_dir=$1; shift
28     name=$1; shift
29
30     out_dir=$OUTPUT/$name
31     out_file=$out_dir/version.txt
32     out_tmp=$out_dir/.version.txt
33     
34     mkdir -p $out_dir
35     
36     ( echo $name ; \
37       date ; \
38       $build_dir/module-version -a --url ; \
39       date ) &> $out_tmp
40     mv -f $out_tmp $out_file
41 }
42
43 # usage: do_version dir name 
44 function do_diff () {
45     build_dir=$1; shift
46     name=$1; shift
47
48     out_dir=$OUTPUT/$name
49     out_file=$out_dir/diff.txt
50     out_tmp=$out_dir/.diff.txt
51     
52     mkdir -p $out_dir
53     
54     ( echo $name ; \
55       date ; \
56       $build_dir/module-diff -a -o ; \
57       date ) &> $out_tmp
58
59     ( echo 'WARNINGS (if any)' ; \
60       egrep 'was not found|Skipping failed' $out_tmp ;
61       cat $out_tmp ) > $out_file
62
63     rm -f $out_tmp
64 }
65
66 function usage () {
67     echo "Usage: $COMMAND [-v] [-f] [-i]"
68 }
69
70 function main () {
71
72     while [[ -n "$@" ]] ; do
73         case "$1" in 
74             -f) rm -f $LOCK ;;
75             -i) ls -l $LOCK ; exit 0 ;;
76             -v) set -x ;;
77             *) usage; exit 1;;
78         esac
79         shift
80     done
81
82     [ -f $LOCK ] && exit 1
83     
84     echo $$ > $LOCK
85
86     do_update  /root/svn-build
87     do_diff    /root/svn-build     trunk 
88     do_version /root/svn-build     trunk 
89 #    do_update  /root/svn-build-4.2
90 #    do_diff    /root/svn-build-4.2 4.2 
91 #    do_version /root/svn-build-4.2 4.2 
92
93     rm $LOCK
94
95 }
96
97 main "$@"