protect against concurrent runs - redone
[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 # usage: do_version dir name 
17 function do_version () {
18     build_dir=$1; shift
19     name=$1; shift
20
21     out_dir=$OUTPUT/$name
22     out_file=$out_dir/version.txt
23     out_tmp=$out_dir/.version.txt
24     
25     mkdir -p $out_dir
26     
27     ( echo $name ; \
28       date ; \
29       $build_dir/module-version -a ; \
30       date ) &> $out_tmp
31     mv -f $out_tmp $out_file
32 }
33
34 # usage: do_version dir name 
35 function do_diff () {
36     build_dir=$1; shift
37     name=$1; shift
38
39     out_dir=$OUTPUT/$name
40     out_file=$out_dir/diff.txt
41     out_tmp=$out_dir/.diff.txt
42     
43     mkdir -p $out_dir
44     
45     ( echo $name ; \
46       date ; \
47       $build_dir/module-diff -a -o -q ; \
48       date ) &> $out_tmp
49
50     ( echo 'WARNINGS (if any)' ; \
51       egrep 'was not found|Skipping failed' $out_tmp ;
52       cat $out_tmp ) > $out_file
53
54     rm -f $out_tmp
55 }
56
57 function usage () {
58     echo "Usage: $COMMAND [-v] [-f] [-i]"
59 }
60
61 function main () {
62
63     while [[ -n "$@" ]] ; do
64         case "$1" in 
65             -f) rm -f $LOCK ;;
66             -i) ls -l $LOCK ; exit 0 ;;
67             -v) set -x ;;
68             *) usage; exit 1;;
69         esac
70         shift
71     done
72
73     [ -f $LOCK ] && exit 1
74     
75     echo $$ > $LOCK
76
77     do_version /root/svn-build-4.2 4.2 
78     do_diff    /root/svn-build-4.2 4.2 
79     do_version /root/svn-build     trunk 
80     do_diff    /root/svn-build     trunk 
81
82     rm $LOCK
83
84 }
85
86 main "$@"